mirror of
https://github.com/remotely-save/remotely-save.git
synced 2024-06-07 21:10:45 +00:00
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;
|
||||
logToDB?: boolean;
|
||||
skipSizeLargerThan?: number;
|
||||
lastSuccessSync?: number;
|
||||
|
||||
/**
|
||||
* @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",
|
||||
logToDB: false,
|
||||
skipSizeLargerThan: -1,
|
||||
lastSuccessSync: -1
|
||||
};
|
||||
|
||||
interface OAuth2Info {
|
||||
@ -125,6 +126,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
settings: RemotelySavePluginSettings;
|
||||
db: InternalDBs;
|
||||
syncStatus: SyncStatusType;
|
||||
statusBarElement: HTMLSpanElement;
|
||||
oauth2Info: OAuth2Info;
|
||||
currLogLevel: string;
|
||||
currSyncMsg?: string;
|
||||
@ -355,11 +357,17 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
this.syncStatus = "finish";
|
||||
this.syncStatus = "idle";
|
||||
|
||||
this.settings.lastSuccessSync = Date.now();
|
||||
|
||||
if (this.syncRibbon !== undefined) {
|
||||
setIcon(this.syncRibbon, iconNameSyncWait);
|
||||
this.syncRibbon.setAttribute("aria-label", originLabel);
|
||||
}
|
||||
|
||||
if (this.statusBarElement !== undefined) {
|
||||
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync);
|
||||
}
|
||||
|
||||
log.info(
|
||||
`${
|
||||
this.manifest.id
|
||||
@ -671,6 +679,15 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
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({
|
||||
id: "start-sync",
|
||||
name: t("command_startsync"),
|
||||
@ -965,6 +982,55 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
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,
|
||||
* We usually want to ignore it in the version control.
|
||||
|
@ -197,6 +197,8 @@ 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();
|
||||
|
Loading…
Reference in New Issue
Block a user