feat: add appMode preference (clipper/player) with persistence
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -49,6 +49,7 @@ export interface Preferences {
|
|||||||
captionSettings: CaptionSettings;
|
captionSettings: CaptionSettings;
|
||||||
clipListPosition: 'bottom' | 'left';
|
clipListPosition: 'bottom' | 'left';
|
||||||
clipListWidth: number;
|
clipListWidth: number;
|
||||||
|
appMode: 'clipper' | 'player';
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_PREFERENCES: Preferences = {
|
const DEFAULT_PREFERENCES: Preferences = {
|
||||||
@@ -57,6 +58,7 @@ const DEFAULT_PREFERENCES: Preferences = {
|
|||||||
captionSettings: { ...DEFAULT_CAPTION_SETTINGS },
|
captionSettings: { ...DEFAULT_CAPTION_SETTINGS },
|
||||||
clipListPosition: 'bottom',
|
clipListPosition: 'bottom',
|
||||||
clipListWidth: 220,
|
clipListWidth: 220,
|
||||||
|
appMode: 'clipper',
|
||||||
};
|
};
|
||||||
|
|
||||||
let store: Store | null = null;
|
let store: Store | null = null;
|
||||||
@@ -81,6 +83,8 @@ export async function loadPreferences(): Promise<void> {
|
|||||||
const savedClipListWidth = await store.get<number>('clipListWidth');
|
const savedClipListWidth = await store.get<number>('clipListWidth');
|
||||||
if (savedClipListPosition) preferences.clipListPosition = savedClipListPosition;
|
if (savedClipListPosition) preferences.clipListPosition = savedClipListPosition;
|
||||||
if (savedClipListWidth != null) preferences.clipListWidth = savedClipListWidth;
|
if (savedClipListWidth != null) preferences.clipListWidth = savedClipListWidth;
|
||||||
|
const savedAppMode = await store.get<'clipper' | 'player'>('appMode');
|
||||||
|
if (savedAppMode) preferences.appMode = savedAppMode;
|
||||||
})();
|
})();
|
||||||
await loadPromise;
|
await loadPromise;
|
||||||
}
|
}
|
||||||
@@ -95,6 +99,7 @@ export async function savePreferences(): Promise<void> {
|
|||||||
await store.set('captionSettings', preferences.captionSettings);
|
await store.set('captionSettings', preferences.captionSettings);
|
||||||
await store.set('clipListPosition', preferences.clipListPosition);
|
await store.set('clipListPosition', preferences.clipListPosition);
|
||||||
await store.set('clipListWidth', preferences.clipListWidth);
|
await store.set('clipListWidth', preferences.clipListWidth);
|
||||||
|
await store.set('appMode', preferences.appMode);
|
||||||
await store.save();
|
await store.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,3 +127,8 @@ export async function setClipListWidth(width: number): Promise<void> {
|
|||||||
preferences.clipListWidth = width;
|
preferences.clipListWidth = width;
|
||||||
await savePreferences();
|
await savePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function setAppMode(mode: 'clipper' | 'player'): Promise<void> {
|
||||||
|
preferences.appMode = mode;
|
||||||
|
await savePreferences();
|
||||||
|
}
|
||||||
|
|||||||
38
tests/lib/stores/preferences.test.ts
Normal file
38
tests/lib/stores/preferences.test.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
|
||||||
|
// Mock the Tauri store before importing the module under test
|
||||||
|
vi.mock('@tauri-apps/plugin-store', () => {
|
||||||
|
const mockStore = {
|
||||||
|
get: vi.fn().mockResolvedValue(null),
|
||||||
|
set: vi.fn().mockResolvedValue(undefined),
|
||||||
|
save: vi.fn().mockResolvedValue(undefined),
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
load: vi.fn().mockResolvedValue(mockStore),
|
||||||
|
Store: vi.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('preferences store — appMode', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.resetModules();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('defaults appMode to clipper', async () => {
|
||||||
|
const { preferences } = await import('$lib/stores/preferences.svelte');
|
||||||
|
expect(preferences.appMode).toBe('clipper');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setAppMode updates appMode to player', async () => {
|
||||||
|
const { preferences, setAppMode } = await import('$lib/stores/preferences.svelte');
|
||||||
|
await setAppMode('player');
|
||||||
|
expect(preferences.appMode).toBe('player');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setAppMode updates appMode back to clipper', async () => {
|
||||||
|
const { preferences, setAppMode } = await import('$lib/stores/preferences.svelte');
|
||||||
|
await setAppMode('player');
|
||||||
|
await setAppMode('clipper');
|
||||||
|
expect(preferences.appMode).toBe('clipper');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user