Added option to settings to toggle status bar item

This commit is contained in:
Lars
2022-08-13 11:55:19 +02:00
parent 30d94986c6
commit 229f74b5e8
5 changed files with 34 additions and 8 deletions
+15 -7
View File
@@ -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);
};