diff --git a/Makefile b/Makefile index b70a0d6..928233a 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,15 @@ build: cli: go build -ldflags "$(LDFLAGS)" -o bin/focusd-cli cmd/main.go -.PHONY: dev -dev: +server: + go run cmd/main.go serve + +wails3: wails3 dev --port 17000 LDFLAGS="$(LDFLAGS)" +.PHONY: dev +dev: server wails3 &> /dev/null & + .PHONY: tidy tidy: go mod tidy diff --git a/cmd/main.go b/cmd/main.go index cdf0d3d..93835c8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -13,8 +13,7 @@ import ( func main() { if err := godotenv.Load(); err != nil { - slog.Error("failed to load .env file", "error", err) - os.Exit(1) + slog.Warn("failed to load .env file", "error", err) } root := &cli.Command{Name: "focusd", Commands: []*cli.Command{serve.Command}} diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index b350008..067e0d4 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -19,7 +19,6 @@ import ( "connectrpc.com/connect" "connectrpc.com/validate" - "github.com/joho/godotenv" _ "github.com/tursodatabase/libsql-client-go/libsql" "github.com/urfave/cli/v3" "golang.org/x/net/http2" @@ -52,10 +51,6 @@ var Command = &cli.Command{ }, }, Action: func(ctx context.Context, cmd *cli.Command) error { - if err := godotenv.Load(); err != nil { - return fmt.Errorf("failed to load .env file: %w", err) - } - gormDB, err := setupDatabase(cmd.String("turso-db-url"), cmd.String("turso-db-token")) if err != nil { return fmt.Errorf("failed to setup database: %w", err) diff --git a/frontend/src/components/insights/bento-dashboard.tsx b/frontend/src/components/insights/bento-dashboard.tsx index a0ff549..d80c734 100644 --- a/frontend/src/components/insights/bento-dashboard.tsx +++ b/frontend/src/components/insights/bento-dashboard.tsx @@ -26,6 +26,8 @@ import { TopDistractionsCard } from "./top-distractions-card"; import { CategoriesCard } from "./categories-card"; import { CommunicationCard } from "./communication-card"; +const MIN_SECONDS_FOR_INSIGHTS = 3600; + // Hourly breakdown chart component function HourlyBreakdownChart({ hourlyData, @@ -159,10 +161,14 @@ export function BentoDashboard() { const isLoading = isStoreLoading || isQueryLoading; - // Real data from backend (values are in seconds, convert to minutes for display) + const productiveSeconds = overview?.UsageOverview?.ProductiveSeconds ?? 0; + const distractiveSeconds = overview?.UsageOverview?.DistractiveSeconds ?? 0; + const totalTrackedSeconds = productiveSeconds + distractiveSeconds; + const hasEnoughData = totalTrackedSeconds >= MIN_SECONDS_FOR_INSIGHTS; + const focusScore = Math.round(overview?.UsageOverview?.ProductivityScore ?? 0); - const productiveMinutes = Math.round((overview?.UsageOverview?.ProductiveSeconds ?? 0) / 60); - const distractiveMinutes = Math.round((overview?.UsageOverview?.DistractiveSeconds ?? 0) / 60); + const productiveMinutes = Math.round(productiveSeconds / 60); + const distractiveMinutes = Math.round(distractiveSeconds / 60); // Get hourly breakdown from backend (already in UsagePerHourBreakdown format with seconds) // Filter out any null values that may come from the backend @@ -243,37 +249,50 @@ export function BentoDashboard() {
Focus Score
-- {focusScore}% -
-- When I chose between work and distraction, I won {focusScore}% of the time -
- -+ {focusScore}% +
++ When I chose between work and distraction, I won {focusScore}% of the time +
+ > + ) : ( + <> +--
++ Requires at least 1h of activity +
+ > + )}