mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-05 18:20:39 -08:00
fix: sync when no draft not working
This commit is contained in:
parent
dc07d907d3
commit
39e310b111
3 changed files with 24 additions and 13 deletions
|
|
@ -90,3 +90,9 @@ Some library doesn't fit electron usage, we move their code to this repo and mod
|
|||
[FileProtocol](./features/FileProtocol.md)
|
||||
|
||||
TBD
|
||||
|
||||
## FAQ
|
||||
|
||||
### `Uncaught ReferenceError: require is not defined`
|
||||
|
||||
`pnpm run clean:cache` can fix this.
|
||||
|
|
|
|||
|
|
@ -40,17 +40,26 @@ export class Sync implements ISyncService {
|
|||
private readonly workspaceService!: IWorkspaceService;
|
||||
|
||||
public async syncWikiIfNeeded(workspace: IWorkspace): Promise<void> {
|
||||
const { gitUrl, storageService, backupOnInterval, id, isSubWiki, wikiFolderLocation: dir } = workspace;
|
||||
const { gitUrl, storageService, id, isSubWiki, wikiFolderLocation: dir } = workspace;
|
||||
const userInfo = await this.authService.getStorageServiceUserInfo(storageService);
|
||||
const defaultCommitMessage = i18n.t('LOG.CommitMessage');
|
||||
const defaultCommitBackupMessage = i18n.t('LOG.CommitBackupMessage');
|
||||
const syncOnlyWhenNoDraft = await this.preferenceService.get('syncOnlyWhenNoDraft');
|
||||
// we can only run filter on main wiki (tw don't know what is sub-wiki)
|
||||
if (!isSubWiki && syncOnlyWhenNoDraft && (await this.checkCanSyncDueToNoDraft(id))) {
|
||||
const mainWorkspace = isSubWiki ? this.workspaceService.getMainWorkspace(workspace) : undefined;
|
||||
if (isSubWiki && mainWorkspace === undefined) {
|
||||
logger.error(`Main workspace not found for sub workspace ${id}`, { function: 'syncWikiIfNeeded' });
|
||||
return;
|
||||
}
|
||||
if (
|
||||
storageService !== SupportedStorageServices.local &&
|
||||
const idToUse = isSubWiki ? mainWorkspace!.id : id;
|
||||
// we can only run filter on main wiki (tw don't know what is sub-wiki)
|
||||
if (syncOnlyWhenNoDraft && !(await this.checkCanSyncDueToNoDraft(idToUse))) {
|
||||
await this.wikiService.wikiOperationInBrowser(WikiChannel.generalNotification, idToUse, [i18n.t('Preference.SyncOnlyWhenNoDraft')]);
|
||||
return;
|
||||
}
|
||||
if (storageService === SupportedStorageServices.local) {
|
||||
// for local workspace, commitOnly, no sync and no force pull.
|
||||
await this.gitService.commitAndSync(workspace, { commitOnly: true, dir, commitMessage: defaultCommitBackupMessage });
|
||||
} else if (
|
||||
typeof gitUrl === 'string' &&
|
||||
userInfo !== undefined
|
||||
) {
|
||||
|
|
@ -59,10 +68,9 @@ export class Sync implements ISyncService {
|
|||
const hasChanges = await this.gitService.syncOrForcePull(workspace, syncOrForcePullConfigs);
|
||||
if (isSubWiki) {
|
||||
// after sync this sub wiki, reload its main workspace
|
||||
const mainWorkspace = this.workspaceService.getMainWorkspace(workspace);
|
||||
if (hasChanges && mainWorkspace !== undefined) {
|
||||
await this.workspaceViewService.restartWorkspaceViewService(mainWorkspace.id);
|
||||
await this.viewService.reloadViewsWebContents(mainWorkspace.id);
|
||||
if (hasChanges) {
|
||||
await this.workspaceViewService.restartWorkspaceViewService(idToUse);
|
||||
await this.viewService.reloadViewsWebContents(idToUse);
|
||||
}
|
||||
} else {
|
||||
// sync all sub workspace
|
||||
|
|
@ -87,9 +95,6 @@ export class Sync implements ISyncService {
|
|||
await this.viewService.reloadViewsWebContents(id);
|
||||
}
|
||||
}
|
||||
} else if (backupOnInterval) {
|
||||
// for local workspace, commitOnly, no sync and no force pull.
|
||||
await this.gitService.commitAndSync(workspace, { commitOnly: true, dir, commitMessage: defaultCommitBackupMessage });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ export async function getWorkspaceMenuTemplate(
|
|||
template.push({
|
||||
label: t('ContextMenu.BackupNow'),
|
||||
click: async () => {
|
||||
await service.git.commitAndSync(workspace, { commitOnly: true, dir: wikiFolderLocation });
|
||||
await service.sync.syncWikiIfNeeded(workspace);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue