Skip to content

Commit 34b22fc

Browse files
authored
refactor: move folders service to trpc (#280)
1 parent 24f3361 commit 34b22fc

File tree

14 files changed

+273
-232
lines changed

14 files changed

+273
-232
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ContextMenuService } from "../services/context-menu/service.js";
44
import { DockBadgeService } from "../services/dock-badge/service.js";
55
import { ExternalAppsService } from "../services/external-apps/service.js";
66
import { FileWatcherService } from "../services/file-watcher/service.js";
7+
import { FoldersService } from "../services/folders/service.js";
78
import { FsService } from "../services/fs/service.js";
89
import { GitService } from "../services/git/service.js";
910
import { ShellService } from "../services/shell/service.js";
@@ -17,6 +18,7 @@ container.bind(MAIN_TOKENS.ContextMenuService).to(ContextMenuService);
1718
container.bind(MAIN_TOKENS.DockBadgeService).to(DockBadgeService);
1819
container.bind(MAIN_TOKENS.ExternalAppsService).to(ExternalAppsService);
1920
container.bind(MAIN_TOKENS.FileWatcherService).to(FileWatcherService);
21+
container.bind(MAIN_TOKENS.FoldersService).to(FoldersService);
2022
container.bind(MAIN_TOKENS.FsService).to(FsService);
2123
container.bind(MAIN_TOKENS.GitService).to(GitService);
2224
container.bind(MAIN_TOKENS.ShellService).to(ShellService);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const MAIN_TOKENS = Object.freeze({
1010
DockBadgeService: Symbol.for("Main.DockBadgeService"),
1111
ExternalAppsService: Symbol.for("Main.ExternalAppsService"),
1212
FileWatcherService: Symbol.for("Main.FileWatcherService"),
13+
FoldersService: Symbol.for("Main.FoldersService"),
1314
FsService: Symbol.for("Main.FsService"),
1415
GitService: Symbol.for("Main.GitService"),
1516
ShellService: Symbol.for("Main.ShellService"),

apps/array/src/main/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { trpcRouter } from "./trpc/index.js";
3333
// Legacy type kept for backwards compatibility with taskControllers map
3434
type TaskController = unknown;
3535

36-
import { registerFoldersIpc } from "./services/folders.js";
3736
import { registerGitIpc } from "./services/git.js";
3837
import "./services/index.js";
3938
import { ExternalAppsService } from "./services/external-apps/service.js";
@@ -295,5 +294,4 @@ ipcMain.handle("app:get-version", () => app.getVersion());
295294
registerOAuthHandlers();
296295
registerGitIpc();
297296
registerAgentIpc(taskControllers, () => mainWindow);
298-
registerFoldersIpc(() => mainWindow);
299297
registerWorkspaceIpc(() => mainWindow);

apps/array/src/main/preload.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { contextBridge, type IpcRendererEvent, ipcRenderer } from "electron";
33
import { exposeElectronTRPC } from "trpc-electron/main";
44
import type {
55
CreateWorkspaceOptions,
6-
RegisteredFolder,
76
ScriptExecutionResult,
87
Workspace,
98
WorkspaceInfo,
@@ -197,23 +196,6 @@ contextBridge.exposeInMainWorld("electronAPI", {
197196
): (() => void) => createIpcListener("updates:status", listener),
198197
onCheckForUpdatesMenu: (listener: () => void): (() => void) =>
199198
createVoidIpcListener("check-for-updates-menu", listener),
200-
folders: {
201-
getFolders: (): Promise<RegisteredFolder[]> =>
202-
ipcRenderer.invoke("get-folders"),
203-
addFolder: (folderPath: string): Promise<RegisteredFolder> =>
204-
ipcRenderer.invoke("add-folder", folderPath),
205-
removeFolder: (folderId: string): Promise<void> =>
206-
ipcRenderer.invoke("remove-folder", folderId),
207-
updateFolderAccessed: (folderId: string): Promise<void> =>
208-
ipcRenderer.invoke("update-folder-accessed", folderId),
209-
clearAllData: (): Promise<void> => ipcRenderer.invoke("clear-all-data"),
210-
cleanupOrphanedWorktrees: (
211-
mainRepoPath: string,
212-
): Promise<{
213-
deleted: string[];
214-
errors: Array<{ path: string; error: string }>;
215-
}> => ipcRenderer.invoke("cleanup-orphaned-worktrees", mainRepoPath),
216-
},
217199
// Workspace API
218200
workspace: {
219201
create: (options: CreateWorkspaceOptions): Promise<WorkspaceInfo> =>

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

Lines changed: 0 additions & 189 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { z } from "zod";
2+
3+
export const registeredFolderSchema = z.object({
4+
id: z.string(),
5+
path: z.string(),
6+
name: z.string(),
7+
lastAccessed: z.string(),
8+
createdAt: z.string(),
9+
});
10+
11+
export const getFoldersOutput = z.array(registeredFolderSchema);
12+
13+
export const addFolderInput = z.object({
14+
folderPath: z.string(),
15+
});
16+
17+
export const addFolderOutput = registeredFolderSchema;
18+
19+
export const removeFolderInput = z.object({
20+
folderId: z.string(),
21+
});
22+
23+
export const updateFolderAccessedInput = z.object({
24+
folderId: z.string(),
25+
});
26+
27+
export const cleanupOrphanedWorktreesInput = z.object({
28+
mainRepoPath: z.string(),
29+
});
30+
31+
export const cleanupOrphanedWorktreesOutput = z.object({
32+
deleted: z.array(z.string()),
33+
errors: z.array(
34+
z.object({
35+
path: z.string(),
36+
error: z.string(),
37+
}),
38+
),
39+
});
40+
41+
export type RegisteredFolder = z.infer<typeof registeredFolderSchema>;
42+
export type GetFoldersOutput = z.infer<typeof getFoldersOutput>;
43+
export type AddFolderInput = z.infer<typeof addFolderInput>;
44+
export type AddFolderOutput = z.infer<typeof addFolderOutput>;
45+
export type RemoveFolderInput = z.infer<typeof removeFolderInput>;
46+
export type UpdateFolderAccessedInput = z.infer<
47+
typeof updateFolderAccessedInput
48+
>;
49+
export type CleanupOrphanedWorktreesInput = z.infer<
50+
typeof cleanupOrphanedWorktreesInput
51+
>;
52+
export type CleanupOrphanedWorktreesOutput = z.infer<
53+
typeof cleanupOrphanedWorktreesOutput
54+
>;

0 commit comments

Comments
 (0)