mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-04 13:02:20 -08:00
parent
d410eaf430
commit
4ab764cff0
3 changed files with 31 additions and 7 deletions
|
|
@ -23,7 +23,7 @@ interface IWorkspaceMenuRequiredServices {
|
|||
wiki: Pick<IWikiService, 'wikiOperation' | 'requestWikiSendActionMessage'>;
|
||||
wikiGitWorkspace: Pick<IWikiGitWorkspaceService, 'removeWorkspace'>;
|
||||
window: Pick<IWindowService, 'open'>;
|
||||
workspace: Pick<IWorkspaceService, 'getActiveWorkspace'>;
|
||||
workspace: Pick<IWorkspaceService, 'getActiveWorkspace' | 'getSubWorkspacesAsListSync'>;
|
||||
workspaceView: Pick<
|
||||
IWorkspaceViewService,
|
||||
| 'wakeUpWorkspaceView'
|
||||
|
|
@ -114,12 +114,28 @@ export async function getWorkspaceMenuTemplate(
|
|||
label: t('ContextMenu.SyncNow') + (isOnline ? '' : `(${t('ContextMenu.NoNetworkConnection')})`),
|
||||
enabled: isOnline,
|
||||
click: async () => {
|
||||
const hasChanges = await service.git.commitAndSync(workspace, { remoteUrl: gitUrl, userInfo });
|
||||
if (hasChanges) {
|
||||
if (isSubWiki && mainWikiID !== null) {
|
||||
await service.workspaceView.restartWorkspaceViewService(mainWikiID);
|
||||
await service.view.reloadViewsWebContents(mainWikiID);
|
||||
} else {
|
||||
if (isSubWiki) {
|
||||
const hasChanges = await service.git.commitAndSync(workspace, { remoteUrl: gitUrl, userInfo });
|
||||
if (hasChanges) {
|
||||
if (mainWikiID === null) {
|
||||
await service.workspaceView.restartWorkspaceViewService(id);
|
||||
await service.view.reloadViewsWebContents(id);
|
||||
} else {
|
||||
// reload main workspace to reflect change (do this before watch-fs stable)
|
||||
await service.workspaceView.restartWorkspaceViewService(mainWikiID);
|
||||
await service.view.reloadViewsWebContents(mainWikiID);
|
||||
}
|
||||
}
|
||||
} 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 hasChanges = await service.git.commitAndSync(workspace, { remoteUrl: gitUrl, userInfo });
|
||||
return hasChanges;
|
||||
});
|
||||
const subHasChange = (await Promise.all(subHasChangesPromise)).some(Boolean);
|
||||
const hasChange = mainHasChanges || subHasChange;
|
||||
if (hasChange) {
|
||||
await service.workspaceView.restartWorkspaceViewService(id);
|
||||
await service.view.reloadViewsWebContents(id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,6 +220,13 @@ export class Workspace implements IWorkspaceService {
|
|||
return Object.values(this.workspaces).sort(workspaceSorter);
|
||||
}
|
||||
|
||||
public getSubWorkspacesAsListSync(workspaceID: string): 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 async get(id: string): Promise<IWorkspace | undefined> {
|
||||
return this.getSync(id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ export interface IWorkspaceService {
|
|||
getMetaData: (id: string) => Promise<Partial<IWorkspaceMetaData>>;
|
||||
getNextWorkspace: (id: string) => Promise<IWorkspace | undefined>;
|
||||
getPreviousWorkspace: (id: string) => Promise<IWorkspace | undefined>;
|
||||
getSubWorkspacesAsListSync(workspaceID: string): IWorkspace[];
|
||||
getWorkspaces(): Promise<Record<string, IWorkspace>>;
|
||||
getWorkspacesAsList(): Promise<IWorkspace[]>;
|
||||
remove(id: string): Promise<void>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue