mirror of
https://github.com/felvesthe/Note-Locker.git
synced 2026-07-22 05:44:06 +00:00
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:
parent
b6822b20c9
commit
7dba2bdf39
3 changed files with 33 additions and 23 deletions
16
src/main.ts
16
src/main.ts
|
|
@ -159,7 +159,9 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private truncateFileName(name: string): string {
|
private truncateFileName(name: string): string {
|
||||||
const maxLength = this.settings.notificationMaxLength;
|
const maxLength = Platform.isMobile
|
||||||
|
? this.settings.mobileNotificationMaxLength
|
||||||
|
: this.settings.desktopNotificationMaxLength;
|
||||||
return name.length > maxLength
|
return name.length > maxLength
|
||||||
? `${name.slice(0, maxLength)}…`
|
? `${name.slice(0, maxLength)}…`
|
||||||
: name;
|
: name;
|
||||||
|
|
@ -196,27 +198,15 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
|
|
||||||
async loadSettings() {
|
async loadSettings() {
|
||||||
const loaded = await this.loadData();
|
const loaded = await this.loadData();
|
||||||
|
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
this.settings = {
|
this.settings = {
|
||||||
...DEFAULT_SETTINGS,
|
...DEFAULT_SETTINGS,
|
||||||
...loaded,
|
...loaded,
|
||||||
lockedNotes: new Set(loaded.lockedNotes || [])
|
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() {
|
async saveSettings() {
|
||||||
await this.saveData({
|
await this.saveData({
|
||||||
...this.settings,
|
...this.settings,
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
export interface NoteLockerSettings {
|
export interface NoteLockerSettings {
|
||||||
lockedNotes: Set<string>;
|
lockedNotes: Set<string>;
|
||||||
notificationMaxLength: number;
|
mobileNotificationMaxLength: number;
|
||||||
|
desktopNotificationMaxLength: number;
|
||||||
showFileExplorerIcons: boolean;
|
showFileExplorerIcons: boolean;
|
||||||
showStatusBarButton: boolean;
|
showStatusBarButton: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: NoteLockerSettings = {
|
export const DEFAULT_SETTINGS: NoteLockerSettings = {
|
||||||
lockedNotes: new Set(),
|
lockedNotes: new Set(),
|
||||||
notificationMaxLength: 18,
|
mobileNotificationMaxLength: 18,
|
||||||
|
desktopNotificationMaxLength: 22,
|
||||||
showFileExplorerIcons: true,
|
showFileExplorerIcons: true,
|
||||||
showStatusBarButton: true
|
showStatusBarButton: true
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ export class NoteLockerSettingTab extends PluginSettingTab {
|
||||||
const { containerEl } = this;
|
const { containerEl } = this;
|
||||||
containerEl.empty();
|
containerEl.empty();
|
||||||
|
|
||||||
let defaultNotificationMaxLength = Platform.isMobile ? 18 : 22;
|
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Show locked notes in file explorer')
|
.setName('Show locked notes in file explorer')
|
||||||
.setDesc('Display a lock icon next to locked notes in the 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);
|
await this.plugin.updateStatusBarVisibility(value);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
new Setting(containerEl)
|
const mobileNotificationSetting = new Setting(containerEl)
|
||||||
.setName('Notification max length')
|
.setName('Mobile notification max length')
|
||||||
.setDesc('Maximum length of file names in notifications')
|
.setDesc('Maximum length of file names in notifications on mobile devices')
|
||||||
.addText(text => text
|
.addText(text => text
|
||||||
.setPlaceholder(Platform.isMobile ? '18' : '22')
|
.setPlaceholder('18')
|
||||||
.setValue(String(this.plugin.settings.notificationMaxLength || defaultNotificationMaxLength))
|
.setValue(String(this.plugin.settings.mobileNotificationMaxLength))
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
const numValue = parseInt(value);
|
const numValue = parseInt(value);
|
||||||
if (!isNaN(numValue) && numValue > 0) {
|
if (!isNaN(numValue) && numValue > 0) {
|
||||||
this.plugin.settings.notificationMaxLength = numValue;
|
this.plugin.settings.mobileNotificationMaxLength = numValue;
|
||||||
await this.plugin.saveSettings();
|
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', {
|
const hotkeyInfo = containerEl.createEl('p', {
|
||||||
text: 'You can set a hotkey for locking/unlocking notes in Settings → Hotkeys → Toggle Lock for current note.'
|
text: 'You can set a hotkey for locking/unlocking notes in Settings → Hotkeys → Toggle Lock for current note.'
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue