mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-04-05 00:25:17 +00:00
disenchanting and dispelling from the nightmarish implicit something
Indeed, even though if this changeset is mostly another nightmare. It might be in beta for a while.
This commit is contained in:
@@ -86,6 +86,9 @@ export function createStub(name: string, key: string, value: string, panel: stri
|
||||
|
||||
export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
plugin: ObsidianLiveSyncPlugin;
|
||||
get services() {
|
||||
return this.plugin.services;
|
||||
}
|
||||
selectedScreen = "";
|
||||
|
||||
_editingSettings?: AllSettings;
|
||||
@@ -139,8 +142,8 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
return await Promise.resolve();
|
||||
}
|
||||
if (key == "deviceAndVaultName") {
|
||||
this.plugin.$$setDeviceAndVaultName(this.editingSettings?.[key] ?? "");
|
||||
this.plugin.$$saveDeviceAndVaultName();
|
||||
this.services.setting.setDeviceAndVaultName(this.editingSettings?.[key] ?? "");
|
||||
this.services.setting.saveDeviceAndVaultName();
|
||||
return await Promise.resolve();
|
||||
}
|
||||
}
|
||||
@@ -210,7 +213,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
const ret = { ...OnDialogSettingsDefault };
|
||||
ret.configPassphrase = localStorage.getItem("ls-setting-passphrase") || "";
|
||||
ret.preset = "";
|
||||
ret.deviceAndVaultName = this.plugin.$$getDeviceAndVaultName();
|
||||
ret.deviceAndVaultName = this.services.setting.getDeviceAndVaultName();
|
||||
return ret;
|
||||
}
|
||||
computeAllLocalSettings(): Partial<OnDialogSettings> {
|
||||
@@ -295,7 +298,11 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
|
||||
async testConnection(settingOverride: Partial<ObsidianLiveSyncSettings> = {}): Promise<void> {
|
||||
const trialSetting = { ...this.editingSettings, ...settingOverride };
|
||||
const replicator = await this.plugin.$anyNewReplicator(trialSetting);
|
||||
const replicator = await this.services.replicator.getNewReplicator(trialSetting);
|
||||
if (!replicator) {
|
||||
Logger("No replicator available for the current settings.", LOG_LEVEL_NOTICE);
|
||||
return;
|
||||
}
|
||||
await replicator.tryConnectRemote(trialSetting);
|
||||
const status = await replicator.getRemoteStatus(trialSetting);
|
||||
if (status) {
|
||||
@@ -546,10 +553,14 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
const settingForCheck: RemoteDBSettings = {
|
||||
...this.editingSettings,
|
||||
};
|
||||
const replicator = this.plugin.$anyNewReplicator(settingForCheck);
|
||||
const replicator = this.services.replicator.getNewReplicator(settingForCheck);
|
||||
if (!(replicator instanceof LiveSyncCouchDBReplicator)) return true;
|
||||
|
||||
const db = await replicator.connectRemoteCouchDBWithSetting(settingForCheck, this.plugin.$$isMobile(), true);
|
||||
const db = await replicator.connectRemoteCouchDBWithSetting(
|
||||
settingForCheck,
|
||||
this.services.API.isMobile(),
|
||||
true
|
||||
);
|
||||
if (typeof db === "string") {
|
||||
Logger($msg("obsidianLiveSyncSettingTab.logCheckPassphraseFailed", { db }), LOG_LEVEL_NOTICE);
|
||||
return false;
|
||||
@@ -588,8 +599,8 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
this.editingSettings.passphrase = "";
|
||||
}
|
||||
this.applyAllSettings();
|
||||
await this.plugin.$allSuspendAllSync();
|
||||
await this.plugin.$allSuspendExtraSync();
|
||||
await this.services.setting.suspendAllSync();
|
||||
await this.services.setting.suspendExtraSync();
|
||||
this.reloadAllSettings();
|
||||
this.editingSettings.isConfigured = true;
|
||||
Logger($msg("obsidianLiveSyncSettingTab.logRebuildNote"), LOG_LEVEL_NOTICE);
|
||||
@@ -638,12 +649,12 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
await this.applyAllSettings();
|
||||
if (result == OPTION_FETCH) {
|
||||
await this.plugin.storageAccess.writeFileAuto(FLAGMD_REDFLAG3_HR, "");
|
||||
this.plugin.$$scheduleAppReload();
|
||||
this.services.appLifecycle.scheduleRestart();
|
||||
this.closeSetting();
|
||||
// await rebuildDB("localOnly");
|
||||
} else if (result == OPTION_REBUILD_BOTH) {
|
||||
await this.plugin.storageAccess.writeFileAuto(FLAGMD_REDFLAG2_HR, "");
|
||||
this.plugin.$$scheduleAppReload();
|
||||
this.services.appLifecycle.scheduleRestart();
|
||||
this.closeSetting();
|
||||
} else if (result == OPTION_ONLY_SETTING) {
|
||||
await this.plugin.saveSettings();
|
||||
|
||||
@@ -156,7 +156,7 @@ export function paneHatch(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElement,
|
||||
}
|
||||
const obsidianInfo = {
|
||||
navigator: navigator.userAgent,
|
||||
fileSystem: this.plugin.$$isStorageInsensitive() ? "insensitive" : "sensitive",
|
||||
fileSystem: this.plugin.services.vault.isStorageInsensitive() ? "insensitive" : "sensitive",
|
||||
};
|
||||
const msgConfig = `# ---- Obsidian info ----
|
||||
${stringifyYaml(obsidianInfo)}
|
||||
@@ -182,10 +182,10 @@ ${stringifyYaml({
|
||||
|
||||
void addPanel(paneEl, "Scram Switches").then((paneEl) => {
|
||||
new Setting(paneEl).autoWireToggle("suspendFileWatching");
|
||||
this.addOnSaved("suspendFileWatching", () => this.plugin.$$askReload());
|
||||
this.addOnSaved("suspendFileWatching", () => this.services.appLifecycle.askRestart());
|
||||
|
||||
new Setting(paneEl).autoWireToggle("suspendParseReplicationResult");
|
||||
this.addOnSaved("suspendParseReplicationResult", () => this.plugin.$$askReload());
|
||||
this.addOnSaved("suspendParseReplicationResult", () => this.services.appLifecycle.askRestart());
|
||||
});
|
||||
|
||||
void addPanel(paneEl, "Recovery and Repair").then((paneEl) => {
|
||||
@@ -384,15 +384,16 @@ ${stringifyYaml({
|
||||
? await this.plugin.storageAccess.statHidden(path)
|
||||
: false;
|
||||
const fileOnStorage = stat != null ? stat : false;
|
||||
if (!(await this.plugin.$$isTargetFile(path))) return incProc();
|
||||
if (!(await this.services.vault.isTargetFile(path))) return incProc();
|
||||
const releaser = await semaphore.acquire(1);
|
||||
if (fileOnStorage && this.plugin.$$isFileSizeExceeded(fileOnStorage.size))
|
||||
if (fileOnStorage && this.services.vault.isFileSizeTooLarge(fileOnStorage.size))
|
||||
return incProc();
|
||||
try {
|
||||
const isHiddenFile = path.startsWith(".");
|
||||
const dbPath = isHiddenFile ? addPrefix(path, ICHeader) : path;
|
||||
const fileOnDB = await this.plugin.localDatabase.getDBEntry(dbPath);
|
||||
if (fileOnDB && this.plugin.$$isFileSizeExceeded(fileOnDB.size)) return incProc();
|
||||
if (fileOnDB && this.services.vault.isFileSizeTooLarge(fileOnDB.size))
|
||||
return incProc();
|
||||
|
||||
if (!fileOnDB && fileOnStorage) {
|
||||
Logger(`Compare: Not found on the local database: ${path}`, LOG_LEVEL_NOTICE);
|
||||
@@ -436,7 +437,7 @@ ${stringifyYaml({
|
||||
.onClick(async () => {
|
||||
for await (const docName of this.plugin.localDatabase.findAllDocNames()) {
|
||||
if (!docName.startsWith("f:")) {
|
||||
const idEncoded = await this.plugin.$$path2id(docName as FilePathWithPrefix);
|
||||
const idEncoded = await this.services.path.path2id(docName as FilePathWithPrefix);
|
||||
const doc = await this.plugin.localDatabase.getRaw(docName as DocumentID);
|
||||
if (!doc) continue;
|
||||
if (doc.type != "newnote" && doc.type != "plain") {
|
||||
@@ -477,7 +478,7 @@ ${stringifyYaml({
|
||||
if ((await this.plugin.localDatabase.putRaw(doc)).ok) {
|
||||
Logger(`Old ${docName} has been deleted`, LOG_LEVEL_NOTICE);
|
||||
}
|
||||
await this.plugin.$$queueConflictCheckIfOpen(docName as FilePathWithPrefix);
|
||||
await this.services.conflict.queueCheckForIfOpen(docName as FilePathWithPrefix);
|
||||
} else {
|
||||
Logger(`Converting ${docName} Failed!`, LOG_LEVEL_NOTICE);
|
||||
Logger(ret, LOG_LEVEL_VERBOSE);
|
||||
@@ -512,7 +513,7 @@ ${stringifyYaml({
|
||||
.onClick(async () => {
|
||||
this.editingSettings.isConfigured = false;
|
||||
await this.saveAllDirtySettings();
|
||||
this.plugin.$$askReload();
|
||||
this.services.appLifecycle.askRestart();
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export function paneMaintenance(
|
||||
(e) => {
|
||||
e.addEventListener("click", () => {
|
||||
fireAndForget(async () => {
|
||||
await this.plugin.$$markRemoteResolved();
|
||||
await this.services.remote.markResolved();
|
||||
this.display();
|
||||
});
|
||||
});
|
||||
@@ -59,7 +59,7 @@ export function paneMaintenance(
|
||||
(e) => {
|
||||
e.addEventListener("click", () => {
|
||||
fireAndForget(async () => {
|
||||
await this.plugin.$$markRemoteUnlocked();
|
||||
await this.services.remote.markUnlocked();
|
||||
this.display();
|
||||
});
|
||||
});
|
||||
@@ -78,7 +78,7 @@ export function paneMaintenance(
|
||||
.setDisabled(false)
|
||||
.setWarning()
|
||||
.onClick(async () => {
|
||||
await this.plugin.$$markRemoteLocked();
|
||||
await this.services.remote.markLocked();
|
||||
})
|
||||
)
|
||||
.addOnUpdate(this.onlyOnCouchDBOrMinIO);
|
||||
@@ -93,7 +93,7 @@ export function paneMaintenance(
|
||||
.setWarning()
|
||||
.onClick(async () => {
|
||||
await this.plugin.storageAccess.writeFileAuto(FLAGMD_REDFLAG, "");
|
||||
this.plugin.$$performRestart();
|
||||
this.services.appLifecycle.performRestart();
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -255,7 +255,7 @@ export function paneMaintenance(
|
||||
.setDisabled(false)
|
||||
.onClick(async () => {
|
||||
await this.plugin.storageAccess.writeFileAuto(FLAGMD_REDFLAG3_HR, "");
|
||||
this.plugin.$$performRestart();
|
||||
this.services.appLifecycle.performRestart();
|
||||
})
|
||||
)
|
||||
.addButton((button) =>
|
||||
@@ -294,7 +294,7 @@ export function paneMaintenance(
|
||||
.setDisabled(false)
|
||||
.onClick(async () => {
|
||||
await this.plugin.storageAccess.writeFileAuto(FLAGMD_REDFLAG2_HR, "");
|
||||
this.plugin.$$performRestart();
|
||||
this.services.appLifecycle.performRestart();
|
||||
})
|
||||
)
|
||||
.addButton((button) =>
|
||||
@@ -405,8 +405,8 @@ export function paneMaintenance(
|
||||
.setWarning()
|
||||
.setDisabled(false)
|
||||
.onClick(async () => {
|
||||
await this.plugin.$$resetLocalDatabase();
|
||||
await this.plugin.$$initializeDatabase();
|
||||
await this.services.database.resetDatabase();
|
||||
await this.services.databaseEvents.initialiseDatabase();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ export function panePatches(this: ObsidianLiveSyncSettingTab, paneEl: HTMLElemen
|
||||
|
||||
this.addOnSaved("additionalSuffixOfDatabaseName", async (key) => {
|
||||
Logger("Suffix has been changed. Reopening database...", LOG_LEVEL_NOTICE);
|
||||
await this.plugin.$$initializeDatabase();
|
||||
await this.services.databaseEvents.initialiseDatabase();
|
||||
});
|
||||
|
||||
new Setting(paneEl).autoWireDropDown("hashAlg", {
|
||||
|
||||
@@ -403,7 +403,7 @@ The pane also can be launched by \`P2P Replicator\` command from the Command Pal
|
||||
|
||||
void addPanel(paneEl, $msg("obsidianLiveSyncSettingTab.titleCouchDB"), undefined, this.onlyOnCouchDB).then(
|
||||
(paneEl) => {
|
||||
if (this.plugin.$$isMobile()) {
|
||||
if (this.services.API.isMobile()) {
|
||||
this.createEl(
|
||||
paneEl,
|
||||
"div",
|
||||
@@ -630,7 +630,8 @@ The pane also can be launched by \`P2P Replicator\` command from the Command Pal
|
||||
.setDisabled(false)
|
||||
.onClick(async () => {
|
||||
const trialSetting = { ...this.initialSettings, ...this.editingSettings };
|
||||
const newTweaks = await this.plugin.$$checkAndAskUseRemoteConfiguration(trialSetting);
|
||||
const newTweaks =
|
||||
await this.services.tweakValue.checkAndAskUseRemoteConfiguration(trialSetting);
|
||||
if (newTweaks.result !== false) {
|
||||
if (this.inWizard) {
|
||||
this.editingSettings = { ...this.editingSettings, ...newTweaks.result };
|
||||
@@ -648,15 +649,15 @@ The pane also can be launched by \`P2P Replicator\` command from the Command Pal
|
||||
}
|
||||
)) == "no"
|
||||
) {
|
||||
await this.plugin.$$saveSettingData();
|
||||
await this.services.setting.saveSettingData();
|
||||
return;
|
||||
}
|
||||
await this.plugin.$$saveSettingData();
|
||||
await this.services.setting.saveSettingData();
|
||||
await this.plugin.rebuilder.scheduleFetch();
|
||||
await this.plugin.$$scheduleAppReload();
|
||||
this.services.appLifecycle.scheduleRestart();
|
||||
return;
|
||||
} else {
|
||||
await this.plugin.$$saveSettingData();
|
||||
await this.services.setting.saveSettingData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -727,7 +728,7 @@ The pane also can be launched by \`P2P Replicator\` command from the Command Pal
|
||||
)) == "yes"
|
||||
) {
|
||||
const trialSetting = { ...this.initialSettings, ...this.editingSettings };
|
||||
const newTweaks = await this.plugin.$$checkAndAskUseRemoteConfiguration(trialSetting);
|
||||
const newTweaks = await this.services.tweakValue.checkAndAskUseRemoteConfiguration(trialSetting);
|
||||
if (newTweaks.result !== false) {
|
||||
this.editingSettings = { ...this.editingSettings, ...newTweaks.result };
|
||||
this.requestUpdate();
|
||||
|
||||
@@ -46,7 +46,7 @@ export function paneSetup(
|
||||
text.setButtonText($msg("obsidianLiveSyncSettingTab.btnEnable")).onClick(async () => {
|
||||
this.editingSettings.isConfigured = true;
|
||||
await this.saveAllDirtySettings();
|
||||
this.plugin.$$askReload();
|
||||
this.services.appLifecycle.askRestart();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -91,10 +91,10 @@ export function paneSetup(
|
||||
this.editingSettings = { ...this.editingSettings, ...DEFAULT_SETTINGS };
|
||||
await this.saveAllDirtySettings();
|
||||
this.plugin.settings = { ...DEFAULT_SETTINGS };
|
||||
await this.plugin.$$saveSettingData();
|
||||
await this.plugin.$$resetLocalDatabase();
|
||||
await this.services.setting.saveSettingData();
|
||||
await this.services.database.resetDatabase();
|
||||
// await this.plugin.initializeDatabase();
|
||||
this.plugin.$$askReload();
|
||||
this.services.appLifecycle.askRestart();
|
||||
}
|
||||
})
|
||||
.setWarning();
|
||||
|
||||
@@ -105,7 +105,7 @@ export function paneSyncSettings(
|
||||
if (!this.editingSettings.isConfigured) {
|
||||
this.editingSettings.isConfigured = true;
|
||||
await this.saveAllDirtySettings();
|
||||
await this.plugin.$$realizeSettingSyncMode();
|
||||
await this.services.setting.onRealiseSetting();
|
||||
await this.rebuildDB("localOnly");
|
||||
// this.resetEditingSettings();
|
||||
if (
|
||||
@@ -124,13 +124,13 @@ export function paneSyncSettings(
|
||||
await this.confirmRebuild();
|
||||
} else {
|
||||
await this.saveAllDirtySettings();
|
||||
await this.plugin.$$realizeSettingSyncMode();
|
||||
this.plugin.$$askReload();
|
||||
await this.services.setting.onRealiseSetting();
|
||||
this.services.appLifecycle.askRestart();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await this.saveAllDirtySettings();
|
||||
await this.plugin.$$realizeSettingSyncMode();
|
||||
await this.services.setting.onRealiseSetting();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -169,7 +169,7 @@ export function paneSyncSettings(
|
||||
}
|
||||
await this.saveSettings(["liveSync", "periodicReplication"]);
|
||||
|
||||
await this.plugin.$$realizeSettingSyncMode();
|
||||
await this.services.setting.onRealiseSetting();
|
||||
});
|
||||
|
||||
new Setting(paneEl)
|
||||
@@ -289,21 +289,21 @@ export function paneSyncSettings(
|
||||
button.setButtonText("Merge").onClick(async () => {
|
||||
this.closeSetting();
|
||||
// this.resetEditingSettings();
|
||||
await this.plugin.$anyConfigureOptionalSyncFeature("MERGE");
|
||||
await this.services.setting.enableOptionalFeature("MERGE");
|
||||
});
|
||||
})
|
||||
.addButton((button) => {
|
||||
button.setButtonText("Fetch").onClick(async () => {
|
||||
this.closeSetting();
|
||||
// this.resetEditingSettings();
|
||||
await this.plugin.$anyConfigureOptionalSyncFeature("FETCH");
|
||||
await this.services.setting.enableOptionalFeature("FETCH");
|
||||
});
|
||||
})
|
||||
.addButton((button) => {
|
||||
button.setButtonText("Overwrite").onClick(async () => {
|
||||
this.closeSetting();
|
||||
// this.resetEditingSettings();
|
||||
await this.plugin.$anyConfigureOptionalSyncFeature("OVERWRITE");
|
||||
await this.services.setting.enableOptionalFeature("OVERWRITE");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user