aboutsummaryrefslogtreecommitdiff
path: root/desktop/src/lib/commands.ts
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-06-13 20:15:51 +0530
committerRanXom <saiyedshizain@gmail.com>2026-06-13 20:15:51 +0530
commita8f378220f7f59320528cf983c09ad8887473892 (patch)
treecf6d3ad65110921cf64ddcab66d499c9b535c4ad /desktop/src/lib/commands.ts
parent8895c648074e74edb7712778c10499c87bf4713a (diff)
downloadpomoru-a8f378220f7f59320528cf983c09ad8887473892.tar.xz
pomoru-a8f378220f7f59320528cf983c09ad8887473892.zip
create required hooks for timeer and tasks and centralize all commands
Diffstat (limited to 'desktop/src/lib/commands.ts')
-rw-r--r--desktop/src/lib/commands.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/desktop/src/lib/commands.ts b/desktop/src/lib/commands.ts
new file mode 100644
index 0000000..687f3ff
--- /dev/null
+++ b/desktop/src/lib/commands.ts
@@ -0,0 +1,69 @@
+import { invoke } from "@tauri-apps/api/core";
+
+// --- Types ---
+
+export interface TimerState {
+ mode: "work" | "short-break" | "long-break";
+ work_time_secs: number;
+ short_break_secs: number;
+ long_break_secs: number;
+ time_remaining_secs: number;
+ total_duration_secs: number;
+ is_running: boolean;
+ auto_switch_sessions: boolean;
+ break_count: number;
+}
+
+export interface Task {
+ title: string;
+ is_done: boolean;
+}
+
+export interface TimerEvent {
+ title: string;
+ message: string;
+}
+
+export interface AppSnapshot {
+ timer: TimerState;
+ tasks: Task[];
+ selected_task: number | null;
+ active_task_title: string | null;
+}
+
+export interface TickResult {
+ timer: TimerState;
+ event: TimerEvent | null;
+}
+
+export interface ThemeColors {
+ primary: string;
+ overlay0: string;
+ surface0: string;
+ text: string;
+}
+
+// --- Commands ---
+
+export const commands = {
+ getState: () => invoke<AppSnapshot>("get_state"),
+ tick: () => invoke<TickResult>("tick"),
+ startTimer: () => invoke<void>("start_timer"),
+ pauseTimer: () => invoke<void>("pause_timer"),
+ toggleTimer: () => invoke<void>("toggle_timer"),
+ resetTimer: () => invoke<void>("reset_timer"),
+ skipSession: () => invoke<void>("skip_session"),
+ cycleMode: () => invoke<void>("cycle_mode"),
+ toggleAutoSwitch: () => invoke<void>("toggle_auto_switch"),
+ setDuration: (mins: number) => invoke<void>("set_duration", { mins }),
+ getTasks: () => invoke<Task[]>("get_tasks"),
+ addTask: (title: string) => invoke<void>("add_task", { title }),
+ editTask: (index: number, title: string) => invoke<void>("edit_task", { index, title }),
+ deleteTask: (index: number) => invoke<void>("delete_task", { index }),
+ toggleTask: (index: number) => invoke<void>("toggle_task", { index }),
+ reorderTask: (index: number, direction: "up" | "down") =>
+ invoke<void>("reorder_task", { index, direction }),
+ moveTask: (from: number, to: number) => invoke<void>("move_task", { from, to }),
+ saveConfig: () => invoke<void>("save_config"),
+ getTheme: () => invoke<ThemeColors>("get_theme"),
+};