From 4f030242004739abcff6748cf923db5d4b1280bc Mon Sep 17 00:00:00 2001 From: Lars <29163322+Drumber@users.noreply.github.com> Date: Fri, 12 Aug 2022 18:02:06 +0200 Subject: [PATCH 1/3] Fixed webpack build Build failed due to missing polyfills needed by @azure/msal-node. --- package.json | 2 ++ webpack.config.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d0281eb..5afdc1c 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "dropbox": "^10.28.0", "emoji-regex": "^10.1.0", "http-status-codes": "^2.2.0", + "https-browserify": "^1.0.0", "localforage": "^1.10.0", "lodash": "^4.17.21", "loglevel": "^1.8.0", @@ -86,6 +87,7 @@ "rfc4648": "^1.5.1", "rimraf": "^3.0.2", "stream-browserify": "^3.0.0", + "stream-http": "^3.2.0", "url": "^0.11.0", "util": "^0.12.4", "webdav": "^4.9.0", diff --git a/webpack.config.js b/webpack.config.js index 03e8c62..c815e0d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -55,8 +55,8 @@ module.exports = { // crypto: false, // domain: require.resolve("domain-browser"), // events: require.resolve("events"), - // http: require.resolve("stream-http"), - // https: require.resolve("https-browserify"), + http: require.resolve("stream-http"), + https: require.resolve("https-browserify"), net: false, // os: require.resolve("os-browserify/browser"), path: require.resolve("path-browserify"), From 30d94986c68a854c5d2fb430c9a76d7768ead682 Mon Sep 17 00:00:00 2001 From: Lars <29163322+Drumber@users.noreply.github.com> Date: Fri, 12 Aug 2022 18:05:45 +0200 Subject: [PATCH 2/3] Added last sync time to statusbar Adds an item to the statusbar that displays the time of the last successful sync. --- src/baseTypes.ts | 1 + src/langs | 2 +- src/main.ts | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ src/settings.ts | 2 ++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/baseTypes.ts b/src/baseTypes.ts index 7d540d1..4c6fafc 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -86,6 +86,7 @@ export interface RemotelySavePluginSettings { lang?: LangTypeAndAuto; logToDB?: boolean; skipSizeLargerThan?: number; + lastSuccessSync?: number; /** * @deprecated diff --git a/src/langs b/src/langs index 42eab5d..58c0bc5 160000 --- a/src/langs +++ b/src/langs @@ -1 +1 @@ -Subproject commit 42eab5d544961f4c7830c63ba9559375437340c0 +Subproject commit 58c0bc5057aee3825bc21b50f2d4b1c95da17b9b diff --git a/src/main.ts b/src/main.ts index 1656afe..727ce82 100644 --- a/src/main.ts +++ b/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. diff --git a/src/settings.ts b/src/settings.ts index e851c9e..b92a6d0 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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(); From 229f74b5e8253fa2935e13dd68d6a6a27a1fb04a Mon Sep 17 00:00:00 2001 From: Lars <29163322+Drumber@users.noreply.github.com> Date: Sat, 13 Aug 2022 11:55:19 +0200 Subject: [PATCH 3/3] Added option to settings to toggle status bar item --- src/baseTypes.ts | 1 + src/langs | 2 +- src/main.ts | 22 +++++++++++++++------- src/settings.ts | 16 ++++++++++++++++ tests/configPersist.test.ts | 1 + 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/baseTypes.ts b/src/baseTypes.ts index 4c6fafc..ed56298 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -86,6 +86,7 @@ export interface RemotelySavePluginSettings { lang?: LangTypeAndAuto; logToDB?: boolean; skipSizeLargerThan?: number; + enableStatusBarInfo: boolean; lastSuccessSync?: number; /** diff --git a/src/langs b/src/langs index 58c0bc5..a0c4a6c 160000 --- a/src/langs +++ b/src/langs @@ -1 +1 @@ -Subproject commit 58c0bc5057aee3825bc21b50f2d4b1c95da17b9b +Subproject commit a0c4a6ca6c7e5d5f3b7f1cd28ec13518a5a01c02 diff --git a/src/main.ts b/src/main.ts index 727ce82..2f5b7ad 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import { addIcon, setIcon, FileSystemAdapter, + Platform, } from "obsidian"; import cloneDeep from "lodash/cloneDeep"; import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide"; @@ -85,6 +86,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = { lang: "auto", logToDB: false, skipSizeLargerThan: -1, + enableStatusBarInfo: true, lastSuccessSync: -1 }; @@ -679,14 +681,18 @@ 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(() => { + // Create Status Bar Item (not supported on mobile) + if (!Platform.isMobileApp && this.settings.enableStatusBarInfo === true) { + const statusBarItem = this.addStatusBarItem(); + this.statusBarElement = statusBarItem.createEl("span"); + this.statusBarElement.setAttribute("aria-label-position", "top"); + this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync); - }, 1000*30)); + // update statusbar text every 30 seconds + this.registerInterval(window.setInterval(() => { + this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync); + }, 1000 * 30)); + } this.addCommand({ id: "start-sync", @@ -983,6 +989,8 @@ export default class RemotelySavePlugin extends Plugin { } updateLastSuccessSyncMsg(lastSuccessSyncMillis?: number) { + if (this.statusBarElement === undefined) return; + const t = (x: TransItemType, vars?: any) => { return this.i18n.t(x, vars); }; diff --git a/src/settings.ts b/src/settings.ts index b92a6d0..ca76a4c 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1597,6 +1597,22 @@ export class RemotelySaveSettingTab extends PluginSettingTab { await this.plugin.saveSettings(); }); }); + + // custom status bar items is not supported on mobile + if (!Platform.isMobileApp) { + new Setting(basicDiv) + .setName(t("settings_enablestatusbar_info")) + .setDesc(t("settings_enablestatusbar_info_desc")) + .addToggle((toggle) => { + toggle + .setValue(this.plugin.settings.enableStatusBarInfo) + .onChange(async (val) => { + this.plugin.settings.enableStatusBarInfo = val; + await this.plugin.saveSettings(); + new Notice(t("settings_enablestatusbar_reloadrequired_notice")); + }); + }); + } ////////////////////////////////////////////////// // below for advanced settings diff --git a/tests/configPersist.test.ts b/tests/configPersist.test.ts index cde0a7c..544eac8 100644 --- a/tests/configPersist.test.ts +++ b/tests/configPersist.test.ts @@ -23,6 +23,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = { password: "password", serviceType: "s3", currLogLevel: "info", + enableStatusBarInfo: true, }; describe("Config Persist tests", () => {