Skip to content

Commit 000405d

Browse files
authored
refactor: move dock-badge service to trpc (#274)
1 parent 49f405e commit 000405d

File tree

11 files changed

+63
-58
lines changed

11 files changed

+63
-58
lines changed

apps/array/src/main/di/container.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "reflect-metadata";
22
import { Container } from "inversify";
33
import { ContextMenuService } from "../services/context-menu/service.js";
4+
import { DockBadgeService } from "../services/dock-badge/service.js";
45
import { ExternalAppsService } from "../services/external-apps/service.js";
56
import { GitService } from "../services/git/service.js";
67
import { MAIN_TOKENS } from "./tokens.js";
@@ -9,6 +10,7 @@ export const container = new Container({
910
defaultScope: "Singleton",
1011
});
1112

13+
container.bind(MAIN_TOKENS.DockBadgeService).to(DockBadgeService);
1214
container.bind(MAIN_TOKENS.ExternalAppsService).to(ExternalAppsService);
1315
container.bind(MAIN_TOKENS.GitService).to(GitService);
1416
container.bind(MAIN_TOKENS.ContextMenuService).to(ContextMenuService);

apps/array/src/main/di/tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
export const MAIN_TOKENS = Object.freeze({
88
// Services
99
ContextMenuService: Symbol.for("Main.ContextMenuService"),
10+
DockBadgeService: Symbol.for("Main.DockBadgeService"),
1011
ExternalAppsService: Symbol.for("Main.ExternalAppsService"),
1112
GitService: Symbol.for("Main.GitService"),
1213
});

apps/array/src/main/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
import { createIPCHandler } from "trpc-electron/main";
2121
import "./lib/logger";
2222
import { ANALYTICS_EVENTS } from "../types/analytics.js";
23-
import { dockBadgeService } from "./services/dockBadge.js";
23+
import { container } from "./di/container.js";
24+
import { MAIN_TOKENS } from "./di/tokens.js";
25+
import type { DockBadgeService } from "./services/dock-badge/service.js";
2426
import {
2527
cleanupAgentSessions,
2628
registerAgentIpc,
@@ -254,7 +256,7 @@ app.whenReady().then(() => {
254256
ensureClaudeConfigDir();
255257

256258
// Initialize dock badge service for notification badges
257-
dockBadgeService.initialize(() => mainWindow);
259+
container.get<DockBadgeService>(MAIN_TOKENS.DockBadgeService);
258260

259261
// Initialize PostHog analytics
260262
initializePostHog();

apps/array/src/main/preload.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,6 @@ contextBridge.exposeInMainWorld("electronAPI", {
337337
}>,
338338
): (() => void) => createIpcListener("workspace:warning", listener),
339339
},
340-
// Dock Badge API
341-
dockBadge: {
342-
show: (): Promise<void> => ipcRenderer.invoke("dock-badge:show"),
343-
},
344340
shellExecute: (
345341
cwd: string,
346342
command: string,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { app } from "electron";
2+
import { injectable, postConstruct } from "inversify";
3+
import { logger } from "../../lib/logger";
4+
5+
const log = logger.scope("dock-badge");
6+
7+
@injectable()
8+
export class DockBadgeService {
9+
private hasBadge = false;
10+
11+
@postConstruct()
12+
init(): void {
13+
app.on("browser-window-focus", () => this.clear());
14+
log.info("Dock badge service initialized");
15+
}
16+
17+
show(): void {
18+
if (this.hasBadge) return;
19+
20+
this.hasBadge = true;
21+
if (process.platform === "darwin" || process.platform === "linux") {
22+
app.setBadgeCount(1);
23+
}
24+
log.info("Dock badge shown");
25+
}
26+
27+
private clear(): void {
28+
if (!this.hasBadge) return;
29+
30+
this.hasBadge = false;
31+
if (process.platform === "darwin" || process.platform === "linux") {
32+
app.setBadgeCount(0);
33+
}
34+
log.info("Dock badge cleared");
35+
}
36+
}

apps/array/src/main/services/dockBadge.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

apps/array/src/main/services/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* This file is auto-generated by vite-plugin-auto-services.ts
44
*/
55

6-
import "./dockBadge.js";
76
import "./fileWatcher.js";
87
import "./folders.js";
98
import "./fs.js";

apps/array/src/main/trpc/router.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { contextMenuRouter } from "./routers/context-menu.js";
2+
import { dockBadgeRouter } from "./routers/dock-badge.js";
23
import { encryptionRouter } from "./routers/encryption.js";
34
import { externalAppsRouter } from "./routers/external-apps.js";
45
import { gitRouter } from "./routers/git.js";
@@ -8,13 +9,14 @@ import { secureStoreRouter } from "./routers/secure-store.js";
89
import { router } from "./trpc.js";
910

1011
export const trpcRouter = router({
11-
os: osRouter,
12-
logs: logsRouter,
13-
secureStore: secureStoreRouter,
14-
encryption: encryptionRouter,
15-
git: gitRouter,
1612
contextMenu: contextMenuRouter,
13+
dockBadge: dockBadgeRouter,
14+
encryption: encryptionRouter,
1715
externalApps: externalAppsRouter,
16+
git: gitRouter,
17+
logs: logsRouter,
18+
os: osRouter,
19+
secureStore: secureStoreRouter,
1820
});
1921

2022
export type TrpcRouter = typeof trpcRouter;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { container } from "../../di/container.js";
2+
import { MAIN_TOKENS } from "../../di/tokens.js";
3+
import type { DockBadgeService } from "../../services/dock-badge/service.js";
4+
import { publicProcedure, router } from "../trpc.js";
5+
6+
const getService = () =>
7+
container.get<DockBadgeService>(MAIN_TOKENS.DockBadgeService);
8+
9+
export const dockBadgeRouter = router({
10+
show: publicProcedure.mutation(() => getService().show()),
11+
});

apps/array/src/renderer/features/task-detail/components/TaskLogsPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { Box } from "@radix-ui/themes";
1414
import { logger } from "@renderer/lib/logger";
1515
import { useNavigationStore } from "@renderer/stores/navigationStore";
16+
import { trpcVanilla } from "@renderer/trpc/client";
1617
import type { Task } from "@shared/types";
1718
import { useCallback, useEffect, useRef } from "react";
1819

@@ -83,7 +84,7 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
8384

8485
const isWindowFocused = document.hasFocus();
8586
if (!isWindowFocused) {
86-
window.electronAPI.dockBadge.show();
87+
trpcVanilla.dockBadge.show.mutate();
8788
}
8889
} catch (error) {
8990
log.error("Failed to send prompt", error);

0 commit comments

Comments
 (0)