diff --git a/src/CmdSetupLiveSync.ts b/src/CmdSetupLiveSync.ts index 91680be..92bd022 100644 --- a/src/CmdSetupLiveSync.ts +++ b/src/CmdSetupLiveSync.ts @@ -60,7 +60,7 @@ export class SetupLiveSync extends LiveSyncCommands { delete setting[k]; } } - const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase, false, false)); + const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase, false, true)); const uri = `${configURIBase}${encryptedSetting}`; await navigator.clipboard.writeText(uri); Logger("Setup URI copied to clipboard", LOG_LEVEL_NOTICE); @@ -70,7 +70,7 @@ export class SetupLiveSync extends LiveSyncCommands { if (encryptingPassphrase === false) return; const setting = { ...this.settings, configPassphraseStore: "", encryptedCouchDBConnection: "", encryptedPassphrase: "" }; - const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase, false, false)); + const encryptedSetting = encodeURIComponent(await encrypt(JSON.stringify(setting), encryptingPassphrase, false, true)); const uri = `${configURIBase}${encryptedSetting}`; await navigator.clipboard.writeText(uri); Logger("Setup URI copied to clipboard", LOG_LEVEL_NOTICE); diff --git a/src/lib b/src/lib index 609c7ae..b2788a8 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 609c7aecf30aba4da1eeb8b6ea945be3de514c05 +Subproject commit b2788a8d98c1f70590c83576a62d06039059f3d7 diff --git a/src/main.ts b/src/main.ts index 8c36c49..85213e2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -515,58 +515,7 @@ Note: We can always able to read V1 format. It will be progressively converted. return ret == CHOICE_V1; } - async onload() { - logStore.subscribe(e => this.addLog(e.message, e.level, e.key)); - Logger("loading plugin"); - //@ts-ignore - const manifestVersion: string = MANIFEST_VERSION || "0.0.0"; - //@ts-ignore - const packageVersion: string = PACKAGE_VERSION || "0.0.0"; - - this.manifestVersion = manifestVersion; - this.packageVersion = packageVersion; - - Logger(`Self-hosted LiveSync v${manifestVersion} ${packageVersion} `); - const lsKey = "obsidian-live-sync-ver" + this.getVaultName(); - const last_version = localStorage.getItem(lsKey); - await this.loadSettings(); - - const lastVersion = ~~(versionNumberString2Number(manifestVersion) / 1000); - if (lastVersion > this.settings.lastReadUpdates) { - Logger("Self-hosted LiveSync has undergone a major upgrade. Please open the setting dialog, and check the information pane.", LOG_LEVEL_NOTICE); - } - - //@ts-ignore - if (this.app.isMobile) { - this.isMobile = true; - this.settings.disableRequestURI = true; - } - if (last_version && Number(last_version) < VER) { - this.settings.liveSync = false; - this.settings.syncOnSave = false; - this.settings.syncOnEditorSave = false; - this.settings.syncOnStart = false; - this.settings.syncOnFileOpen = false; - this.settings.syncAfterMerge = false; - this.settings.periodicReplication = false; - this.settings.versionUpFlash = "Self-hosted LiveSync has been upgraded and some behaviors have changed incompatibly. All automatic synchronization is now disabled temporary. Ensure that other devices are also upgraded, and enable synchronization again."; - this.saveSettings(); - } - localStorage.setItem(lsKey, `${VER}`); - await this.openDatabase(); - this.watchWorkspaceOpen = debounce(this.watchWorkspaceOpen.bind(this), 1000, false); - this.watchWindowVisibility = debounce(this.watchWindowVisibility.bind(this), 1000, false); - this.watchOnline = debounce(this.watchOnline.bind(this), 500, false); - - this.parseReplicationResult = this.parseReplicationResult.bind(this); - - this.loadQueuedFiles = this.loadQueuedFiles.bind(this); - - this.triggerRealizeSettingSyncMode = debounce(this.triggerRealizeSettingSyncMode.bind(this), 1000); - - this.statusBar = this.addStatusBarItem(); - this.statusBar.addClass("syncstatusbar"); - + addUIs() { addIcon( "replicate", ` @@ -583,14 +532,23 @@ Note: We can always able to read V1 format. It will be progressively converted. ` ); - await Promise.all(this.addOns.map(e => e.onload())); + addIcon( + "custom-sync", + ` + + ` + ); this.addRibbonIcon("replicate", "Replicate", async () => { await this.replicate(true); - }); + }).addClass("livesync-ribbon-replicate"); this.addRibbonIcon("view-log", "Show log", () => { this.showView(VIEW_TYPE_LOG); - }); + }).addClass("livesync-ribbon-showlog"); + this.addRibbonIcon("custom-sync", "Show Customization sync", () => { + this.addOnConfigSync.showPluginSyncModal(); + }).addClass("livesync-ribbon-showcustom"); + this.addCommand({ id: "view-log", name: "Show log", @@ -598,8 +556,6 @@ Note: We can always able to read V1 format. It will be progressively converted. this.showView(VIEW_TYPE_LOG); } }); - this.addSettingTab(new ObsidianLiveSyncSettingTab(this.app, this)); - this.app.workspace.onLayoutReady(this.onLayoutReady.bind(this)); this.addCommand({ id: "livesync-replicate", @@ -672,8 +628,6 @@ Note: We can always able to read V1 format. It will be progressively converted. } }) - this.triggerRealizeSettingSyncMode = debounce(this.triggerRealizeSettingSyncMode.bind(this), 1000); - this.addCommand({ id: "livesync-filehistory", name: "Pick a file to show history", @@ -709,6 +663,13 @@ Note: We can always able to read V1 format. It will be progressively converted. this.replicator.terminateSync(); }, }) + this.addCommand({ + id: "livesync-global-history", + name: "Show vault history", + callback: () => { + this.showGlobalHistory() + } + }) this.registerView( VIEW_TYPE_GLOBAL_HISTORY, @@ -718,13 +679,66 @@ Note: We can always able to read V1 format. It will be progressively converted. VIEW_TYPE_LOG, (leaf) => new LogPaneView(leaf, this) ); - this.addCommand({ - id: "livesync-global-history", - name: "Show vault history", - callback: () => { - this.showGlobalHistory() - } - }) + } + + async onload() { + logStore.subscribe(e => this.addLog(e.message, e.level, e.key)); + Logger("loading plugin"); + this.addSettingTab(new ObsidianLiveSyncSettingTab(this.app, this)); + this.addUIs(); + //@ts-ignore + const manifestVersion: string = MANIFEST_VERSION || "0.0.0"; + //@ts-ignore + const packageVersion: string = PACKAGE_VERSION || "0.0.0"; + + this.manifestVersion = manifestVersion; + this.packageVersion = packageVersion; + + Logger(`Self-hosted LiveSync v${manifestVersion} ${packageVersion} `); + const lsKey = "obsidian-live-sync-ver" + this.getVaultName(); + const last_version = localStorage.getItem(lsKey); + await this.loadSettings(); + this.statusBar = this.addStatusBarItem(); + this.statusBar.addClass("syncstatusbar"); + const lastVersion = ~~(versionNumberString2Number(manifestVersion) / 1000); + if (lastVersion > this.settings.lastReadUpdates) { + Logger("Self-hosted LiveSync has undergone a major upgrade. Please open the setting dialog, and check the information pane.", LOG_LEVEL_NOTICE); + } + + //@ts-ignore + if (this.app.isMobile) { + this.isMobile = true; + this.settings.disableRequestURI = true; + } + if (last_version && Number(last_version) < VER) { + this.settings.liveSync = false; + this.settings.syncOnSave = false; + this.settings.syncOnEditorSave = false; + this.settings.syncOnStart = false; + this.settings.syncOnFileOpen = false; + this.settings.syncAfterMerge = false; + this.settings.periodicReplication = false; + this.settings.versionUpFlash = "Self-hosted LiveSync has been upgraded and some behaviors have changed incompatibly. All automatic synchronization is now disabled temporary. Ensure that other devices are also upgraded, and enable synchronization again."; + this.saveSettings(); + } + localStorage.setItem(lsKey, `${VER}`); + await this.openDatabase(); + this.watchWorkspaceOpen = debounce(this.watchWorkspaceOpen.bind(this), 1000, false); + this.watchWindowVisibility = debounce(this.watchWindowVisibility.bind(this), 1000, false); + this.watchOnline = debounce(this.watchOnline.bind(this), 500, false); + + this.parseReplicationResult = this.parseReplicationResult.bind(this); + + this.loadQueuedFiles = this.loadQueuedFiles.bind(this); + + this.triggerRealizeSettingSyncMode = debounce(this.triggerRealizeSettingSyncMode.bind(this), 1000); + + await Promise.all(this.addOns.map(e => e.onload())); + + this.app.workspace.onLayoutReady(this.onLayoutReady.bind(this)); + + this.triggerRealizeSettingSyncMode = debounce(this.triggerRealizeSettingSyncMode.bind(this), 1000); + } async showView(viewType: string) { const leaves = this.app.workspace.getLeavesOfType(viewType); @@ -1609,6 +1623,9 @@ Note: We can always able to read V1 format. It will be progressively converted. this.replicator.openReplication(this.settings, true, false); } + const q = activeDocument.querySelector(`.livesync-ribbon-showcustom`); + q?.toggleClass("sls-hidden", !this.settings.usePluginSync); + this.periodicSyncProcessor.enable(this.settings.periodicReplication ? this.settings.periodicReplicationInterval * 1000 : 0);