Skip to content

Commit 6d4ebe3

Browse files
authored
refactor: move updates service to trprc, type emitted :events (#282)
1 parent 62ad820 commit 6d4ebe3

File tree

18 files changed

+364
-295
lines changed

18 files changed

+364
-295
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { FsService } from "../services/fs/service.js";
99
import { GitService } from "../services/git/service.js";
1010
import { OAuthService } from "../services/oauth/service.js";
1111
import { ShellService } from "../services/shell/service.js";
12+
import { UpdatesService } from "../services/updates/service.js";
1213
import { MAIN_TOKENS } from "./tokens.js";
1314

1415
export const container = new Container({
@@ -24,3 +25,4 @@ container.bind(MAIN_TOKENS.FsService).to(FsService);
2425
container.bind(MAIN_TOKENS.GitService).to(GitService);
2526
container.bind(MAIN_TOKENS.OAuthService).to(OAuthService);
2627
container.bind(MAIN_TOKENS.ShellService).to(ShellService);
28+
container.bind(MAIN_TOKENS.UpdatesService).to(UpdatesService);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export const MAIN_TOKENS = Object.freeze({
1515
GitService: Symbol.for("Main.GitService"),
1616
OAuthService: Symbol.for("Main.OAuthService"),
1717
ShellService: Symbol.for("Main.ShellService"),
18+
UpdatesService: Symbol.for("Main.UpdatesService"),
1819
});

apps/array/src/main/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
shutdownPostHog,
4242
trackAppEvent,
4343
} from "./services/posthog-analytics.js";
44-
import { registerAutoUpdater } from "./services/updates.js";
44+
import type { UpdatesService } from "./services/updates/service.js";
4545
import { registerWorkspaceIpc } from "./services/workspace/index.js";
4646

4747
const __filename = fileURLToPath(import.meta.url);
@@ -152,12 +152,19 @@ function createWindow(): void {
152152
},
153153
},
154154
{ type: "separator" },
155-
{
156-
label: "Check for Updates...",
157-
click: () => {
158-
mainWindow?.webContents.send("check-for-updates-menu");
159-
},
160-
},
155+
...(app.isPackaged
156+
? [
157+
{
158+
label: "Check for Updates...",
159+
click: () => {
160+
const updatesService = container.get<UpdatesService>(
161+
MAIN_TOKENS.UpdatesService,
162+
);
163+
updatesService.triggerMenuCheck();
164+
},
165+
},
166+
]
167+
: []),
161168
{ type: "separator" },
162169
{
163170
label: "Settings...",
@@ -249,8 +256,9 @@ app.whenReady().then(() => {
249256
createWindow();
250257
ensureClaudeConfigDir();
251258

252-
// Initialize dock badge service for notification badges
259+
// Initialize services that need early startup
253260
container.get<DockBadgeService>(MAIN_TOKENS.DockBadgeService);
261+
container.get<UpdatesService>(MAIN_TOKENS.UpdatesService);
254262

255263
// Initialize PostHog analytics
256264
initializePostHog();
@@ -284,9 +292,6 @@ app.on("activate", () => {
284292
}
285293
});
286294

287-
// Background services
288-
registerAutoUpdater(() => mainWindow);
289-
290295
ipcMain.handle("app:get-version", () => app.getVersion());
291296

292297
// Register IPC handlers via services

apps/array/src/main/preload.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,6 @@ contextBridge.exposeInMainWorld("electronAPI", {
167167
onClearStorage: (listener: () => void): (() => void) =>
168168
createVoidIpcListener("clear-storage", listener),
169169
getAppVersion: (): Promise<string> => ipcRenderer.invoke("app:get-version"),
170-
onUpdateReady: (listener: () => void): (() => void) =>
171-
createVoidIpcListener("updates:ready", listener),
172-
installUpdate: (): Promise<{ installed: boolean }> =>
173-
ipcRenderer.invoke("updates:install"),
174-
checkForUpdates: (): Promise<{
175-
success: boolean;
176-
error?: string;
177-
}> => ipcRenderer.invoke("updates:check"),
178-
onUpdateStatus: (
179-
listener: IpcEventListener<{
180-
checking?: boolean;
181-
upToDate?: boolean;
182-
}>,
183-
): (() => void) => createIpcListener("updates:status", listener),
184-
onCheckForUpdatesMenu: (listener: () => void): (() => void) =>
185-
createVoidIpcListener("check-for-updates-menu", listener),
186170
// Workspace API
187171
workspace: {
188172
create: (options: CreateWorkspaceOptions): Promise<WorkspaceInfo> =>

apps/array/src/main/services/file-watcher/schemas.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,28 @@ export const FileWatcherEvent = {
2727
GitStateChanged: "git-state-changed",
2828
} as const;
2929

30+
export type DirectoryChangedPayload = {
31+
repoPath: string;
32+
dirPath: string;
33+
};
34+
35+
export type FileChangedPayload = {
36+
repoPath: string;
37+
filePath: string;
38+
};
39+
40+
export type FileDeletedPayload = {
41+
repoPath: string;
42+
filePath: string;
43+
};
44+
45+
export type GitStateChangedPayload = {
46+
repoPath: string;
47+
};
48+
3049
export interface FileWatcherEvents {
31-
[FileWatcherEvent.DirectoryChanged]: { repoPath: string; dirPath: string };
32-
[FileWatcherEvent.FileChanged]: { repoPath: string; filePath: string };
33-
[FileWatcherEvent.FileDeleted]: { repoPath: string; filePath: string };
34-
[FileWatcherEvent.GitStateChanged]: { repoPath: string };
50+
[FileWatcherEvent.DirectoryChanged]: DirectoryChangedPayload;
51+
[FileWatcherEvent.FileChanged]: FileChangedPayload;
52+
[FileWatcherEvent.FileDeleted]: FileDeletedPayload;
53+
[FileWatcherEvent.GitStateChanged]: GitStateChangedPayload;
3554
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ import "./posthog-analytics.js";
88
import "./session-manager.js";
99
import "./settingsStore.js";
1010
import "./transcription-prompts.js";
11-
import "./updates.js";

apps/array/src/main/services/shell/schemas.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ export const ShellEvent = {
4141
Exit: "exit",
4242
} as const;
4343

44+
export type ShellDataPayload = {
45+
sessionId: string;
46+
data: string;
47+
};
48+
49+
export type ShellExitPayload = {
50+
sessionId: string;
51+
exitCode: number;
52+
};
53+
4454
export interface ShellEvents {
45-
[ShellEvent.Data]: { sessionId: string; data: string };
46-
[ShellEvent.Exit]: { sessionId: string; exitCode: number };
55+
[ShellEvent.Data]: ShellDataPayload;
56+
[ShellEvent.Exit]: ShellExitPayload;
4757
}

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

Lines changed: 0 additions & 176 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { z } from "zod";
2+
3+
export const isEnabledOutput = z.object({
4+
enabled: z.boolean(),
5+
});
6+
7+
export const checkForUpdatesOutput = z.object({
8+
success: z.boolean(),
9+
error: z.string().optional(),
10+
});
11+
12+
export const installUpdateOutput = z.object({
13+
installed: z.boolean(),
14+
});
15+
16+
export type IsEnabledOutput = z.infer<typeof isEnabledOutput>;
17+
18+
export type CheckForUpdatesOutput = z.infer<typeof checkForUpdatesOutput>;
19+
export type InstallUpdateOutput = z.infer<typeof installUpdateOutput>;
20+
21+
export const UpdatesEvent = {
22+
Ready: "ready",
23+
Status: "status",
24+
CheckFromMenu: "check-from-menu",
25+
} as const;
26+
27+
export type UpdatesStatusPayload = {
28+
checking: boolean;
29+
upToDate?: boolean;
30+
version?: string;
31+
};
32+
33+
export interface UpdatesEvents {
34+
[UpdatesEvent.Ready]: undefined;
35+
[UpdatesEvent.Status]: UpdatesStatusPayload;
36+
[UpdatesEvent.CheckFromMenu]: undefined;
37+
}

0 commit comments

Comments
 (0)