feat: add appMode preference (clipper/player) with persistence

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-22 19:00:34 -04:00
parent 8bcec23d8c
commit bd96da4dc9
2 changed files with 48 additions and 0 deletions

View File

@@ -49,6 +49,7 @@ export interface Preferences {
captionSettings: CaptionSettings;
clipListPosition: 'bottom' | 'left';
clipListWidth: number;
appMode: 'clipper' | 'player';
}
const DEFAULT_PREFERENCES: Preferences = {
@@ -57,6 +58,7 @@ const DEFAULT_PREFERENCES: Preferences = {
captionSettings: { ...DEFAULT_CAPTION_SETTINGS },
clipListPosition: 'bottom',
clipListWidth: 220,
appMode: 'clipper',
};
let store: Store | null = null;
@@ -81,6 +83,8 @@ export async function loadPreferences(): Promise<void> {
const savedClipListWidth = await store.get<number>('clipListWidth');
if (savedClipListPosition) preferences.clipListPosition = savedClipListPosition;
if (savedClipListWidth != null) preferences.clipListWidth = savedClipListWidth;
const savedAppMode = await store.get<'clipper' | 'player'>('appMode');
if (savedAppMode) preferences.appMode = savedAppMode;
})();
await loadPromise;
}
@@ -95,6 +99,7 @@ export async function savePreferences(): Promise<void> {
await store.set('captionSettings', preferences.captionSettings);
await store.set('clipListPosition', preferences.clipListPosition);
await store.set('clipListWidth', preferences.clipListWidth);
await store.set('appMode', preferences.appMode);
await store.save();
}
@@ -122,3 +127,8 @@ export async function setClipListWidth(width: number): Promise<void> {
preferences.clipListWidth = width;
await savePreferences();
}
export async function setAppMode(mode: 'clipper' | 'player'): Promise<void> {
preferences.appMode = mode;
await savePreferences();
}

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