diff --git a/package.json b/package.json index a3e3d71..677adb8 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,6 @@ "assert": "^2.0.0", "aws-crt": "^1.10.1", "buffer": "^6.0.3", - "codemirror": "^5.63.1", "crypto-browserify": "^3.12.0", "dropbox": "^10.22.0", "http-status-codes": "^2.2.0", diff --git a/src/localdb.ts b/src/localdb.ts index d3ad57b..abcc1a0 100644 --- a/src/localdb.ts +++ b/src/localdb.ts @@ -196,6 +196,26 @@ export const prepareDBs = async (vaultRandomID: string) => { return db; }; +export const dropDBs = async (db: InternalDBs) => { + const a1 = localforage.dropInstance({ + name: DEFAULT_DB_NAME, + storeName: DEFAULT_TBL_VERSION, + }); + const a2 = localforage.dropInstance({ + name: DEFAULT_DB_NAME, + storeName: DEFAULT_TBL_DELETE_HISTORY, + }); + const a3 = localforage.dropInstance({ + name: DEFAULT_DB_NAME, + storeName: DEFAULT_TBL_SYNC_MAPPING, + }); + const a4 = localforage.dropInstance({ + name: DEFAULT_DB_NAME, + storeName: DEFAULT_SYNC_PLANS_HISTORY, + }); + await Promise.all([a1, a2, a3, a4]); +}; + export const destroyDBs = async () => { // await localforage.dropInstance({ // name: DEFAULT_DB_NAME, diff --git a/src/main.ts b/src/main.ts index ab5b6c7..c71cac5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,13 +10,14 @@ import { COMMAND_URI, } from "./baseTypes"; import { importQrCodeUri } from "./importExport"; -import type { InternalDBs } from "./localdb"; import { insertDeleteRecordByVault, insertRenameRecordByVault, insertSyncPlanRecordByVault, loadDeleteRenameHistoryTableByVault, prepareDBs, + dropDBs, + InternalDBs, } from "./localdb"; import { RemoteClient } from "./remote"; import { @@ -77,16 +78,25 @@ type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit"; const iconNameSyncWait = `remotely-save-sync-wait`; const iconNameSyncRunning = `remotely-save-sync-running`; -const iconSvgSyncWait = createElement(RotateCcw); -iconSvgSyncWait.setAttribute("width", "100"); -iconSvgSyncWait.setAttribute("height", "100"); -const iconSvgSyncRunning = createElement(RefreshCcw); -iconSvgSyncRunning.setAttribute("width", "100"); -iconSvgSyncRunning.setAttribute("height", "100"); +const getIconSvg = () => { + const iconSvgSyncWait = createElement(RotateCcw); + iconSvgSyncWait.setAttribute("width", "100"); + iconSvgSyncWait.setAttribute("height", "100"); + const iconSvgSyncRunning = createElement(RefreshCcw); + iconSvgSyncRunning.setAttribute("width", "100"); + iconSvgSyncRunning.setAttribute("height", "100"); + const res = { + iconSvgSyncWait: iconSvgSyncWait.outerHTML, + iconSvgSyncRunning: iconSvgSyncRunning.outerHTML, + }; + + iconSvgSyncWait.empty(); + iconSvgSyncRunning.empty(); + return res; +}; export default class RemotelySavePlugin extends Plugin { settings: RemotelySavePluginSettings; - // cm: CodeMirror.Editor; db: InternalDBs; syncStatus: SyncStatusType; oauth2Info: OAuth2Info; @@ -344,8 +354,10 @@ export default class RemotelySavePlugin extends Plugin { async onload() { log.info(`loading plugin ${this.manifest.id}`); - addIcon(iconNameSyncWait, iconSvgSyncWait.outerHTML); - addIcon(iconNameSyncRunning, iconSvgSyncRunning.outerHTML); + const { iconSvgSyncWait, iconSvgSyncRunning } = getIconSvg(); + + addIcon(iconNameSyncWait, iconSvgSyncWait); + addIcon(iconNameSyncRunning, iconSvgSyncRunning); this.oauth2Info = { verifier: "", @@ -629,9 +641,14 @@ export default class RemotelySavePlugin extends Plugin { } } - onunload() { + async onunload() { log.info(`unloading plugin ${this.manifest.id}`); - this.destroyDBs(); + await dropDBs(this.db); + this.syncRibbon = undefined; + if (this.oauth2Info !== undefined) { + this.oauth2Info.helperModal = undefined; + this.oauth2Info = undefined; + } } async loadSettings() { @@ -792,10 +809,6 @@ export default class RemotelySavePlugin extends Plugin { await this.saveSettings(); } - destroyDBs() { - /* destroyDBs(this.db); */ - } - async setCurrSyncMsg( i: number, totalCount: number, diff --git a/src/settings.ts b/src/settings.ts index 5728caf..aa7a077 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1376,15 +1376,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab { .onChange(async (val) => { if (val === "enable" && !bridge.secondConfirm) { dropdown.setValue("disable"); - const modal = new SyncConfigDirModal( - this.app, - this.plugin, - () => { - bridge.secondConfirm = true; - dropdown.setValue("enable"); - } - ); - modal.open(); + new SyncConfigDirModal(this.app, this.plugin, () => { + bridge.secondConfirm = true; + dropdown.setValue("enable"); + }).open(); } else { bridge.secondConfirm = false; this.plugin.settings.syncConfigDir = false; @@ -1506,4 +1501,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab { }); }); } + + hide() { + let { containerEl } = this; + containerEl.empty(); + super.hide(); + } }