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