From d0dfd7d60091667c577ab9af4220662d9c6609b8 Mon Sep 17 00:00:00 2001 From: Nick Winters <65742767+DynamicPlayerSector@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:35:00 +0300 Subject: [PATCH] Added "don't show emojis" feature --- manifest.json | 2 +- src/main.ts | 22 +++++++++++++++------- src/settings.ts | 32 +++++++++++++++++++++++++++----- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/manifest.json b/manifest.json index 35718e4..3158439 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "timethings", "name": "Time Things", - "version": "1.2.5", + "version": "1.2.6", "minAppVersion": "0.15.0", "description": "Show clock in the corner. Track total editing time of a note and the last time it was modified.", "author": "Nick Winters", diff --git a/src/main.ts b/src/main.ts index e69d3b1..fca833b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -88,9 +88,17 @@ export default class TimeThings extends Plugin { const ignoreKeys = [ "ArrowDown", "ArrowUp", + "ArrowLeft", + "ArrowRight", "Tab", "CapsLock", "Alt", + "PageUp", + "PageDown", + "Home", + "End", + "Meta", + "Escape", ] if (evt.ctrlKey || ignoreKeys.includes(evt.key)) { @@ -195,12 +203,12 @@ export default class TimeThings extends Plugin { if (this.isDebugBuild) { // Add DEBUG icon this.debugBar = this.addStatusBarItem(); - this.debugBar.setText("☢️ DEBUG BUILD ☢️") + this.settings.showEmojiStatusBar ? this.debugBar.setText("☢️ DEBUG BUILD ☢️") : this.debugBar.setText("/ DEBUG BUILD /"); } if (this.settings.enableEditDurationKey) { // Ad duration icon this.editDurationBar = this.addStatusBarItem(); - this.editDurationBar.setText("⌛"); + this.settings.showEmojiStatusBar ? this.editDurationBar.setText("⌛") : this.editDurationBar.setText("/"); } } @@ -228,21 +236,21 @@ export default class TimeThings extends Plugin { } let text = ""; if (+value < 60) { - text = `⌛ <1 m`; + text = this.settings.showEmojiStatusBar ? `⌛ <1 m` : `<1 m`; } else if (+value < 60 * 60) { const minutes = Math.floor(+value / 60); - text = `⌛ ${minutes} m`; + text = this.settings.showEmojiStatusBar ? `⌛ ${minutes} m` : `${minutes} m`; } else if (+value < 60 * 60 * 24) { const hours = Math.floor(+value / (60 * 60)); const minutes = Math.floor((+value - (hours * 60 * 60)) / 60); - text = `⌛ ${hours} h ${minutes} m`; + text = this.settings.showEmojiStatusBar ? `⌛ ${hours} h ${minutes} m` : `${hours} h ${minutes} m`; } else { const days = Math.floor(+value / (24 * 60 * 60)); const hours = Math.floor((+value - (days * 24 * 60 * 60)) / (60 * 60)); - text = `⌛ ${days} d ${hours} h`; + text = this.settings.showEmojiStatusBar ? `⌛ ${days} d ${hours} h` : `${days} d ${hours} h`; } this.editDurationBar.setText(text); } @@ -301,7 +309,7 @@ export default class TimeThings extends Plugin { const dateFormatted = dateChosen.format(this.settings.clockFormat); const emoji = timeUtils.momentToClockEmoji(dateChosen); - this.clockBar.setText(emoji + " " + dateFormatted); + this.settings.showEmojiStatusBar ? this.clockBar.setText(emoji + " " + dateFormatted) : this.clockBar.setText(dateFormatted); } async standardUpdateModifiedKey(file: TAbstractFile) { diff --git a/src/settings.ts b/src/settings.ts index 1e79b2c..b1f0e19 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -2,6 +2,7 @@ import { App, PluginSettingTab, Setting } from 'obsidian'; import TimeThings from './main'; export interface TimeThingsSettings { + showEmojiStatusBar: boolean; clockFormat: string; isUTC: boolean; updateIntervalMilliseconds: string; @@ -11,12 +12,16 @@ export interface TimeThingsSettings { enableModifiedKeyUpdate: boolean; useCustomFrontmatterHandlingSolution: boolean; updateIntervalFrontmatterMinutes: number; - editDurationPath: string, - enableEditDurationKey: boolean, - nonTypingEditingTimePercentage: number, + editDurationPath: string; + enableEditDurationKey: boolean; + nonTypingEditingTimePercentage: number; + enableSwitch: boolean; + switchKey: string; + switchKeyValue: string; } export const DEFAULT_SETTINGS: TimeThingsSettings = { + showEmojiStatusBar: true, clockFormat: 'hh:mm A', updateIntervalMilliseconds: '1000', isUTC: false, @@ -29,6 +34,9 @@ export const DEFAULT_SETTINGS: TimeThingsSettings = { editDurationPath: "edited_seconds", enableEditDurationKey: true, nonTypingEditingTimePercentage: 22, + enableSwitch: false, + switchKey: "timethings.switch", + switchKeyValue: "true", } export class TimeThingsSettingsTab extends PluginSettingTab { @@ -71,7 +79,20 @@ export class TimeThingsSettingsTab extends PluginSettingTab { ); containerEl.createEl('h1', { text: 'Status bar' }); - containerEl.createEl('p', { text: 'Displays clock in the status bar.' }); + containerEl.createEl('p', { text: 'Displays clock and duration edited in the status bar' }); + + new Setting(containerEl) + .setName('Enable emojis') + .setDesc('Show emojis in the status bar?') + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.showEmojiStatusBar) + .onChange(async (newValue) => { + this.plugin.settings.showEmojiStatusBar = newValue; + await this.plugin.saveSettings(); + await this.display(); + }), + ); new Setting(containerEl) .setName('Enable status bar clock') @@ -83,9 +104,10 @@ export class TimeThingsSettingsTab extends PluginSettingTab { this.plugin.settings.enableClock = newValue; await this.plugin.saveSettings(); await this.display(); - }), + }), ); + if (this.plugin.settings.enableClock === true) { new Setting(containerEl)