From 27cbe81185ca82ec8f438f85b6d9bcbcbb29c2fd Mon Sep 17 00:00:00 2001 From: tiagoarroz Date: Wed, 6 May 2026 10:34:24 +0100 Subject: [PATCH 1/2] Translate sync recovery comments to English --- src/sync-manager.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sync-manager.ts b/src/sync-manager.ts index af6e7f0..bc71564 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -610,7 +610,7 @@ export default class SyncManager { } /** - * Remove artefactos volateis do metadata local para evitar conflitos recorrentes. + * Removes volatile artifacts from local metadata to prevent recurring conflicts. */ private async removeVolatileArtifactsFromLocalMetadata() { let changed = false; @@ -626,7 +626,7 @@ export default class SyncManager { } /** - * Reconcilia SHAs do metadata remoto com a tree atual para remover referencias obsoletas. + * Reconciles remote metadata SHAs with the current tree to remove stale references. */ private async reconcileRemoteMetadataWithTree( remoteMetadataFiles: { @@ -662,7 +662,7 @@ export default class SyncManager { } /** - * Tenta obter o blob pelo SHA do metadata e, em caso de 404, tenta pelo SHA atual da tree. + * Tries to load a blob by metadata SHA and, on 404, retries with the current tree SHA. */ private async getRemoteFileContentWithFallback( filePath: string, From 570b2f846be8fe911a5fb562e035c9473f4c36f0 Mon Sep 17 00:00:00 2001 From: tiagoarroz Date: Fri, 8 May 2026 12:09:41 +0100 Subject: [PATCH 2/2] Add option to sync workspace files --- src/events-listener.ts | 17 ++++++++++------ src/settings/settings.ts | 2 ++ src/settings/tab.ts | 17 ++++++++++++++++ src/sync-manager.ts | 43 ++++++++++++++++++++++++++++++---------- 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/events-listener.ts b/src/events-listener.ts index 15093c4..7cd416c 100644 --- a/src/events-listener.ts +++ b/src/events-listener.ts @@ -135,16 +135,21 @@ export default class EventsListener { } } + private isWorkspaceFile(filePath: string): boolean { + return ( + filePath === `${this.vault.configDir}/workspace.json` || + filePath === `${this.vault.configDir}/workspace-mobile.json` + ); + } + private isSyncable(filePath: string) { if (filePath === `${this.vault.configDir}/${MANIFEST_FILE_NAME}`) { // Manifest file must always be synced return true; - } else if ( - filePath === `${this.vault.configDir}/workspace.json` || - filePath === `${this.vault.configDir}/workspace-mobile.json` - ) { - // Obsidian recommends not syncing the workspace files - return false; + } else if (this.isWorkspaceFile(filePath)) { + // Workspace files are synced only when config directory sync is enabled + // and the dedicated workspace-files option is enabled too. + return this.settings.syncConfigDir && this.settings.syncWorkspaceFiles; } else if (filePath === `${this.vault.configDir}/${LOG_FILE_NAME}`) { // Don't sync the log file, doesn't make sense return false; diff --git a/src/settings/settings.ts b/src/settings/settings.ts index 97baf09..5c32c29 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -8,6 +8,7 @@ export interface GitHubSyncSettings { syncInterval: number; syncOnStartup: boolean; syncConfigDir: boolean; + syncWorkspaceFiles: boolean; conflictHandling: "overwriteLocal" | "ask" | "overwriteRemote"; conflictViewMode: "default" | "unified" | "split"; showStatusBarItem: boolean; @@ -26,6 +27,7 @@ export const DEFAULT_SETTINGS: GitHubSyncSettings = { syncInterval: 1, syncOnStartup: false, syncConfigDir: false, + syncWorkspaceFiles: false, conflictHandling: "ask", conflictViewMode: "default", showStatusBarItem: true, diff --git a/src/settings/tab.ts b/src/settings/tab.ts index 8921460..0a98984 100644 --- a/src/settings/tab.ts +++ b/src/settings/tab.ts @@ -168,6 +168,23 @@ export default class GitHubSyncSettingsTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName("Sync workspace files") + .setDesc("Sync workspace.json and workspace-mobile.json files") + .addToggle((toggle) => { + toggle + .setValue(this.plugin.settings.syncWorkspaceFiles) + .onChange(async (value) => { + this.plugin.settings.syncWorkspaceFiles = value; + if (value && this.plugin.settings.syncConfigDir) { + await this.plugin.syncManager.addConfigDirToMetadata(); + } else if (!value) { + await this.plugin.syncManager.removeWorkspaceFilesFromMetadata(); + } + await this.plugin.saveSettings(); + }); + }); + const conflictHandlingOptions = { overwriteLocal: "Overwrite local file", ask: "Ask", diff --git a/src/sync-manager.ts b/src/sync-manager.ts index bc71564..551b157 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -233,11 +233,8 @@ export default class SyncManager { return; } - if (targetPath === `${this.vault.configDir}/${LOG_FILE_NAME}`) { - // We don't want to download the log file if the user synced it in the past. - // This is necessary because in the past we forgot to ignore the log file - // from syncing if the user enabled configs sync. - // To avoid downloading it we ignore it if still present in the remote repo. + if (this.isVolatileSyncArtifact(targetPath)) { + await this.logger.info("Skipping volatile sync artifact", targetPath); return; } @@ -588,8 +585,23 @@ export default class SyncManager { return filePath === `${this.vault.configDir}/${LOG_FILE_NAME}`; } + private isWorkspaceFile(filePath: string): boolean { + return ( + filePath === `${this.vault.configDir}/workspace.json` || + filePath === `${this.vault.configDir}/workspace-mobile.json` + ); + } + + private shouldSyncWorkspaceFiles(): boolean { + return this.settings.syncConfigDir && this.settings.syncWorkspaceFiles; + } + private isVolatileSyncArtifact(filePath: string): boolean { - return this.isLogFile(filePath); + // Keep these files out of metadata when they should not be synced. + return ( + this.isLogFile(filePath) || + (this.isWorkspaceFile(filePath) && !this.shouldSyncWorkspaceFiles()) + ); } private filterRemoteMetadataFiles(filesMetadata: { @@ -1143,10 +1155,6 @@ export default class SyncManager { folders.push(...res.folders); } files.forEach((filePath: string) => { - if (filePath === `${this.vault.configDir}/workspace.json`) { - // Obsidian recommends not syncing the workspace file - return; - } if (this.isVolatileSyncArtifact(filePath)) { return; } @@ -1245,6 +1253,21 @@ export default class SyncManager { this.metadataStore.save(); } + /** + * Removes workspace files from local metadata. + * Useful when the user disables workspace files synchronization. + */ + async removeWorkspaceFilesFromMetadata() { + await this.logger.info("Removing workspace files from metadata"); + [ + `${this.vault.configDir}/workspace.json`, + `${this.vault.configDir}/workspace-mobile.json`, + ].forEach((filePath: string) => { + delete this.metadataStore.data.files[filePath]; + }); + this.metadataStore.save(); + } + getFileMetadata(filePath: string): FileMetadata { return this.metadataStore.data.files[filePath]; }