refactor statusbar
This commit is contained in:
parent
8a631ee809
commit
b3c9ac8cbb
@ -88,7 +88,6 @@ export interface RemotelySavePluginSettings {
|
||||
skipSizeLargerThan?: number;
|
||||
ignorePaths?: string[];
|
||||
enableStatusBarInfo?: boolean;
|
||||
lastSuccessSync?: number;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit a8f6e1d05def00387ee5a50a829fd91e60ae6351
|
||||
Subproject commit cdbb220a6bb0f566912ec08a8476316c8232fb79
|
||||
@ -18,6 +18,7 @@ export const DEFAULT_TBL_SYNC_MAPPING = "syncmetadatahistory";
|
||||
export const DEFAULT_SYNC_PLANS_HISTORY = "syncplanshistory";
|
||||
export const DEFAULT_TBL_VAULT_RANDOM_ID_MAPPING = "vaultrandomidmapping";
|
||||
export const DEFAULT_TBL_LOGGER_OUTPUT = "loggeroutput";
|
||||
export const DEFAULT_TBL_SIMPLE_KV_FOR_MISC = "simplekvformisc";
|
||||
|
||||
export interface FileFolderHistoryRecord {
|
||||
key: string;
|
||||
@ -58,6 +59,7 @@ export interface InternalDBs {
|
||||
syncPlansTbl: LocalForage;
|
||||
vaultRandomIDMappingTbl: LocalForage;
|
||||
loggerOutputTbl: LocalForage;
|
||||
simpleKVForMiscTbl: LocalForage;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,6 +218,10 @@ export const prepareDBs = async (
|
||||
name: DEFAULT_DB_NAME,
|
||||
storeName: DEFAULT_TBL_LOGGER_OUTPUT,
|
||||
}),
|
||||
simpleKVForMiscTbl: localforage.createInstance({
|
||||
name: DEFAULT_DB_NAME,
|
||||
storeName: DEFAULT_TBL_SIMPLE_KV_FOR_MISC,
|
||||
}),
|
||||
} as InternalDBs;
|
||||
|
||||
// try to get vaultRandomID firstly
|
||||
@ -680,3 +686,23 @@ export const clearExpiredLoggerOutputRecords = async (db: InternalDBs) => {
|
||||
});
|
||||
await Promise.all(ps);
|
||||
};
|
||||
|
||||
export const upsertLastSuccessSyncByVault = async (
|
||||
db: InternalDBs,
|
||||
vaultRandomID: string,
|
||||
millis: number
|
||||
) => {
|
||||
await db.simpleKVForMiscTbl.setItem(
|
||||
`${vaultRandomID}-lastSuccessSyncMillis`,
|
||||
millis
|
||||
);
|
||||
};
|
||||
|
||||
export const getLastSuccessSyncByVault = async (
|
||||
db: InternalDBs,
|
||||
vaultRandomID: string
|
||||
) => {
|
||||
return (await db.simpleKVForMiscTbl.getItem(
|
||||
`${vaultRandomID}-lastSuccessSyncMillis`
|
||||
)) as number;
|
||||
};
|
||||
|
||||
25
src/main.ts
25
src/main.ts
@ -32,6 +32,8 @@ import {
|
||||
insertLoggerOutputByVault,
|
||||
clearExpiredLoggerOutputRecords,
|
||||
clearExpiredSyncPlanRecords,
|
||||
upsertLastSuccessSyncByVault,
|
||||
getLastSuccessSyncByVault,
|
||||
} from "./localdb";
|
||||
import { RemoteClient } from "./remote";
|
||||
import {
|
||||
@ -88,7 +90,6 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
||||
skipSizeLargerThan: -1,
|
||||
ignorePaths: [],
|
||||
enableStatusBarInfo: true,
|
||||
lastSuccessSync: -1,
|
||||
};
|
||||
|
||||
interface OAuth2Info {
|
||||
@ -361,7 +362,12 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
this.syncStatus = "finish";
|
||||
this.syncStatus = "idle";
|
||||
|
||||
this.settings.lastSuccessSync = Date.now();
|
||||
const lastSuccessSyncMillis = Date.now();
|
||||
await upsertLastSuccessSyncByVault(
|
||||
this.db,
|
||||
this.vaultRandomID,
|
||||
lastSuccessSyncMillis
|
||||
);
|
||||
|
||||
if (this.syncRibbon !== undefined) {
|
||||
setIcon(this.syncRibbon, iconNameSyncWait);
|
||||
@ -369,7 +375,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
}
|
||||
|
||||
if (this.statusBarElement !== undefined) {
|
||||
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync);
|
||||
this.updateLastSuccessSyncMsg(lastSuccessSyncMillis);
|
||||
}
|
||||
|
||||
log.info(
|
||||
@ -689,11 +695,15 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
this.statusBarElement = statusBarItem.createEl("span");
|
||||
this.statusBarElement.setAttribute("aria-label-position", "top");
|
||||
|
||||
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync);
|
||||
this.updateLastSuccessSyncMsg(
|
||||
await getLastSuccessSyncByVault(this.db, this.vaultRandomID)
|
||||
);
|
||||
// update statusbar text every 30 seconds
|
||||
this.registerInterval(
|
||||
window.setInterval(() => {
|
||||
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync);
|
||||
window.setInterval(async () => {
|
||||
this.updateLastSuccessSyncMsg(
|
||||
await getLastSuccessSyncByVault(this.db, this.vaultRandomID)
|
||||
);
|
||||
}, 1000 * 30)
|
||||
);
|
||||
}
|
||||
@ -823,6 +833,9 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
if (this.settings.ignorePaths === undefined) {
|
||||
this.settings.ignorePaths = [];
|
||||
}
|
||||
if (this.settings.enableStatusBarInfo === undefined) {
|
||||
this.settings.enableStatusBarInfo = true;
|
||||
}
|
||||
}
|
||||
|
||||
async checkIfPresetRulesFollowed() {
|
||||
|
||||
@ -30,6 +30,7 @@ import {
|
||||
clearAllLoggerOutputRecords,
|
||||
insertLoggerOutputByVault,
|
||||
clearExpiredLoggerOutputRecords,
|
||||
upsertLastSuccessSyncByVault,
|
||||
} from "./localdb";
|
||||
import type RemotelySavePlugin from "./main"; // unavoidable
|
||||
import { RemoteClient } from "./remote";
|
||||
@ -197,8 +198,6 @@ class ChangeRemoteBaseDirModal extends Modal {
|
||||
button.onClick(async () => {
|
||||
this.plugin.settings[this.service].remoteBaseDir =
|
||||
this.newRemoteBaseDir;
|
||||
// reset last sync time
|
||||
this.plugin.settings.lastSuccessSync = -1;
|
||||
await this.plugin.saveSettings();
|
||||
new Notice(t("modal_remotebasedir_notice"));
|
||||
this.close();
|
||||
@ -1612,6 +1611,23 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
new Notice(t("settings_enablestatusbar_reloadrequired_notice"));
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(basicDiv)
|
||||
.setName(t("settings_resetstatusbar_time"))
|
||||
.setDesc(t("settings_resetstatusbar_time_desc"))
|
||||
.addButton((button) => {
|
||||
button.setButtonText(t("settings_resetstatusbar_button"));
|
||||
button.onClick(async () => {
|
||||
// reset last sync time
|
||||
await upsertLastSuccessSyncByVault(
|
||||
this.plugin.db,
|
||||
this.plugin.vaultRandomID,
|
||||
-1
|
||||
);
|
||||
this.plugin.updateLastSuccessSyncMsg(-1);
|
||||
new Notice(t("settings_resetstatusbar_notice"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
new Setting(basicDiv)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user