Wizard behaviour has been improved

This commit is contained in:
vorotamoroz
2022-09-11 10:37:46 +09:00
parent d04be6813b
commit 5e7b44d35a

View File

@@ -131,10 +131,13 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
.addButton((text) => { .addButton((text) => {
text.setButtonText("Next").onClick(async () => { text.setButtonText("Next").onClick(async () => {
if (JSON.stringify(this.plugin.settings) != JSON.stringify(DEFAULT_SETTINGS)) { if (JSON.stringify(this.plugin.settings) != JSON.stringify(DEFAULT_SETTINGS)) {
this.plugin.localDatabase.closeReplication();
this.plugin.settings = { ...DEFAULT_SETTINGS }; this.plugin.settings = { ...DEFAULT_SETTINGS };
this.plugin.saveSettings(); this.plugin.saveSettings();
Logger("Configuration has been flushed, please open it again", LOG_LEVEL.NOTICE) Logger("Configuration has been flushed, please open it again", LOG_LEVEL.NOTICE)
this.hide(); // @ts-ignore
this.plugin.app.setting.close()
} else { } else {
containerEl.addClass("isWizard"); containerEl.addClass("isWizard");
applyDisplayEnabled(); applyDisplayEnabled();
@@ -147,12 +150,12 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
.setName("Do not discard the existing configuration and set up again") .setName("Do not discard the existing configuration and set up again")
.addButton((text) => { .addButton((text) => {
text.setButtonText("Next").onClick(async () => { text.setButtonText("Next").onClick(async () => {
await this.plugin.resetLocalDatabase();
this.plugin.settings.liveSync = false; this.plugin.settings.liveSync = false;
this.plugin.settings.periodicReplication = false; this.plugin.settings.periodicReplication = false;
this.plugin.settings.syncOnSave = false; this.plugin.settings.syncOnSave = false;
this.plugin.settings.syncOnStart = false; this.plugin.settings.syncOnStart = false;
this.plugin.settings.syncOnFileOpen = false; this.plugin.settings.syncOnFileOpen = false;
this.plugin.localDatabase.closeReplication();
await this.plugin.saveSettings(); await this.plugin.saveSettings();
containerEl.addClass("isWizard"); containerEl.addClass("isWizard");
applyDisplayEnabled(); applyDisplayEnabled();
@@ -683,6 +686,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
new Setting(containerLocalDatabaseEl) new Setting(containerLocalDatabaseEl)
.setName("Batch database update") .setName("Batch database update")
.setDesc("Delay all changes, save once before replication or opening another file.") .setDesc("Delay all changes, save once before replication or opening another file.")
.setClass("wizardHidden")
.addToggle((toggle) => .addToggle((toggle) =>
toggle.setValue(this.plugin.settings.batchSave).onChange(async (value) => { toggle.setValue(this.plugin.settings.batchSave).onChange(async (value) => {
if (value && this.plugin.settings.liveSync) { if (value && this.plugin.settings.liveSync) {
@@ -1193,11 +1197,14 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
this.plugin.saveSettings(); this.plugin.saveSettings();
await this.plugin.realizeSettingSyncMode(); await this.plugin.realizeSettingSyncMode();
if (inWizard) { if (inWizard) {
this.hide(); // @ts-ignore
this.plugin.app.setting.close()
await this.plugin.resetLocalDatabase(); await this.plugin.resetLocalDatabase();
await this.plugin.initializeDatabase(true) await this.plugin.initializeDatabase(true)
await this.plugin.replicate(true); await this.plugin.replicate(true);
Logger("All done! Please set up subsequent devices with 'Copy setup URI' and 'Open setup URI'.", LOG_LEVEL.NOTICE) Logger("All done! Please set up subsequent devices with 'Copy setup URI' and 'Open setup URI'.", LOG_LEVEL.NOTICE);
// @ts-ignore
this.plugin.app.commands.executeCommandById("obsidian-livesync:livesync-copysetupuri")
} }