Added last sync time to statusbar
Adds an item to the statusbar that displays the time of the last successful sync.
This commit is contained in:
parent
4f03024200
commit
30d94986c6
@ -86,6 +86,7 @@ export interface RemotelySavePluginSettings {
|
|||||||
lang?: LangTypeAndAuto;
|
lang?: LangTypeAndAuto;
|
||||||
logToDB?: boolean;
|
logToDB?: boolean;
|
||||||
skipSizeLargerThan?: number;
|
skipSizeLargerThan?: number;
|
||||||
|
lastSuccessSync?: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit 42eab5d544961f4c7830c63ba9559375437340c0
|
Subproject commit 58c0bc5057aee3825bc21b50f2d4b1c95da17b9b
|
||||||
66
src/main.ts
66
src/main.ts
@ -85,6 +85,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
|||||||
lang: "auto",
|
lang: "auto",
|
||||||
logToDB: false,
|
logToDB: false,
|
||||||
skipSizeLargerThan: -1,
|
skipSizeLargerThan: -1,
|
||||||
|
lastSuccessSync: -1
|
||||||
};
|
};
|
||||||
|
|
||||||
interface OAuth2Info {
|
interface OAuth2Info {
|
||||||
@ -125,6 +126,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
settings: RemotelySavePluginSettings;
|
settings: RemotelySavePluginSettings;
|
||||||
db: InternalDBs;
|
db: InternalDBs;
|
||||||
syncStatus: SyncStatusType;
|
syncStatus: SyncStatusType;
|
||||||
|
statusBarElement: HTMLSpanElement;
|
||||||
oauth2Info: OAuth2Info;
|
oauth2Info: OAuth2Info;
|
||||||
currLogLevel: string;
|
currLogLevel: string;
|
||||||
currSyncMsg?: string;
|
currSyncMsg?: string;
|
||||||
@ -355,11 +357,17 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
this.syncStatus = "finish";
|
this.syncStatus = "finish";
|
||||||
this.syncStatus = "idle";
|
this.syncStatus = "idle";
|
||||||
|
|
||||||
|
this.settings.lastSuccessSync = Date.now();
|
||||||
|
|
||||||
if (this.syncRibbon !== undefined) {
|
if (this.syncRibbon !== undefined) {
|
||||||
setIcon(this.syncRibbon, iconNameSyncWait);
|
setIcon(this.syncRibbon, iconNameSyncWait);
|
||||||
this.syncRibbon.setAttribute("aria-label", originLabel);
|
this.syncRibbon.setAttribute("aria-label", originLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.statusBarElement !== undefined) {
|
||||||
|
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync);
|
||||||
|
}
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`${
|
`${
|
||||||
this.manifest.id
|
this.manifest.id
|
||||||
@ -671,6 +679,15 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
async () => this.syncRun("manual")
|
async () => this.syncRun("manual")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const statusBarItem = this.addStatusBarItem();
|
||||||
|
this.statusBarElement = statusBarItem.createEl("span");
|
||||||
|
this.statusBarElement.setAttribute("aria-label-position", "top");
|
||||||
|
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync);
|
||||||
|
// update statusbar text every 30 seconds
|
||||||
|
this.registerInterval(window.setInterval(() => {
|
||||||
|
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync);
|
||||||
|
}, 1000*30));
|
||||||
|
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: "start-sync",
|
id: "start-sync",
|
||||||
name: t("command_startsync"),
|
name: t("command_startsync"),
|
||||||
@ -965,6 +982,55 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
this.currSyncMsg = msg;
|
this.currSyncMsg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateLastSuccessSyncMsg(lastSuccessSyncMillis?: number) {
|
||||||
|
const t = (x: TransItemType, vars?: any) => {
|
||||||
|
return this.i18n.t(x, vars);
|
||||||
|
};
|
||||||
|
|
||||||
|
let lastSyncMsg = t("statusbar_lastsync_never");
|
||||||
|
let lastSyncLabelMsg = t("statusbar_lastsync_never_label");
|
||||||
|
|
||||||
|
if (lastSuccessSyncMillis !== undefined && lastSuccessSyncMillis > 0) {
|
||||||
|
const deltaTime = Date.now() - lastSuccessSyncMillis;
|
||||||
|
|
||||||
|
// create human readable time
|
||||||
|
const years = Math.floor(deltaTime / 31556952000);
|
||||||
|
const months = Math.floor(deltaTime / 2629746000);
|
||||||
|
const weeks = Math.floor(deltaTime / 604800000);
|
||||||
|
const days = Math.floor(deltaTime / 86400000);
|
||||||
|
const hours = Math.floor(deltaTime / 3600000);
|
||||||
|
const minutes = Math.floor(deltaTime / 60000);
|
||||||
|
let timeText = "";
|
||||||
|
|
||||||
|
if (years > 0) {
|
||||||
|
timeText = t("statusbar_time_years", { time: years });
|
||||||
|
} else if (months > 0) {
|
||||||
|
timeText = t("statusbar_time_months", { time: months });
|
||||||
|
} else if (weeks > 0) {
|
||||||
|
timeText = t("statusbar_time_weeks", { time: weeks });
|
||||||
|
} else if (days > 0) {
|
||||||
|
timeText = t("statusbar_time_days", { time: days });
|
||||||
|
} else if (hours > 0) {
|
||||||
|
timeText = t("statusbar_time_hours", { time: hours });
|
||||||
|
} else if (minutes > 0) {
|
||||||
|
timeText = t("statusbar_time_minutes", { time: minutes });
|
||||||
|
} else {
|
||||||
|
timeText = t("statusbar_time_lessminute");
|
||||||
|
}
|
||||||
|
|
||||||
|
let dateText = new Date(lastSuccessSyncMillis)
|
||||||
|
.toLocaleTimeString(navigator.language, {
|
||||||
|
weekday: "long", year: "numeric", month: "long", day: "numeric"
|
||||||
|
});
|
||||||
|
|
||||||
|
lastSyncMsg = t("statusbar_lastsync", { time: timeText });
|
||||||
|
lastSyncLabelMsg = t("statusbar_lastsync_label", { date: dateText });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.statusBarElement.setText(lastSyncMsg);
|
||||||
|
this.statusBarElement.setAttribute("aria-label", lastSyncLabelMsg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Because data.json contains sensitive information,
|
* Because data.json contains sensitive information,
|
||||||
* We usually want to ignore it in the version control.
|
* We usually want to ignore it in the version control.
|
||||||
|
|||||||
@ -197,6 +197,8 @@ 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();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user