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

View File

@ -86,6 +86,7 @@ export interface RemotelySavePluginSettings {
lang?: LangTypeAndAuto; lang?: LangTypeAndAuto;
logToDB?: boolean; logToDB?: boolean;
skipSizeLargerThan?: number; skipSizeLargerThan?: number;
enableStatusBarInfo: boolean;
lastSuccessSync?: number; lastSuccessSync?: number;
/** /**

@ -1 +1 @@
Subproject commit 58c0bc5057aee3825bc21b50f2d4b1c95da17b9b Subproject commit a0c4a6ca6c7e5d5f3b7f1cd28ec13518a5a01c02

View File

@ -6,6 +6,7 @@ import {
addIcon, addIcon,
setIcon, setIcon,
FileSystemAdapter, FileSystemAdapter,
Platform,
} from "obsidian"; } from "obsidian";
import cloneDeep from "lodash/cloneDeep"; import cloneDeep from "lodash/cloneDeep";
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide"; import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
@ -85,6 +86,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
lang: "auto", lang: "auto",
logToDB: false, logToDB: false,
skipSizeLargerThan: -1, skipSizeLargerThan: -1,
enableStatusBarInfo: true,
lastSuccessSync: -1 lastSuccessSync: -1
}; };
@ -679,14 +681,18 @@ export default class RemotelySavePlugin extends Plugin {
async () => this.syncRun("manual") async () => this.syncRun("manual")
); );
const statusBarItem = this.addStatusBarItem(); // Create Status Bar Item (not supported on mobile)
this.statusBarElement = statusBarItem.createEl("span"); if (!Platform.isMobileApp && this.settings.enableStatusBarInfo === true) {
this.statusBarElement.setAttribute("aria-label-position", "top"); const statusBarItem = this.addStatusBarItem();
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync); this.statusBarElement = statusBarItem.createEl("span");
// update statusbar text every 30 seconds this.statusBarElement.setAttribute("aria-label-position", "top");
this.registerInterval(window.setInterval(() => {
this.updateLastSuccessSyncMsg(this.settings.lastSuccessSync); 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({ this.addCommand({
id: "start-sync", id: "start-sync",
@ -983,6 +989,8 @@ export default class RemotelySavePlugin extends Plugin {
} }
updateLastSuccessSyncMsg(lastSuccessSyncMillis?: number) { updateLastSuccessSyncMsg(lastSuccessSyncMillis?: number) {
if (this.statusBarElement === undefined) return;
const t = (x: TransItemType, vars?: any) => { const t = (x: TransItemType, vars?: any) => {
return this.i18n.t(x, vars); return this.i18n.t(x, vars);
}; };

View File

@ -1597,6 +1597,22 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
await this.plugin.saveSettings(); 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 // below for advanced settings

View File

@ -23,6 +23,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
password: "password", password: "password",
serviceType: "s3", serviceType: "s3",
currLogLevel: "info", currLogLevel: "info",
enableStatusBarInfo: true,
}; };
describe("Config Persist tests", () => { describe("Config Persist tests", () => {