fix memory. Squashed commit of the following:

commit 1c24e48f2528238aeac417866ccec9ee3deced5f
Author: fyears <1142836+fyears@users.noreply.github.com>
Date:   Fri Mar 25 02:08:05 2022 +0800

    just some trying
This commit is contained in:
fyears 2022-03-26 09:45:48 +08:00
parent a5e415aeaf
commit 6474faad51
4 changed files with 59 additions and 26 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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,

View File

@ -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();
}
}