diff --git a/docs/internal/ServiceIPC.md b/docs/internal/ServiceIPC.md new file mode 100644 index 00000000..3d3c765e --- /dev/null +++ b/docs/internal/ServiceIPC.md @@ -0,0 +1,7 @@ +# Service IPC + +## Sync service + +Some services are sync, like `getSubWorkspacesAsListSync` `getActiveWorkspaceSync` from `src/services/workspaces/index.ts`, they can't be called from renderer, only can be used in the main process. + +Because after pass through IPC, everything will be async, so its function typescript signature will be wrong. diff --git a/src/services/workspaces/getWorkspaceMenuTemplate.ts b/src/services/workspaces/getWorkspaceMenuTemplate.ts index 98a8549c..5c76f766 100644 --- a/src/services/workspaces/getWorkspaceMenuTemplate.ts +++ b/src/services/workspaces/getWorkspaceMenuTemplate.ts @@ -23,7 +23,7 @@ interface IWorkspaceMenuRequiredServices { wiki: Pick; wikiGitWorkspace: Pick; window: Pick; - workspace: Pick; + workspace: Pick; workspaceView: Pick< IWorkspaceViewService, | 'wakeUpWorkspaceView' @@ -129,7 +129,8 @@ export async function getWorkspaceMenuTemplate( } else { // sync all sub workspace const mainHasChanges = await service.git.commitAndSync(workspace, { remoteUrl: gitUrl, userInfo }); - const subHasChangesPromise = service.workspace.getSubWorkspacesAsListSync(id).map(async (workspace) => { + const subWorkspaces = await service.workspace.getSubWorkspacesAsList(id); + const subHasChangesPromise = subWorkspaces.map(async (workspace) => { const hasChanges = await service.git.commitAndSync(workspace, { remoteUrl: gitUrl, userInfo }); return hasChanges; }); diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index 14cf4f05..de3ffece 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -220,6 +220,13 @@ export class Workspace implements IWorkspaceService { return Object.values(this.workspaces).sort(workspaceSorter); } + public async getSubWorkspacesAsList(workspaceID: string): Promise { + const workspace = this.getSync(workspaceID); + if (workspace === undefined) return []; + if (workspace.isSubWiki) return []; + return this.getWorkspacesAsListSync().filter((w) => w.mainWikiID === workspaceID).sort(workspaceSorter); + } + public getSubWorkspacesAsListSync(workspaceID: string): IWorkspace[] { const workspace = this.getSync(workspaceID); if (workspace === undefined) return []; diff --git a/src/services/workspaces/interface.ts b/src/services/workspaces/interface.ts index d6cf26c6..c6145b56 100644 --- a/src/services/workspaces/interface.ts +++ b/src/services/workspaces/interface.ts @@ -181,6 +181,10 @@ export interface IWorkspaceService { getMetaData: (id: string) => Promise>; getNextWorkspace: (id: string) => Promise; getPreviousWorkspace: (id: string) => Promise; + getSubWorkspacesAsList(workspaceID: string): Promise; + /** + * Only meant to be used in TidGi's services internally. + */ getSubWorkspacesAsListSync(workspaceID: string): IWorkspace[]; getWorkspaces(): Promise>; getWorkspacesAsList(): Promise;