Adapt settings pages to Obsidian's declarative API

This commit is contained in:
vorotamoroz
2026-08-24 12:17:19 +00:00
parent d8f7762d01
commit 47759f6205
20 changed files with 1327 additions and 185 deletions
@@ -5,7 +5,7 @@ import { fireAndForget } from "@vrtmrz/livesync-commonlib/compat/common/utils";
import { LiveSyncCouchDBReplicator } from "@vrtmrz/livesync-commonlib/compat/replication/couchdb/LiveSyncReplicator";
import { LiveSyncSetting as Setting } from "./LiveSyncSetting.ts";
import type { ObsidianLiveSyncSettingTab } from "./ObsidianLiveSyncSettingTab";
import { visibleOnly, type PageFunctions } from "./SettingPane";
import { setButtonDestructiveState, visibleOnly, type PageFunctions } from "./SettingPane";
export function paneMaintenance(
this: ObsidianLiveSyncSettingTab,
paneEl: HTMLElement,
@@ -33,7 +33,7 @@ export function paneMaintenance(
e.addEventListener("click", () => {
fireAndForget(async () => {
await this.services.replication.markResolved();
this.display();
this.requestPageRefresh();
});
});
}
@@ -60,7 +60,7 @@ export function paneMaintenance(
e.addEventListener("click", () => {
fireAndForget(async () => {
await this.services.replication.markUnlocked();
this.display();
this.requestPageRefresh();
});
});
}
@@ -73,10 +73,9 @@ export function paneMaintenance(
.setName("Lock Server")
.setDesc("Lock the remote server to prevent synchronization with other devices.")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Lock")
.setDisabled(false)
.setWarning()
.onClick(async () => {
await this.services.replication.markLocked();
})
@@ -87,10 +86,9 @@ export function paneMaintenance(
.setName("Emergency restart")
.setDesc("Disables all synchronization and restart.")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Flag and restart")
.setDisabled(false)
.setWarning()
.onClick(async () => {
await this.core.storageAccess.writeFileAuto(FLAGMD_REDFLAG, "");
this.services.appLifecycle.performRestart();
@@ -132,9 +130,8 @@ export function paneMaintenance(
.setName("Resend")
.setDesc("Resend all chunks to the remote.")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Send chunks")
.setWarning()
.setDisabled(false)
.onClick(async () => {
if (this.core.replicator instanceof LiveSyncCouchDBReplicator) {
@@ -150,9 +147,8 @@ export function paneMaintenance(
"Initialise journal received history. On the next sync, every item except this device sent will be downloaded again."
)
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Reset received")
.setWarning()
.setDisabled(false)
.onClick(async () => {
await this.getMinioJournalSyncClient().updateCheckPointInfo((info) => ({
@@ -171,9 +167,8 @@ export function paneMaintenance(
"Initialise journal sent history. On the next sync, every item except this device received will be sent again."
)
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Reset sent history")
.setWarning()
.setDisabled(false)
.onClick(async () => {
await this.getMinioJournalSyncClient().updateCheckPointInfo((info) => ({
@@ -314,9 +309,8 @@ export function paneMaintenance(
.setName("Overwrite remote")
.setDesc("Overwrite remote with local DB and passphrase.")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Send")
.setWarning()
.setDisabled(false)
.onClick(async () => {
await this.rebuildDB("remoteOnly");
@@ -327,9 +321,8 @@ export function paneMaintenance(
.setName("Reset all journal counter")
.setDesc("Initialise all journal history, On the next sync, every item will be received and sent.")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Reset all")
.setWarning()
.setDisabled(false)
.onClick(async () => {
await this.getMinioJournalSyncClient().resetCheckpointInfo();
@@ -342,9 +335,8 @@ export function paneMaintenance(
.setName("Purge all journal counter")
.setDesc("Purge all download/upload cache.")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Reset all")
.setWarning()
.setDisabled(false)
.onClick(() => {
this.getMinioJournalSyncClient().resetAllCaches();
@@ -357,9 +349,8 @@ export function paneMaintenance(
.setName("Fresh Start Wipe")
.setDesc("Delete all data on the remote server.")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Delete")
.setWarning()
.setDisabled(false)
.onClick(async () => {
await this.getMinioJournalSyncClient().updateCheckPointInfo((info) => ({
@@ -381,9 +372,8 @@ export function paneMaintenance(
new Setting(paneEl)
.setName("Delete local database to reset or uninstall Self-hosted LiveSync")
.addButton((button) =>
button
setButtonDestructiveState(button)
.setButtonText("Delete")
.setWarning()
.setDisabled(false)
.onClick(async () => {
await this.services.database.resetDatabase();