From 7dba2bdf39339f28abea3d30fb03b027aef546a1 Mon Sep 17 00:00:00 2001 From: Felvesthe <23108389+Felvesthe@users.noreply.github.com> Date: Sun, 11 May 2025 01:04:15 +0200 Subject: [PATCH] Bring back separate notification max length settings for mobile and desktop * Unified setting causes issues with cross-device config sync * Hide desktop setting on mobile, and mobile setting on desktop Signed-off-by: Felvesthe <23108389+Felvesthe@users.noreply.github.com> --- src/main.ts | 16 +++------------- src/models/types.ts | 6 ++++-- src/settings.ts | 34 ++++++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/main.ts b/src/main.ts index e8c6011..cd21d85 100644 --- a/src/main.ts +++ b/src/main.ts @@ -159,7 +159,9 @@ export default class NoteLockerPlugin extends Plugin { } private truncateFileName(name: string): string { - const maxLength = this.settings.notificationMaxLength; + const maxLength = Platform.isMobile + ? this.settings.mobileNotificationMaxLength + : this.settings.desktopNotificationMaxLength; return name.length > maxLength ? `${name.slice(0, maxLength)}…` : name; @@ -196,27 +198,15 @@ export default class NoteLockerPlugin extends Plugin { async loadSettings() { const loaded = await this.loadData(); - if (loaded) { this.settings = { ...DEFAULT_SETTINGS, ...loaded, lockedNotes: new Set(loaded.lockedNotes || []) }; - } else { - this.settings = { ...DEFAULT_SETTINGS }; } - - if (Platform.isMobile && this.settings.notificationMaxLength === DEFAULT_SETTINGS.notificationMaxLength) { - this.settings.notificationMaxLength = 18; // Default for mobile - } else if (!Platform.isMobile && this.settings.notificationMaxLength === DEFAULT_SETTINGS.notificationMaxLength) { - this.settings.notificationMaxLength = 22; // Default for desktop - } - - await this.saveSettings(); } - async saveSettings() { await this.saveData({ ...this.settings, diff --git a/src/models/types.ts b/src/models/types.ts index 434ca12..283d288 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -1,13 +1,15 @@ export interface NoteLockerSettings { lockedNotes: Set; - notificationMaxLength: number; + mobileNotificationMaxLength: number; + desktopNotificationMaxLength: number; showFileExplorerIcons: boolean; showStatusBarButton: boolean; } export const DEFAULT_SETTINGS: NoteLockerSettings = { lockedNotes: new Set(), - notificationMaxLength: 18, + mobileNotificationMaxLength: 18, + desktopNotificationMaxLength: 22, showFileExplorerIcons: true, showStatusBarButton: true }; diff --git a/src/settings.ts b/src/settings.ts index 4ca9c4a..d34c2db 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -13,8 +13,6 @@ export class NoteLockerSettingTab extends PluginSettingTab { const { containerEl } = this; containerEl.empty(); - let defaultNotificationMaxLength = Platform.isMobile ? 18 : 22; - new Setting(containerEl) .setName('Show locked notes in file explorer') .setDesc('Display a lock icon next to locked notes in the file explorer') @@ -33,20 +31,40 @@ export class NoteLockerSettingTab extends PluginSettingTab { await this.plugin.updateStatusBarVisibility(value); })); - new Setting(containerEl) - .setName('Notification max length') - .setDesc('Maximum length of file names in notifications') + const mobileNotificationSetting = new Setting(containerEl) + .setName('Mobile notification max length') + .setDesc('Maximum length of file names in notifications on mobile devices') .addText(text => text - .setPlaceholder(Platform.isMobile ? '18' : '22') - .setValue(String(this.plugin.settings.notificationMaxLength || defaultNotificationMaxLength)) + .setPlaceholder('18') + .setValue(String(this.plugin.settings.mobileNotificationMaxLength)) .onChange(async (value) => { const numValue = parseInt(value); if (!isNaN(numValue) && numValue > 0) { - this.plugin.settings.notificationMaxLength = numValue; + this.plugin.settings.mobileNotificationMaxLength = numValue; await this.plugin.saveSettings(); } })); + const desktopNotificationSetting = new Setting(containerEl) + .setName('Desktop notification max length') + .setDesc('Maximum length of file names in notifications on desktop') + .addText(text => text + .setPlaceholder('22') + .setValue(String(this.plugin.settings.desktopNotificationMaxLength)) + .onChange(async (value) => { + const numValue = parseInt(value); + if (!isNaN(numValue) && numValue > 0) { + this.plugin.settings.desktopNotificationMaxLength = numValue; + await this.plugin.saveSettings(); + } + })); + + if (Platform.isMobile) { + desktopNotificationSetting.settingEl.style.display = 'none'; + } else { + mobileNotificationSetting.settingEl.style.display = 'none'; + } + const hotkeyInfo = containerEl.createEl('p', { text: 'You can set a hotkey for locking/unlocking notes in Settings → Hotkeys → Toggle Lock for current note.' });