mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
fix: ipc sync method
This commit is contained in:
parent
f545526fcb
commit
597797d779
4 changed files with 21 additions and 2 deletions
7
docs/internal/ServiceIPC.md
Normal file
7
docs/internal/ServiceIPC.md
Normal file
|
|
@ -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.
|
||||
|
|
@ -23,7 +23,7 @@ interface IWorkspaceMenuRequiredServices {
|
|||
wiki: Pick<IWikiService, 'wikiOperation' | 'requestWikiSendActionMessage'>;
|
||||
wikiGitWorkspace: Pick<IWikiGitWorkspaceService, 'removeWorkspace'>;
|
||||
window: Pick<IWindowService, 'open'>;
|
||||
workspace: Pick<IWorkspaceService, 'getActiveWorkspace' | 'getSubWorkspacesAsListSync'>;
|
||||
workspace: Pick<IWorkspaceService, 'getActiveWorkspace' | 'getSubWorkspacesAsList'>;
|
||||
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;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -220,6 +220,13 @@ export class Workspace implements IWorkspaceService {
|
|||
return Object.values(this.workspaces).sort(workspaceSorter);
|
||||
}
|
||||
|
||||
public async getSubWorkspacesAsList(workspaceID: string): Promise<IWorkspace[]> {
|
||||
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 [];
|
||||
|
|
|
|||
|
|
@ -181,6 +181,10 @@ export interface IWorkspaceService {
|
|||
getMetaData: (id: string) => Promise<Partial<IWorkspaceMetaData>>;
|
||||
getNextWorkspace: (id: string) => Promise<IWorkspace | undefined>;
|
||||
getPreviousWorkspace: (id: string) => Promise<IWorkspace | undefined>;
|
||||
getSubWorkspacesAsList(workspaceID: string): Promise<IWorkspace[]>;
|
||||
/**
|
||||
* Only meant to be used in TidGi's services internally.
|
||||
*/
|
||||
getSubWorkspacesAsListSync(workspaceID: string): IWorkspace[];
|
||||
getWorkspaces(): Promise<Record<string, IWorkspace>>;
|
||||
getWorkspacesAsList(): Promise<IWorkspace[]>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue