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>
This commit is contained in:
Felvesthe 2025-05-11 01:04:15 +02:00
parent b6822b20c9
commit 7dba2bdf39
3 changed files with 33 additions and 23 deletions

View file

@ -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,

View file

@ -1,13 +1,15 @@
export interface NoteLockerSettings {
lockedNotes: Set<string>;
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
};

View file

@ -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.'
});