blob: ea7be34613fb0b30ec0c0fd6be2aeea1e963f1e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import { create } from 'zustand';
import { invoke } from '@tauri-apps/api/core';
export interface Settings {
work_duration_secs: number;
short_break_secs: number;
long_break_secs: number;
sessions_before_long_break: number;
}
interface SettingsStore {
settings: Settings | null;
fetchSettings: () => Promise<void>;
updateSettings: (s: Settings) => Promise<void>;
}
export const useSettingsStore = create<SettingsStore>((set) => ({
settings: null,
fetchSettings: async () => {
try {
const settings = await invoke<Settings>('get_settings');
set({ settings });
} catch (e) {
console.error('fetchSettings error:', e);
}
},
updateSettings: async (s) => {
await invoke('update_settings', { settings: s });
set({ settings: s });
},
}));
|