From 45ceca8bb6b7fd89f28239c92665f2dcdcc00b5a Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Wed, 12 Feb 2025 03:44:46 +0000 Subject: [PATCH] run prettier and update lib --- src/lib | 2 +- .../coreFeatures/ModuleCheckRemoteSize.ts | 9 +- src/modules/essential/ModuleMigration.ts | 82 +- .../SettingDialogue/LiveSyncSetting.ts | 15 +- .../ObsidianLiveSyncSettingTab.ts | 1318 +++++++++-------- src/modules/main/ModuleLiveSyncMain.ts | 2 +- 6 files changed, 765 insertions(+), 663 deletions(-) diff --git a/src/lib b/src/lib index 90ace6d..d94133d 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 90ace6de16b92a4cdcf899068084d152173e5ff7 +Subproject commit d94133d964c966e31c7d95bc16a8d7e66d08df22 diff --git a/src/modules/coreFeatures/ModuleCheckRemoteSize.ts b/src/modules/coreFeatures/ModuleCheckRemoteSize.ts index e4c4bba..f01b481 100644 --- a/src/modules/coreFeatures/ModuleCheckRemoteSize.ts +++ b/src/modules/coreFeatures/ModuleCheckRemoteSize.ts @@ -93,9 +93,12 @@ export class ModuleCheckRemoteSize extends AbstractModule implements ICoreModule LOG_LEVEL_INFO ); } else { - this._log($msg("moduleCheckRemoteSize.logCurrentStorageSize", { - measuredSize: sizeToHumanReadable(estimatedSize), - }), LOG_LEVEL_INFO); + this._log( + $msg("moduleCheckRemoteSize.logCurrentStorageSize", { + measuredSize: sizeToHumanReadable(estimatedSize), + }), + LOG_LEVEL_INFO + ); } } } diff --git a/src/modules/essential/ModuleMigration.ts b/src/modules/essential/ModuleMigration.ts index 982f570..2fd2eca 100644 --- a/src/modules/essential/ModuleMigration.ts +++ b/src/modules/essential/ModuleMigration.ts @@ -13,7 +13,7 @@ import { $msg } from "src/lib/src/common/i18n.ts"; export class ModuleMigration extends AbstractModule implements ICoreModule { async migrateDisableBulkSend() { if (this.settings.sendChunksBulk) { - this._log($msg('moduleMigration.logBulkSendCorrupted'), LOG_LEVEL_NOTICE); + this._log($msg("moduleMigration.logBulkSendCorrupted"), LOG_LEVEL_NOTICE); this.settings.sendChunksBulk = false; this.settings.sendChunksBulkMaxSize = 1; await this.saveSettings(); @@ -24,10 +24,13 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { const current = SETTING_VERSION_SUPPORT_CASE_INSENSITIVE; // Check each migrations(old -> current) if (!(await this.migrateToCaseInsensitive(old, current))) { - this._log($msg('moduleMigration.logMigrationFailed', { - old: old.toString(), - current: current.toString() - }), LOG_LEVEL_NOTICE); + this._log( + $msg("moduleMigration.logMigrationFailed", { + old: old.toString(), + current: current.toString(), + }), + LOG_LEVEL_NOTICE + ); return; } } @@ -67,10 +70,10 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { remoteChecked = true; } } else { - this._log($msg('moduleMigration.logFetchRemoteTweakFailed'), LOG_LEVEL_INFO); + this._log($msg("moduleMigration.logFetchRemoteTweakFailed"), LOG_LEVEL_INFO); } } catch (ex) { - this._log($msg('moduleMigration.logRemoteTweakUnavailable'), LOG_LEVEL_INFO); + this._log($msg("moduleMigration.logRemoteTweakUnavailable"), LOG_LEVEL_INFO); this._log(ex, LOG_LEVEL_VERBOSE); } @@ -81,18 +84,21 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { this.settings.handleFilenameCaseSensitive = true; this.settings.doNotUseFixedRevisionForChunks = true; this.settings.settingVersion = SETTING_VERSION_SUPPORT_CASE_INSENSITIVE; - this._log($msg('moduleMigration.logMigratedSameBehaviour', { - current: current.toString() - }), LOG_LEVEL_INFO); + this._log( + $msg("moduleMigration.logMigratedSameBehaviour", { + current: current.toString(), + }), + LOG_LEVEL_INFO + ); await this.saveSettings(); return true; } - const message = $msg('moduleMigration.msgFetchRemoteAgain'); - const OPTION_FETCH = $msg('moduleMigration.optionYesFetchAgain'); - const DISMISS = $msg('moduleMigration.optionNoAskAgain'); + const message = $msg("moduleMigration.msgFetchRemoteAgain"); + const OPTION_FETCH = $msg("moduleMigration.optionYesFetchAgain"); + const DISMISS = $msg("moduleMigration.optionNoAskAgain"); const options = [OPTION_FETCH, DISMISS]; const ret = await this.core.confirm.confirmWithMessage( - $msg('moduleMigration.titleCaseSensitivity'), + $msg("moduleMigration.titleCaseSensitivity"), message, options, DISMISS, @@ -107,7 +113,7 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { await this.core.rebuilder.scheduleFetch(); return; } catch (ex) { - this._log($msg('moduleMigration.logRedflag2CreationFail'), LOG_LEVEL_VERBOSE); + this._log($msg("moduleMigration.logRedflag2CreationFail"), LOG_LEVEL_VERBOSE); this._log(ex, LOG_LEVEL_VERBOSE); } return false; @@ -116,19 +122,25 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { } } - const ENABLE_BOTH = $msg('moduleMigration.optionEnableBoth'); - const ENABLE_FILENAME_CASE_INSENSITIVE = $msg('moduleMigration.optionEnableFilenameCaseInsensitive'); - const ENABLE_FIXED_REVISION_FOR_CHUNKS = $msg('moduleMigration.optionEnableFixedRevisionForChunks'); - const ADJUST_TO_REMOTE = $msg('moduleMigration.optionAdjustRemote'); - const KEEP = $msg('moduleMigration.optionKeepPreviousBehaviour'); - const DISMISS = $msg('moduleMigration.optionDecideLater'); - const message = $msg('moduleMigration.msgSinceV02321'); + const ENABLE_BOTH = $msg("moduleMigration.optionEnableBoth"); + const ENABLE_FILENAME_CASE_INSENSITIVE = $msg("moduleMigration.optionEnableFilenameCaseInsensitive"); + const ENABLE_FIXED_REVISION_FOR_CHUNKS = $msg("moduleMigration.optionEnableFixedRevisionForChunks"); + const ADJUST_TO_REMOTE = $msg("moduleMigration.optionAdjustRemote"); + const KEEP = $msg("moduleMigration.optionKeepPreviousBehaviour"); + const DISMISS = $msg("moduleMigration.optionDecideLater"); + const message = $msg("moduleMigration.msgSinceV02321"); const options = [ENABLE_BOTH, ENABLE_FILENAME_CASE_INSENSITIVE, ENABLE_FIXED_REVISION_FOR_CHUNKS]; if (remoteChecked) { options.push(ADJUST_TO_REMOTE); } options.push(KEEP, DISMISS); - const ret = await this.core.confirm.confirmWithMessage($msg('moduleMigration.titleCaseSensitivity'), message, options, DISMISS, 40); + const ret = await this.core.confirm.confirmWithMessage( + $msg("moduleMigration.titleCaseSensitivity"), + message, + options, + DISMISS, + 40 + ); console.dir(ret); switch (ret) { case ENABLE_BOTH: @@ -160,14 +172,14 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { } async initialMessage() { - const message = $msg('moduleMigration.msgInitialSetup', { - URI_DOC: $msg('moduleMigration.docUri'), + const message = $msg("moduleMigration.msgInitialSetup", { + URI_DOC: $msg("moduleMigration.docUri"), }); - const USE_SETUP = $msg('moduleMigration.optionHaveSetupUri'); - const NEXT = $msg('moduleMigration.optionNoSetupUri'); + const USE_SETUP = $msg("moduleMigration.optionHaveSetupUri"); + const NEXT = $msg("moduleMigration.optionNoSetupUri"); const ret = await this.core.confirm.askSelectStringDialogue(message, [USE_SETUP, NEXT], { - title: $msg('moduleMigration.titleWelcome'), + title: $msg("moduleMigration.titleWelcome"), defaultAction: USE_SETUP, }); if (ret === USE_SETUP) { @@ -180,13 +192,13 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { } async askAgainForSetupURI() { - const message = $msg('moduleMigration.msgRecommendSetupUri', { URI_DOC: $msg('moduleMigration.docUri') }); - const USE_MINIMAL = $msg('moduleMigration.optionSetupWizard'); - const USE_SETUP = $msg('moduleMigration.optionManualSetup'); - const NEXT = $msg('moduleMigration.optionRemindNextLaunch'); + const message = $msg("moduleMigration.msgRecommendSetupUri", { URI_DOC: $msg("moduleMigration.docUri") }); + const USE_MINIMAL = $msg("moduleMigration.optionSetupWizard"); + const USE_SETUP = $msg("moduleMigration.optionManualSetup"); + const NEXT = $msg("moduleMigration.optionRemindNextLaunch"); const ret = await this.core.confirm.askSelectStringDialogue(message, [USE_MINIMAL, USE_SETUP, NEXT], { - title: $msg('moduleMigration.titleRecommendSetupUri'), + title: $msg("moduleMigration.titleRecommendSetupUri"), defaultAction: USE_MINIMAL, }); if (ret === USE_MINIMAL) { @@ -204,7 +216,7 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { async $everyOnFirstInitialize(): Promise { if (!this.localDatabase.isReady) { - this._log($msg('moduleMigration.logLocalDatabaseNotReady'), LOG_LEVEL_NOTICE); + this._log($msg("moduleMigration.logLocalDatabaseNotReady"), LOG_LEVEL_NOTICE); return false; } if (this.settings.isConfigured) { @@ -214,7 +226,7 @@ export class ModuleMigration extends AbstractModule implements ICoreModule { if (!this.settings.isConfigured) { // Case sensitivity if (!(await this.initialMessage()) || !(await this.askAgainForSetupURI())) { - this._log($msg('moduleMigration.logSetupCancelled'), LOG_LEVEL_NOTICE); + this._log($msg("moduleMigration.logSetupCancelled"), LOG_LEVEL_NOTICE); return false; } } diff --git a/src/modules/features/SettingDialogue/LiveSyncSetting.ts b/src/modules/features/SettingDialogue/LiveSyncSetting.ts index e64c6ea..14d3ea6 100644 --- a/src/modules/features/SettingDialogue/LiveSyncSetting.ts +++ b/src/modules/features/SettingDialogue/LiveSyncSetting.ts @@ -218,13 +218,10 @@ export class LiveSyncSetting extends Setting { await this.commitValue(value); } else { this.setTooltip( - $msg( - "liveSyncSetting.valueShouldBeInRange", - { - min: opt.clampMin?.toString() || "~", - max: opt.clampMax?.toString() || "~", - } - ) + $msg("liveSyncSetting.valueShouldBeInRange", { + min: opt.clampMin?.toString() || "~", + max: opt.clampMax?.toString() || "~", + }) ); text.inputEl.toggleClass("sls-item-invalid-value", true); lastError = true; @@ -373,7 +370,9 @@ export class LiveSyncSetting extends Setting { if (this.holdValue && this.selfKey) { const isDirty = LiveSyncSetting.env.isDirty(this.selfKey); const alt = isDirty - ? $msg("liveSyncSetting.originalValue", { value: String(LiveSyncSetting.env.initialSettings?.[this.selfKey] ?? "") }) + ? $msg("liveSyncSetting.originalValue", { + value: String(LiveSyncSetting.env.initialSettings?.[this.selfKey] ?? ""), + }) : ""; this.controlEl.toggleClass("sls-item-dirty", isDirty); if (!this.hasPassword) { diff --git a/src/modules/features/SettingDialogue/ObsidianLiveSyncSettingTab.ts b/src/modules/features/SettingDialogue/ObsidianLiveSyncSettingTab.ts index 6964667..819c061 100644 --- a/src/modules/features/SettingDialogue/ObsidianLiveSyncSettingTab.ts +++ b/src/modules/features/SettingDialogue/ObsidianLiveSyncSettingTab.ts @@ -119,10 +119,10 @@ function getLevelStr(level: ConfigLevel) { return level == LEVEL_POWER_USER ? $msg("obsidianLiveSyncSettingTab.levelPowerUser") : level == LEVEL_ADVANCED - ? $msg("obsidianLiveSyncSettingTab.levelAdvanced") - : level == LEVEL_EDGE_CASE - ? $msg("obsidianLiveSyncSettingTab.levelEdgeCase") - : ""; + ? $msg("obsidianLiveSyncSettingTab.levelAdvanced") + : level == LEVEL_EDGE_CASE + ? $msg("obsidianLiveSyncSettingTab.levelEdgeCase") + : ""; } export function findAttrFromParent(el: HTMLElement, attr: string): string { @@ -384,7 +384,12 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { const status = await replicator.getRemoteStatus(trialSetting); if (status) { if (status.estimatedSize) { - Logger($msg("obsidianLiveSyncSettingTab.logEstimatedSize", { size: sizeToHumanReadable(status.estimatedSize) }), LOG_LEVEL_NOTICE); + Logger( + $msg("obsidianLiveSyncSettingTab.logEstimatedSize", { + size: sizeToHumanReadable(status.estimatedSize), + }), + LOG_LEVEL_NOTICE + ); } } } @@ -464,7 +469,9 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { // And modified. this.plugin.confirm.askInPopup( `config-reloaded-${k}`, - $msg("obsidianLiveSyncSettingTab.msgSettingModified", { setting: getConfName(k as AllSettingItemKey) }), + $msg("obsidianLiveSyncSettingTab.msgSettingModified", { + setting: getConfName(k as AllSettingItemKey), + }), (anchor) => { anchor.text = $msg("obsidianLiveSyncSettingTab.optionHere"); anchor.addEventListener("click", () => { @@ -632,9 +639,12 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { if (result == OPTION_FETCH) { if (!(await checkWorkingPassphrase())) { if ( - (await this.plugin.confirm.askYesNoDialog($msg("obsidianLiveSyncSettingTab.msgAreYouSureProceed"), { - defaultOption: "No", - })) != "yes" + (await this.plugin.confirm.askYesNoDialog( + $msg("obsidianLiveSyncSettingTab.msgAreYouSureProceed"), + { + defaultOption: "No", + } + )) != "yes" ) return; } @@ -664,9 +674,14 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { (el) => { el.addClass("wizardHidden"); el.createEl("label", { text: $msg("obsidianLiveSyncSettingTab.msgChangesNeedToBeApplied") }); - void this.addEl(el, "button", { text: $msg("obsidianLiveSyncSettingTab.optionApply"), cls: "mod-warning" }, (buttonEl) => { - buttonEl.addEventListener("click", () => fireAndForget(async () => await confirmRebuild())); - }); + void this.addEl( + el, + "button", + { text: $msg("obsidianLiveSyncSettingTab.optionApply"), cls: "mod-warning" }, + (buttonEl) => { + buttonEl.addEventListener("click", () => fireAndForget(async () => await confirmRebuild())); + } + ); }, visibleOnly(() => isNeedRebuildLocal() || isNeedRebuildRemote()) ); @@ -828,10 +843,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { // Logger($msg("obsidianLiveSyncSettingTab.logDatabaseConnected"), LOG_LEVEL_NOTICE); return true; } else { - Logger( - $msg("obsidianLiveSyncSettingTab.logPassphraseNotCompatible"), - LOG_LEVEL_NOTICE - ); + Logger($msg("obsidianLiveSyncSettingTab.logPassphraseNotCompatible"), LOG_LEVEL_NOTICE); return false; } } @@ -875,28 +887,30 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { }; // Panes - void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.panelChangeLog"), "💬", 100, false).then((paneEl) => { - const informationDivEl = this.createEl(paneEl, "div", { text: "" }); + void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.panelChangeLog"), "💬", 100, false).then( + (paneEl) => { + const informationDivEl = this.createEl(paneEl, "div", { text: "" }); - const tmpDiv = createDiv(); - // tmpDiv.addClass("sls-header-button"); - tmpDiv.addClass("op-warn-info"); + const tmpDiv = createDiv(); + // tmpDiv.addClass("sls-header-button"); + tmpDiv.addClass("op-warn-info"); - tmpDiv.innerHTML = `

${$msg("obsidianLiveSyncSettingTab.msgNewVersionNote")}

` - if (lastVersion > (this.editingSettings?.lastReadUpdates || 0)) { - const informationButtonDiv = informationDivEl.appendChild(tmpDiv); - informationButtonDiv.querySelector("button")?.addEventListener("click", () => { - fireAndForget(async () => { - this.editingSettings.lastReadUpdates = lastVersion; - await this.saveAllDirtySettings(); - informationButtonDiv.remove(); + tmpDiv.innerHTML = `

${$msg("obsidianLiveSyncSettingTab.msgNewVersionNote")}

`; + if (lastVersion > (this.editingSettings?.lastReadUpdates || 0)) { + const informationButtonDiv = informationDivEl.appendChild(tmpDiv); + informationButtonDiv.querySelector("button")?.addEventListener("click", () => { + fireAndForget(async () => { + this.editingSettings.lastReadUpdates = lastVersion; + await this.saveAllDirtySettings(); + informationButtonDiv.remove(); + }); }); - }); + } + fireAndForget(() => + MarkdownRenderer.render(this.plugin.app, updateInformation, informationDivEl, "/", this.plugin) + ); } - fireAndForget(() => - MarkdownRenderer.render(this.plugin.app, updateInformation, informationDivEl, "/", this.plugin) - ); - }); + ); void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.panelSetup"), "🧙‍♂️", 110, false).then((paneEl) => { void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleQuickSetup")).then((paneEl) => { @@ -1077,40 +1091,42 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { void loadMarkdownPage(topPath); }); }); - void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.panelGeneralSettings"), "⚙️", 20, false).then((paneEl) => { - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleAppearance")).then((paneEl) => { - const languages = Object.fromEntries([ - ["", $msg("obsidianLiveSyncSettingTab.defaultLanguage")], - ...SUPPORTED_I18N_LANGS.map((e) => [e, $t(`lang-${e}`)]), - ]) as Record; - new Setting(paneEl).autoWireDropDown("displayLanguage", { - options: languages, + void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.panelGeneralSettings"), "⚙️", 20, false).then( + (paneEl) => { + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleAppearance")).then((paneEl) => { + const languages = Object.fromEntries([ + ["", $msg("obsidianLiveSyncSettingTab.defaultLanguage")], + ...SUPPORTED_I18N_LANGS.map((e) => [e, $t(`lang-${e}`)]), + ]) as Record; + new Setting(paneEl).autoWireDropDown("displayLanguage", { + options: languages, + }); + this.addOnSaved("displayLanguage", () => this.display()); + new Setting(paneEl).autoWireToggle("showStatusOnEditor"); + new Setting(paneEl).autoWireToggle("showOnlyIconsOnEditor", { + onUpdate: visibleOnly(() => this.isConfiguredAs("showStatusOnEditor", true)), + }); + new Setting(paneEl).autoWireToggle("showStatusOnStatusbar"); }); - this.addOnSaved("displayLanguage", () => this.display()); - new Setting(paneEl).autoWireToggle("showStatusOnEditor"); - new Setting(paneEl).autoWireToggle("showOnlyIconsOnEditor", { - onUpdate: visibleOnly(() => this.isConfiguredAs("showStatusOnEditor", true)), - }); - new Setting(paneEl).autoWireToggle("showStatusOnStatusbar"); - }); - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleLogging")).then((paneEl) => { - paneEl.addClass("wizardHidden"); + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleLogging")).then((paneEl) => { + paneEl.addClass("wizardHidden"); - new Setting(paneEl).autoWireToggle("lessInformationInLog"); + new Setting(paneEl).autoWireToggle("lessInformationInLog"); - new Setting(paneEl).autoWireToggle("showVerboseLog", { - onUpdate: visibleOnly(() => this.isConfiguredAs("lessInformationInLog", false)), + new Setting(paneEl).autoWireToggle("showVerboseLog", { + onUpdate: visibleOnly(() => this.isConfiguredAs("lessInformationInLog", false)), + }); }); - }); - new Setting(paneEl).setClass("wizardOnly").addButton((button) => - button - .setButtonText($msg("obsidianLiveSyncSettingTab.btnNext")) - .setCta() - .onClick(() => { - this.changeDisplay("0"); - }) - ); - }); + new Setting(paneEl).setClass("wizardOnly").addButton((button) => + button + .setButtonText($msg("obsidianLiveSyncSettingTab.btnNext")) + .setCta() + .onClick(() => { + this.changeDisplay("0"); + }) + ); + } + ); let checkResultDiv: HTMLDivElement; const checkConfig = async (checkResultDiv: HTMLDivElement | undefined) => { Logger($msg("obsidianLiveSyncSettingTab.logCheckingDbConfig"), LOG_LEVEL_INFO); @@ -1159,11 +1175,17 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { value ); if (res.status == 200) { - Logger($msg("obsidianLiveSyncSettingTab.logCouchDbConfigUpdated", { title }), LOG_LEVEL_NOTICE); + Logger( + $msg("obsidianLiveSyncSettingTab.logCouchDbConfigUpdated", { title }), + LOG_LEVEL_NOTICE + ); checkResultDiv.removeChild(x); await checkConfig(checkResultDiv); } else { - Logger($msg("obsidianLiveSyncSettingTab.logCouchDbConfigFail", { title }), LOG_LEVEL_NOTICE); + Logger( + $msg("obsidianLiveSyncSettingTab.logCouchDbConfigFail", { title }), + LOG_LEVEL_NOTICE + ); Logger(res.text, LOG_LEVEL_VERBOSE); } }); @@ -1254,7 +1276,11 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { if (responseConfig?.cors?.credentials != "true") { isSuccessful = false; addResult($msg("obsidianLiveSyncSettingTab.errCorsCredentials")); - addConfigFixButton($msg("obsidianLiveSyncSettingTab.msgSetCorsCredentials"), "cors/credentials", "true"); + addConfigFixButton( + $msg("obsidianLiveSyncSettingTab.msgSetCorsCredentials"), + "cors/credentials", + "true" + ); } else { addResult($msg("obsidianLiveSyncSettingTab.okCorsCredentials")); } @@ -1329,580 +1355,642 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { return isSuccessful; }; - void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.panelRemoteConfiguration"), "🛰️", 0, false).then((paneEl) => { - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleRemoteServer")).then((paneEl) => { - // const containerRemoteDatabaseEl = containerEl.createDiv(); - new Setting(paneEl).autoWireDropDown("remoteType", { - holdValue: true, - options: { - [REMOTE_COUCHDB]: $msg("obsidianLiveSyncSettingTab.optionCouchDB"), - [REMOTE_MINIO]: $msg("obsidianLiveSyncSettingTab.optionMinioS3R2"), - }, - onUpdate: enableOnlySyncDisabled, - }); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleMinioS3R2"), undefined, onlyOnMinIO).then((paneEl) => { - const syncWarnMinio = this.createEl(paneEl, "div", { - text: "", - }); - const ObjectStorageMessage = $msg("obsidianLiveSyncSettingTab.msgObjectStorageWarning"); - - void MarkdownRenderer.render( - this.plugin.app, - ObjectStorageMessage, - syncWarnMinio, - "/", - this.plugin - ); - syncWarnMinio.addClass("op-warn-info"); - - new Setting(paneEl).autoWireText("endpoint", { holdValue: true }); - new Setting(paneEl).autoWireText("accessKey", { holdValue: true }); - - new Setting(paneEl).autoWireText("secretKey", { + void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.panelRemoteConfiguration"), "🛰️", 0, false).then( + (paneEl) => { + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleRemoteServer")).then((paneEl) => { + // const containerRemoteDatabaseEl = containerEl.createDiv(); + new Setting(paneEl).autoWireDropDown("remoteType", { holdValue: true, - isPassword: true, - }); - - new Setting(paneEl).autoWireText("region", { holdValue: true }); - - new Setting(paneEl).autoWireText("bucket", { holdValue: true }); - - new Setting(paneEl).autoWireToggle("useCustomRequestHandler", { holdValue: true }); - new Setting(paneEl).setName($msg("obsidianLiveSyncSettingTab.nameTestConnection")).addButton((button) => - button - .setButtonText($msg("obsidianLiveSyncSettingTab.btnTest")) - .setDisabled(false) - .onClick(async () => { - await this.testConnection(this.editingSettings); - }) - ); - new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.nameApplySettings")) - .setClass("wizardHidden") - .addApplyButton([ - "remoteType", - "endpoint", - "region", - "accessKey", - "secretKey", - "bucket", - "useCustomRequestHandler", - ]) - .addOnUpdate(onlyOnMinIO); - }); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleCouchDB"), undefined, onlyOnCouchDB).then((paneEl) => { - if (this.plugin.$$isMobile()) { - this.createEl( - paneEl, - "div", - { - text:$msg("obsidianLiveSyncSettingTab.msgNonHTTPSWarning"), - }, - undefined, - visibleOnly(() => !this.editingSettings.couchDB_URI.startsWith("https://")) - ).addClass("op-warn"); - } else { - this.createEl( - paneEl, - "div", - { - text: $msg("obsidianLiveSyncSettingTab.msgNonHTTPSInfo"), - }, - undefined, - visibleOnly(() => !this.editingSettings.couchDB_URI.startsWith("https://")) - ).addClass("op-warn-info"); - } - - this.createEl( - paneEl, - "div", - { - text: $msg("obsidianLiveSyncSettingTab.msgSettingsUnchangeableDuringSync"), + options: { + [REMOTE_COUCHDB]: $msg("obsidianLiveSyncSettingTab.optionCouchDB"), + [REMOTE_MINIO]: $msg("obsidianLiveSyncSettingTab.optionMinioS3R2"), }, - undefined, - visibleOnly(() => isAnySyncEnabled()) - ).addClass("sls-setting-hidden"); + onUpdate: enableOnlySyncDisabled, + }); - new Setting(paneEl).autoWireText("couchDB_URI", { - holdValue: true, - onUpdate: enableOnlySyncDisabled, + void addPanel( + paneEl, + $msg("obsidianLiveSyncSettingTab.titleMinioS3R2"), + undefined, + onlyOnMinIO + ).then((paneEl) => { + const syncWarnMinio = this.createEl(paneEl, "div", { + text: "", + }); + const ObjectStorageMessage = $msg("obsidianLiveSyncSettingTab.msgObjectStorageWarning"); + + void MarkdownRenderer.render( + this.plugin.app, + ObjectStorageMessage, + syncWarnMinio, + "/", + this.plugin + ); + syncWarnMinio.addClass("op-warn-info"); + + new Setting(paneEl).autoWireText("endpoint", { holdValue: true }); + new Setting(paneEl).autoWireText("accessKey", { holdValue: true }); + + new Setting(paneEl).autoWireText("secretKey", { + holdValue: true, + isPassword: true, + }); + + new Setting(paneEl).autoWireText("region", { holdValue: true }); + + new Setting(paneEl).autoWireText("bucket", { holdValue: true }); + + new Setting(paneEl).autoWireToggle("useCustomRequestHandler", { holdValue: true }); + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameTestConnection")) + .addButton((button) => + button + .setButtonText($msg("obsidianLiveSyncSettingTab.btnTest")) + .setDisabled(false) + .onClick(async () => { + await this.testConnection(this.editingSettings); + }) + ); + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameApplySettings")) + .setClass("wizardHidden") + .addApplyButton([ + "remoteType", + "endpoint", + "region", + "accessKey", + "secretKey", + "bucket", + "useCustomRequestHandler", + ]) + .addOnUpdate(onlyOnMinIO); }); - new Setting(paneEl).autoWireText("couchDB_USER", { - holdValue: true, - onUpdate: enableOnlySyncDisabled, + + void addPanel( + paneEl, + $msg("obsidianLiveSyncSettingTab.titleCouchDB"), + undefined, + onlyOnCouchDB + ).then((paneEl) => { + if (this.plugin.$$isMobile()) { + this.createEl( + paneEl, + "div", + { + text: $msg("obsidianLiveSyncSettingTab.msgNonHTTPSWarning"), + }, + undefined, + visibleOnly(() => !this.editingSettings.couchDB_URI.startsWith("https://")) + ).addClass("op-warn"); + } else { + this.createEl( + paneEl, + "div", + { + text: $msg("obsidianLiveSyncSettingTab.msgNonHTTPSInfo"), + }, + undefined, + visibleOnly(() => !this.editingSettings.couchDB_URI.startsWith("https://")) + ).addClass("op-warn-info"); + } + + this.createEl( + paneEl, + "div", + { + text: $msg("obsidianLiveSyncSettingTab.msgSettingsUnchangeableDuringSync"), + }, + undefined, + visibleOnly(() => isAnySyncEnabled()) + ).addClass("sls-setting-hidden"); + + new Setting(paneEl).autoWireText("couchDB_URI", { + holdValue: true, + onUpdate: enableOnlySyncDisabled, + }); + new Setting(paneEl).autoWireText("couchDB_USER", { + holdValue: true, + onUpdate: enableOnlySyncDisabled, + }); + new Setting(paneEl).autoWireText("couchDB_PASSWORD", { + holdValue: true, + isPassword: true, + onUpdate: enableOnlySyncDisabled, + }); + new Setting(paneEl).autoWireText("couchDB_DBNAME", { + holdValue: true, + onUpdate: enableOnlySyncDisabled, + }); + + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameTestDatabaseConnection")) + .setClass("wizardHidden") + .setDesc($msg("obsidianLiveSyncSettingTab.descTestDatabaseConnection")) + .addButton((button) => + button + .setButtonText($msg("obsidianLiveSyncSettingTab.btnTest")) + .setDisabled(false) + .onClick(async () => { + await this.testConnection(); + }) + ); + + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameValidateDatabaseConfig")) + .setDesc($msg("obsidianLiveSyncSettingTab.descValidateDatabaseConfig")) + .addButton((button) => + button + .setButtonText($msg("obsidianLiveSyncSettingTab.btnCheck")) + .setDisabled(false) + .onClick(async () => { + await checkConfig(checkResultDiv); + }) + ); + checkResultDiv = this.createEl(paneEl, "div", { + text: "", + }); + + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameApplySettings")) + .setClass("wizardHidden") + .addApplyButton([ + "remoteType", + "couchDB_URI", + "couchDB_USER", + "couchDB_PASSWORD", + "couchDB_DBNAME", + ]) + .addOnUpdate(onlyOnCouchDB); }); - new Setting(paneEl).autoWireText("couchDB_PASSWORD", { + }); + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleNotification")).then((paneEl) => { + paneEl.addClass("wizardHidden"); + new Setting(paneEl) + .autoWireNumeric("notifyThresholdOfRemoteStorageSize", {}) + .setClass("wizardHidden"); + }); + + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.panelPrivacyEncryption")).then((paneEl) => { + new Setting(paneEl).autoWireToggle("encrypt", { holdValue: true }); + + const isEncryptEnabled = visibleOnly(() => this.isConfiguredAs("encrypt", true)); + + new Setting(paneEl).autoWireText("passphrase", { holdValue: true, isPassword: true, - onUpdate: enableOnlySyncDisabled, - }); - new Setting(paneEl).autoWireText("couchDB_DBNAME", { - holdValue: true, - onUpdate: enableOnlySyncDisabled, + onUpdate: isEncryptEnabled, }); - new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.nameTestDatabaseConnection")) - .setClass("wizardHidden") - .setDesc($msg("obsidianLiveSyncSettingTab.descTestDatabaseConnection")) - .addButton((button) => - button - .setButtonText($msg("obsidianLiveSyncSettingTab.btnTest")) - .setDisabled(false) - .onClick(async () => { - await this.testConnection(); - }) - ); - - new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.nameValidateDatabaseConfig")) - .setDesc($msg("obsidianLiveSyncSettingTab.descValidateDatabaseConfig")) - .addButton((button) => - button - .setButtonText($msg("obsidianLiveSyncSettingTab.btnCheck")) - .setDisabled(false) - .onClick(async () => { - await checkConfig(checkResultDiv); - }) - ); - checkResultDiv = this.createEl(paneEl, "div", { - text: "", - }); - - new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.nameApplySettings")) - .setClass("wizardHidden") - .addApplyButton([ - "remoteType", - "couchDB_URI", - "couchDB_USER", - "couchDB_PASSWORD", - "couchDB_DBNAME", - ]) - .addOnUpdate(onlyOnCouchDB); - }); - }); - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleNotification")).then((paneEl) => { - paneEl.addClass("wizardHidden"); - new Setting(paneEl).autoWireNumeric("notifyThresholdOfRemoteStorageSize", {}).setClass("wizardHidden"); - }); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.panelPrivacyEncryption")).then((paneEl) => { - new Setting(paneEl).autoWireToggle("encrypt", { holdValue: true }); - - const isEncryptEnabled = visibleOnly(() => this.isConfiguredAs("encrypt", true)); - - new Setting(paneEl).autoWireText("passphrase", { - holdValue: true, - isPassword: true, - onUpdate: isEncryptEnabled, - }); - - new Setting(paneEl).autoWireToggle("usePathObfuscation", { - holdValue: true, - onUpdate: isEncryptEnabled, - }); - new Setting(paneEl) - .autoWireToggle("useDynamicIterationCount", { + new Setting(paneEl).autoWireToggle("usePathObfuscation", { holdValue: true, onUpdate: isEncryptEnabled, - }) - .setClass("wizardHidden"); - }); + }); + new Setting(paneEl) + .autoWireToggle("useDynamicIterationCount", { + holdValue: true, + onUpdate: isEncryptEnabled, + }) + .setClass("wizardHidden"); + }); - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleFetchSettings")).then((paneEl) => { - new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.titleFetchConfigFromRemote")) - .setDesc($msg("obsidianLiveSyncSettingTab.descFetchConfigFromRemote")) - .addButton((button) => - button - .setButtonText($msg("obsidianLiveSyncSettingTab.buttonFetch")) - .setDisabled(false) - .onClick(async () => { + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleFetchSettings")).then((paneEl) => { + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.titleFetchConfigFromRemote")) + .setDesc($msg("obsidianLiveSyncSettingTab.descFetchConfigFromRemote")) + .addButton((button) => + button + .setButtonText($msg("obsidianLiveSyncSettingTab.buttonFetch")) + .setDisabled(false) + .onClick(async () => { + const trialSetting = { ...this.initialSettings, ...this.editingSettings }; + const newTweaks = + await this.plugin.$$checkAndAskUseRemoteConfiguration(trialSetting); + if (newTweaks.result !== false) { + this.editingSettings = { ...this.editingSettings, ...newTweaks.result }; + this.requestUpdate(); + } + }) + ); + }); + new Setting(paneEl).setClass("wizardOnly").addButton((button) => + button + .setButtonText($msg("obsidianLiveSyncSettingTab.buttonNext")) + .setCta() + .setDisabled(false) + .onClick(async () => { + if (!(await checkConfig(checkResultDiv))) { + if ( + (await this.plugin.confirm.askYesNoDialog( + $msg("obsidianLiveSyncSettingTab.msgConfigCheckFailed"), + { + defaultOption: "No", + title: $msg("obsidianLiveSyncSettingTab.titleRemoteConfigCheckFailed"), + } + )) == "no" + ) { + return; + } + } + const isEncryptionFullyEnabled = + !this.editingSettings.encrypt || !this.editingSettings.usePathObfuscation; + if (isEncryptionFullyEnabled) { + if ( + (await this.plugin.confirm.askYesNoDialog( + $msg("obsidianLiveSyncSettingTab.msgEnableEncryptionRecommendation"), + { + defaultOption: "No", + title: $msg("obsidianLiveSyncSettingTab.titleEncryptionNotEnabled"), + } + )) == "no" + ) { + return; + } + } + if (!this.editingSettings.encrypt) { + this.editingSettings.passphrase = ""; + } + if (!(await isPassphraseValid())) { + if ( + (await this.plugin.confirm.askYesNoDialog( + $msg("obsidianLiveSyncSettingTab.msgInvalidPassphrase"), + { + defaultOption: "No", + title: $msg("obsidianLiveSyncSettingTab.titleEncryptionPassphraseInvalid"), + } + )) == "no" + ) { + return; + } + } + if (isCloudantURI(this.editingSettings.couchDB_URI)) { + this.editingSettings = { ...this.editingSettings, ...PREFERRED_SETTING_CLOUDANT }; + } else if (this.editingSettings.remoteType == REMOTE_MINIO) { + this.editingSettings = { ...this.editingSettings, ...PREFERRED_JOURNAL_SYNC }; + } else { + this.editingSettings = { ...this.editingSettings, ...PREFERRED_SETTING_SELF_HOSTED }; + } + if ( + (await this.plugin.confirm.askYesNoDialog( + $msg("obsidianLiveSyncSettingTab.msgFetchConfigFromRemote"), + { defaultOption: "Yes", title: $msg("obsidianLiveSyncSettingTab.titleFetchConfig") } + )) == "yes" + ) { const trialSetting = { ...this.initialSettings, ...this.editingSettings }; const newTweaks = await this.plugin.$$checkAndAskUseRemoteConfiguration(trialSetting); if (newTweaks.result !== false) { this.editingSettings = { ...this.editingSettings, ...newTweaks.result }; this.requestUpdate(); + } else { + // Messages should be already shown. } - }) - ); - }); - new Setting(paneEl).setClass("wizardOnly").addButton((button) => - button - .setButtonText($msg("obsidianLiveSyncSettingTab.buttonNext")) - .setCta() - .setDisabled(false) - .onClick(async () => { - if (!(await checkConfig(checkResultDiv))) { - if ( - (await this.plugin.confirm.askYesNoDialog( - $msg("obsidianLiveSyncSettingTab.msgConfigCheckFailed"), - { defaultOption: "No", title: $msg("obsidianLiveSyncSettingTab.titleRemoteConfigCheckFailed") } - )) == "no" - ) { - return; } - } - const isEncryptionFullyEnabled = - !this.editingSettings.encrypt || !this.editingSettings.usePathObfuscation; - if (isEncryptionFullyEnabled) { - if ( - (await this.plugin.confirm.askYesNoDialog( - $msg("obsidianLiveSyncSettingTab.msgEnableEncryptionRecommendation"), - { defaultOption: "No", title: $msg("obsidianLiveSyncSettingTab.titleEncryptionNotEnabled") } - )) == "no" - ) { - return; - } - } - if (!this.editingSettings.encrypt) { - this.editingSettings.passphrase = ""; - } - if (!(await isPassphraseValid())) { - if ( - (await this.plugin.confirm.askYesNoDialog( - $msg("obsidianLiveSyncSettingTab.msgInvalidPassphrase"), - { defaultOption: "No", title: $msg("obsidianLiveSyncSettingTab.titleEncryptionPassphraseInvalid") } - )) == "no" - ) { - return; - } - } - if (isCloudantURI(this.editingSettings.couchDB_URI)) { - this.editingSettings = { ...this.editingSettings, ...PREFERRED_SETTING_CLOUDANT }; - } else if (this.editingSettings.remoteType == REMOTE_MINIO) { - this.editingSettings = { ...this.editingSettings, ...PREFERRED_JOURNAL_SYNC }; - } else { - this.editingSettings = { ...this.editingSettings, ...PREFERRED_SETTING_SELF_HOSTED }; - } - if ( - (await this.plugin.confirm.askYesNoDialog( - $msg("obsidianLiveSyncSettingTab.msgFetchConfigFromRemote"), - { defaultOption: "Yes", title: $msg("obsidianLiveSyncSettingTab.titleFetchConfig") } - )) == "yes" - ) { - const trialSetting = { ...this.initialSettings, ...this.editingSettings }; - const newTweaks = await this.plugin.$$checkAndAskUseRemoteConfiguration(trialSetting); - if (newTweaks.result !== false) { - this.editingSettings = { ...this.editingSettings, ...newTweaks.result }; - this.requestUpdate(); - } else { - // Messages should be already shown. - } - } - changeDisplay("30"); - }) - ); - }); - void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.titleSyncSettings"), "🔄", 30, false).then((paneEl) => { - if (this.editingSettings.versionUpFlash != "") { - const c = this.createEl( - paneEl, - "div", - { - text: this.editingSettings.versionUpFlash, - cls: "op-warn sls-setting-hidden", - }, - (el) => { - this.createEl(el, "button", { text: $msg("obsidianLiveSyncSettingTab.btnGotItAndUpdated") }, (e) => { - e.addClass("mod-cta"); - e.addEventListener("click", () => { - fireAndForget(async () => { - this.editingSettings.versionUpFlash = ""; - await this.saveAllDirtySettings(); - c.remove(); - }); - }); - }); - }, - visibleOnly(() => !this.isConfiguredAs("versionUpFlash", "")) + changeDisplay("30"); + }) ); } - - this.createEl(paneEl, "div", { - text: $msg("obsidianLiveSyncSettingTab.msgSelectAndApplyPreset"), - cls: "wizardOnly", - }).addClasses(["op-warn-info"]); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleSynchronizationPreset")).then((paneEl) => { - const options: Record = - this.editingSettings.remoteType == REMOTE_COUCHDB - ? { - NONE: "", - LIVESYNC: $msg("obsidianLiveSyncSettingTab.optionLiveSync"), - PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicWithBatch"), - DISABLE: $msg("obsidianLiveSyncSettingTab.optionDisableAllAutomatic"), - } - : { - NONE: "", - PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicWithBatch"), - DISABLE: $msg("obsidianLiveSyncSettingTab.optionDisableAllAutomatic"), - }; - - new Setting(paneEl) - .autoWireDropDown("preset", { - options: options, - holdValue: true, - }) - .addButton((button) => { - button.setButtonText($msg("obsidianLiveSyncSettingTab.btnApply")); - button.onClick(async () => { - // await this.saveSettings(["preset"]); - await this.saveAllDirtySettings(); - }); - }); - - this.addOnSaved("preset", async (currentPreset) => { - if (currentPreset == "") { - Logger($msg("obsidianLiveSyncSettingTab.logSelectAnyPreset"), LOG_LEVEL_NOTICE); - return; - } - const presetAllDisabled = { - batchSave: false, - liveSync: false, - periodicReplication: false, - syncOnSave: false, - syncOnEditorSave: false, - syncOnStart: false, - syncOnFileOpen: false, - syncAfterMerge: false, - } as Partial; - const presetLiveSync = { - ...presetAllDisabled, - liveSync: true, - } as Partial; - const presetPeriodic = { - ...presetAllDisabled, - batchSave: true, - periodicReplication: true, - syncOnSave: false, - syncOnEditorSave: false, - syncOnStart: true, - syncOnFileOpen: true, - syncAfterMerge: true, - } as Partial; - - if (currentPreset == "LIVESYNC") { - this.editingSettings = { - ...this.editingSettings, - ...presetLiveSync, - }; - Logger($msg("obsidianLiveSyncSettingTab.logConfiguredLiveSync"), LOG_LEVEL_NOTICE); - } else if (currentPreset == "PERIODIC") { - this.editingSettings = { - ...this.editingSettings, - ...presetPeriodic, - }; - Logger($msg("obsidianLiveSyncSettingTab.logConfiguredPeriodic"), LOG_LEVEL_NOTICE); - } else { - Logger($msg("obsidianLiveSyncSettingTab.logConfiguredDisabled"), LOG_LEVEL_NOTICE); - this.editingSettings = { - ...this.editingSettings, - ...presetAllDisabled, - }; - } - - if (this.inWizard) { - this.closeSetting(); - this.inWizard = false; - if (!this.editingSettings.isConfigured) { - this.editingSettings.isConfigured = true; - await this.saveAllDirtySettings(); - await this.plugin.$$realizeSettingSyncMode(); - await rebuildDB("localOnly"); - // this.resetEditingSettings(); - if ( - (await this.plugin.confirm.askYesNoDialog( - $msg("obsidianLiveSyncSettingTab.msgGenerateSetupURI"), - { defaultOption: "Yes", title: $msg("obsidianLiveSyncSettingTab.titleCongratulations") } - )) == "yes" - ) { - eventHub.emitEvent(EVENT_REQUEST_COPY_SETUP_URI); - } - } else { - if (isNeedRebuildLocal() || isNeedRebuildRemote()) { - await confirmRebuild(); - } else { - await this.saveAllDirtySettings(); - await this.plugin.$$realizeSettingSyncMode(); - this.plugin.$$askReload(); - } - } - } else { - await this.saveAllDirtySettings(); - await this.plugin.$$realizeSettingSyncMode(); - } - }); - }); - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleSynchronizationMethod")).then((paneEl) => { - paneEl.addClass("wizardHidden"); - - // const onlyOnLiveSync = visibleOnly(() => this.isConfiguredAs("syncMode", "LIVESYNC")); - const onlyOnNonLiveSync = visibleOnly(() => !this.isConfiguredAs("syncMode", "LIVESYNC")); - const onlyOnPeriodic = visibleOnly(() => this.isConfiguredAs("syncMode", "PERIODIC")); - - const optionsSyncMode = - this.editingSettings.remoteType == REMOTE_COUCHDB - ? { - ONEVENTS: $msg("obsidianLiveSyncSettingTab.optionOnEvents"), - PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicAndEvents"), - LIVESYNC: $msg("obsidianLiveSyncSettingTab.optionLiveSync"), - } - : { - ONEVENTS: $msg("obsidianLiveSyncSettingTab.optionOnEvents"), - PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicAndEvents"), - }; - - new Setting(paneEl) - .autoWireDropDown("syncMode", { - //@ts-ignore - options: optionsSyncMode, - }) - .setClass("wizardHidden"); - this.addOnSaved("syncMode", async (value) => { - this.editingSettings.liveSync = false; - this.editingSettings.periodicReplication = false; - if (value == "LIVESYNC") { - this.editingSettings.liveSync = true; - } else if (value == "PERIODIC") { - this.editingSettings.periodicReplication = true; - } - await this.saveSettings(["liveSync", "periodicReplication"]); - - await this.plugin.$$realizeSettingSyncMode(); - }); - - new Setting(paneEl) - .autoWireNumeric("periodicReplicationInterval", { - clampMax: 5000, - onUpdate: onlyOnPeriodic, - }) - .setClass("wizardHidden"); - - new Setting(paneEl) - .setClass("wizardHidden") - .autoWireToggle("syncOnSave", { onUpdate: onlyOnNonLiveSync }); - new Setting(paneEl) - .setClass("wizardHidden") - .autoWireToggle("syncOnEditorSave", { onUpdate: onlyOnNonLiveSync }); - new Setting(paneEl) - .setClass("wizardHidden") - .autoWireToggle("syncOnFileOpen", { onUpdate: onlyOnNonLiveSync }); - new Setting(paneEl) - .setClass("wizardHidden") - .autoWireToggle("syncOnStart", { onUpdate: onlyOnNonLiveSync }); - new Setting(paneEl) - .setClass("wizardHidden") - .autoWireToggle("syncAfterMerge", { onUpdate: onlyOnNonLiveSync }); - }); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleUpdateThinning")).then((paneEl) => { - paneEl.addClass("wizardHidden"); - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("batchSave"); - new Setting(paneEl).setClass("wizardHidden").autoWireNumeric("batchSaveMinimumDelay", { - acceptZero: true, - onUpdate: visibleOnly(() => this.isConfiguredAs("batchSave", true)), - }); - new Setting(paneEl).setClass("wizardHidden").autoWireNumeric("batchSaveMaximumDelay", { - acceptZero: true, - onUpdate: visibleOnly(() => this.isConfiguredAs("batchSave", true)), - }); - }); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleDeletionPropagation"), undefined, undefined, LEVEL_ADVANCED).then((paneEl) => { - paneEl.addClass("wizardHidden"); - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("trashInsteadDelete"); - - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("doNotDeleteFolder"); - }); - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleConflictResolution"), undefined, undefined, LEVEL_ADVANCED).then((paneEl) => { - paneEl.addClass("wizardHidden"); - - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("resolveConflictsByNewerFile"); - - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("checkConflictOnlyOnOpen"); - - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("showMergeDialogOnlyOnActive"); - }); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleSyncSettingsViaMarkdown"), undefined, undefined, LEVEL_ADVANCED).then((paneEl) => { - paneEl.addClass("wizardHidden"); - - new Setting(paneEl) - .autoWireText("settingSyncFile", { holdValue: true }) - .addApplyButton(["settingSyncFile"]); - - new Setting(paneEl).autoWireToggle("writeCredentialsForSettingSync"); - - new Setting(paneEl).autoWireToggle("notifyAllSettingSyncFile"); - }); - - void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleHiddenFiles"), undefined, undefined, LEVEL_ADVANCED).then((paneEl) => { - paneEl.addClass("wizardHidden"); - - const LABEL_ENABLED = $msg("obsidianLiveSyncSettingTab.labelEnabled"); - const LABEL_DISABLED = $msg("obsidianLiveSyncSettingTab.labelDisabled"); - - const hiddenFileSyncSetting = new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.nameHiddenFileSynchronization")) - .setClass("wizardHidden"); - const hiddenFileSyncSettingEl = hiddenFileSyncSetting.settingEl; - const hiddenFileSyncSettingDiv = hiddenFileSyncSettingEl.createDiv(""); - hiddenFileSyncSettingDiv.innerText = this.editingSettings.syncInternalFiles - ? LABEL_ENABLED - : LABEL_DISABLED; - if (this.editingSettings.syncInternalFiles) { - new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.nameDisableHiddenFileSync")) - .setClass("wizardHidden") - .addButton((button) => { - button.setButtonText($msg("obsidianLiveSyncSettingTab.btnDisable")).onClick(async () => { - this.editingSettings.syncInternalFiles = false; - await this.saveAllDirtySettings(); - this.display(); - }); - }); - } else { - new Setting(paneEl) - .setName($msg("obsidianLiveSyncSettingTab.nameEnableHiddenFileSync")) - .setClass("wizardHidden") - .addButton((button) => { - button.setButtonText("Merge").onClick(async () => { - this.closeSetting(); - // this.resetEditingSettings(); - await this.plugin.$anyConfigureOptionalSyncFeature("MERGE"); - }); - }) - .addButton((button) => { - button.setButtonText("Fetch").onClick(async () => { - this.closeSetting(); - // this.resetEditingSettings(); - await this.plugin.$anyConfigureOptionalSyncFeature("FETCH"); - }); - }) - .addButton((button) => { - button.setButtonText("Overwrite").onClick(async () => { - this.closeSetting(); - // this.resetEditingSettings(); - await this.plugin.$anyConfigureOptionalSyncFeature("OVERWRITE"); - }); - }); + ); + void addPane(containerEl, $msg("obsidianLiveSyncSettingTab.titleSyncSettings"), "🔄", 30, false).then( + (paneEl) => { + if (this.editingSettings.versionUpFlash != "") { + const c = this.createEl( + paneEl, + "div", + { + text: this.editingSettings.versionUpFlash, + cls: "op-warn sls-setting-hidden", + }, + (el) => { + this.createEl( + el, + "button", + { text: $msg("obsidianLiveSyncSettingTab.btnGotItAndUpdated") }, + (e) => { + e.addClass("mod-cta"); + e.addEventListener("click", () => { + fireAndForget(async () => { + this.editingSettings.versionUpFlash = ""; + await this.saveAllDirtySettings(); + c.remove(); + }); + }); + } + ); + }, + visibleOnly(() => !this.isConfiguredAs("versionUpFlash", "")) + ); } - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("suppressNotifyHiddenFilesChange", {}); - new Setting(paneEl).setClass("wizardHidden").autoWireToggle("syncInternalFilesBeforeReplication", { - onUpdate: visibleOnly(() => this.isConfiguredAs("watchInternalFileChanges", true)), + this.createEl(paneEl, "div", { + text: $msg("obsidianLiveSyncSettingTab.msgSelectAndApplyPreset"), + cls: "wizardOnly", + }).addClasses(["op-warn-info"]); + + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleSynchronizationPreset")).then((paneEl) => { + const options: Record = + this.editingSettings.remoteType == REMOTE_COUCHDB + ? { + NONE: "", + LIVESYNC: $msg("obsidianLiveSyncSettingTab.optionLiveSync"), + PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicWithBatch"), + DISABLE: $msg("obsidianLiveSyncSettingTab.optionDisableAllAutomatic"), + } + : { + NONE: "", + PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicWithBatch"), + DISABLE: $msg("obsidianLiveSyncSettingTab.optionDisableAllAutomatic"), + }; + + new Setting(paneEl) + .autoWireDropDown("preset", { + options: options, + holdValue: true, + }) + .addButton((button) => { + button.setButtonText($msg("obsidianLiveSyncSettingTab.btnApply")); + button.onClick(async () => { + // await this.saveSettings(["preset"]); + await this.saveAllDirtySettings(); + }); + }); + + this.addOnSaved("preset", async (currentPreset) => { + if (currentPreset == "") { + Logger($msg("obsidianLiveSyncSettingTab.logSelectAnyPreset"), LOG_LEVEL_NOTICE); + return; + } + const presetAllDisabled = { + batchSave: false, + liveSync: false, + periodicReplication: false, + syncOnSave: false, + syncOnEditorSave: false, + syncOnStart: false, + syncOnFileOpen: false, + syncAfterMerge: false, + } as Partial; + const presetLiveSync = { + ...presetAllDisabled, + liveSync: true, + } as Partial; + const presetPeriodic = { + ...presetAllDisabled, + batchSave: true, + periodicReplication: true, + syncOnSave: false, + syncOnEditorSave: false, + syncOnStart: true, + syncOnFileOpen: true, + syncAfterMerge: true, + } as Partial; + + if (currentPreset == "LIVESYNC") { + this.editingSettings = { + ...this.editingSettings, + ...presetLiveSync, + }; + Logger($msg("obsidianLiveSyncSettingTab.logConfiguredLiveSync"), LOG_LEVEL_NOTICE); + } else if (currentPreset == "PERIODIC") { + this.editingSettings = { + ...this.editingSettings, + ...presetPeriodic, + }; + Logger($msg("obsidianLiveSyncSettingTab.logConfiguredPeriodic"), LOG_LEVEL_NOTICE); + } else { + Logger($msg("obsidianLiveSyncSettingTab.logConfiguredDisabled"), LOG_LEVEL_NOTICE); + this.editingSettings = { + ...this.editingSettings, + ...presetAllDisabled, + }; + } + + if (this.inWizard) { + this.closeSetting(); + this.inWizard = false; + if (!this.editingSettings.isConfigured) { + this.editingSettings.isConfigured = true; + await this.saveAllDirtySettings(); + await this.plugin.$$realizeSettingSyncMode(); + await rebuildDB("localOnly"); + // this.resetEditingSettings(); + if ( + (await this.plugin.confirm.askYesNoDialog( + $msg("obsidianLiveSyncSettingTab.msgGenerateSetupURI"), + { + defaultOption: "Yes", + title: $msg("obsidianLiveSyncSettingTab.titleCongratulations"), + } + )) == "yes" + ) { + eventHub.emitEvent(EVENT_REQUEST_COPY_SETUP_URI); + } + } else { + if (isNeedRebuildLocal() || isNeedRebuildRemote()) { + await confirmRebuild(); + } else { + await this.saveAllDirtySettings(); + await this.plugin.$$realizeSettingSyncMode(); + this.plugin.$$askReload(); + } + } + } else { + await this.saveAllDirtySettings(); + await this.plugin.$$realizeSettingSyncMode(); + } + }); + }); + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleSynchronizationMethod")).then((paneEl) => { + paneEl.addClass("wizardHidden"); + + // const onlyOnLiveSync = visibleOnly(() => this.isConfiguredAs("syncMode", "LIVESYNC")); + const onlyOnNonLiveSync = visibleOnly(() => !this.isConfiguredAs("syncMode", "LIVESYNC")); + const onlyOnPeriodic = visibleOnly(() => this.isConfiguredAs("syncMode", "PERIODIC")); + + const optionsSyncMode = + this.editingSettings.remoteType == REMOTE_COUCHDB + ? { + ONEVENTS: $msg("obsidianLiveSyncSettingTab.optionOnEvents"), + PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicAndEvents"), + LIVESYNC: $msg("obsidianLiveSyncSettingTab.optionLiveSync"), + } + : { + ONEVENTS: $msg("obsidianLiveSyncSettingTab.optionOnEvents"), + PERIODIC: $msg("obsidianLiveSyncSettingTab.optionPeriodicAndEvents"), + }; + + new Setting(paneEl) + .autoWireDropDown("syncMode", { + //@ts-ignore + options: optionsSyncMode, + }) + .setClass("wizardHidden"); + this.addOnSaved("syncMode", async (value) => { + this.editingSettings.liveSync = false; + this.editingSettings.periodicReplication = false; + if (value == "LIVESYNC") { + this.editingSettings.liveSync = true; + } else if (value == "PERIODIC") { + this.editingSettings.periodicReplication = true; + } + await this.saveSettings(["liveSync", "periodicReplication"]); + + await this.plugin.$$realizeSettingSyncMode(); + }); + + new Setting(paneEl) + .autoWireNumeric("periodicReplicationInterval", { + clampMax: 5000, + onUpdate: onlyOnPeriodic, + }) + .setClass("wizardHidden"); + + new Setting(paneEl) + .setClass("wizardHidden") + .autoWireToggle("syncOnSave", { onUpdate: onlyOnNonLiveSync }); + new Setting(paneEl) + .setClass("wizardHidden") + .autoWireToggle("syncOnEditorSave", { onUpdate: onlyOnNonLiveSync }); + new Setting(paneEl) + .setClass("wizardHidden") + .autoWireToggle("syncOnFileOpen", { onUpdate: onlyOnNonLiveSync }); + new Setting(paneEl) + .setClass("wizardHidden") + .autoWireToggle("syncOnStart", { onUpdate: onlyOnNonLiveSync }); + new Setting(paneEl) + .setClass("wizardHidden") + .autoWireToggle("syncAfterMerge", { onUpdate: onlyOnNonLiveSync }); }); - new Setting(paneEl).setClass("wizardHidden").autoWireNumeric("syncInternalFilesInterval", { - clampMin: 10, - acceptZero: true, + void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleUpdateThinning")).then((paneEl) => { + paneEl.addClass("wizardHidden"); + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("batchSave"); + new Setting(paneEl).setClass("wizardHidden").autoWireNumeric("batchSaveMinimumDelay", { + acceptZero: true, + onUpdate: visibleOnly(() => this.isConfiguredAs("batchSave", true)), + }); + new Setting(paneEl).setClass("wizardHidden").autoWireNumeric("batchSaveMaximumDelay", { + acceptZero: true, + onUpdate: visibleOnly(() => this.isConfiguredAs("batchSave", true)), + }); }); - }); - }); + + void addPanel( + paneEl, + $msg("obsidianLiveSyncSettingTab.titleDeletionPropagation"), + undefined, + undefined, + LEVEL_ADVANCED + ).then((paneEl) => { + paneEl.addClass("wizardHidden"); + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("trashInsteadDelete"); + + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("doNotDeleteFolder"); + }); + void addPanel( + paneEl, + $msg("obsidianLiveSyncSettingTab.titleConflictResolution"), + undefined, + undefined, + LEVEL_ADVANCED + ).then((paneEl) => { + paneEl.addClass("wizardHidden"); + + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("resolveConflictsByNewerFile"); + + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("checkConflictOnlyOnOpen"); + + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("showMergeDialogOnlyOnActive"); + }); + + void addPanel( + paneEl, + $msg("obsidianLiveSyncSettingTab.titleSyncSettingsViaMarkdown"), + undefined, + undefined, + LEVEL_ADVANCED + ).then((paneEl) => { + paneEl.addClass("wizardHidden"); + + new Setting(paneEl) + .autoWireText("settingSyncFile", { holdValue: true }) + .addApplyButton(["settingSyncFile"]); + + new Setting(paneEl).autoWireToggle("writeCredentialsForSettingSync"); + + new Setting(paneEl).autoWireToggle("notifyAllSettingSyncFile"); + }); + + void addPanel( + paneEl, + $msg("obsidianLiveSyncSettingTab.titleHiddenFiles"), + undefined, + undefined, + LEVEL_ADVANCED + ).then((paneEl) => { + paneEl.addClass("wizardHidden"); + + const LABEL_ENABLED = $msg("obsidianLiveSyncSettingTab.labelEnabled"); + const LABEL_DISABLED = $msg("obsidianLiveSyncSettingTab.labelDisabled"); + + const hiddenFileSyncSetting = new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameHiddenFileSynchronization")) + .setClass("wizardHidden"); + const hiddenFileSyncSettingEl = hiddenFileSyncSetting.settingEl; + const hiddenFileSyncSettingDiv = hiddenFileSyncSettingEl.createDiv(""); + hiddenFileSyncSettingDiv.innerText = this.editingSettings.syncInternalFiles + ? LABEL_ENABLED + : LABEL_DISABLED; + if (this.editingSettings.syncInternalFiles) { + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameDisableHiddenFileSync")) + .setClass("wizardHidden") + .addButton((button) => { + button + .setButtonText($msg("obsidianLiveSyncSettingTab.btnDisable")) + .onClick(async () => { + this.editingSettings.syncInternalFiles = false; + await this.saveAllDirtySettings(); + this.display(); + }); + }); + } else { + new Setting(paneEl) + .setName($msg("obsidianLiveSyncSettingTab.nameEnableHiddenFileSync")) + .setClass("wizardHidden") + .addButton((button) => { + button.setButtonText("Merge").onClick(async () => { + this.closeSetting(); + // this.resetEditingSettings(); + await this.plugin.$anyConfigureOptionalSyncFeature("MERGE"); + }); + }) + .addButton((button) => { + button.setButtonText("Fetch").onClick(async () => { + this.closeSetting(); + // this.resetEditingSettings(); + await this.plugin.$anyConfigureOptionalSyncFeature("FETCH"); + }); + }) + .addButton((button) => { + button.setButtonText("Overwrite").onClick(async () => { + this.closeSetting(); + // this.resetEditingSettings(); + await this.plugin.$anyConfigureOptionalSyncFeature("OVERWRITE"); + }); + }); + } + + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("suppressNotifyHiddenFilesChange", {}); + new Setting(paneEl).setClass("wizardHidden").autoWireToggle("syncInternalFilesBeforeReplication", { + onUpdate: visibleOnly(() => this.isConfiguredAs("watchInternalFileChanges", true)), + }); + + new Setting(paneEl).setClass("wizardHidden").autoWireNumeric("syncInternalFilesInterval", { + clampMin: 10, + acceptZero: true, + }); + }); + } + ); void addPane(containerEl, "Selector", "🚦", 33, false, LEVEL_ADVANCED).then((paneEl) => { void addPanel(paneEl, "Normal Files").then((paneEl) => { paneEl.addClass("wizardHidden"); diff --git a/src/modules/main/ModuleLiveSyncMain.ts b/src/modules/main/ModuleLiveSyncMain.ts index 43609a6..5940979 100644 --- a/src/modules/main/ModuleLiveSyncMain.ts +++ b/src/modules/main/ModuleLiveSyncMain.ts @@ -24,7 +24,7 @@ export class ModuleLiveSyncMain extends AbstractModule implements ICoreModule { const ANSWER_RESUME = $msg("moduleLiveSyncMain.optionResumeAndRestart"); const message = $msg("moduleLiveSyncMain.msgScramEnabled", { fileWatchingStatus: this.settings.suspendFileWatching ? "suspended" : "active", - parseReplicationStatus: this.settings.suspendParseReplicationResult ? "suspended" : "active" + parseReplicationStatus: this.settings.suspendParseReplicationResult ? "suspended" : "active", }); if ( (await this.core.confirm.askSelectStringDialogue(message, [ANSWER_KEEP, ANSWER_RESUME], {