Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

UI v2 (#103)

CJ Paisd6684ccb2128
diff --git a/bun.lockb b/bun.lockb
index 8fbc20a5..2e86f7ef 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/package.json b/package.json
index b9db1bfd..5ac94dd7 100644
--- a/package.json
+++ b/package.json
@@ -23,12 +23,14 @@
"@tauri-apps/plugin-stronghold": "~2",
"@tauri-apps/plugin-updater": "~2",
"@tauri-apps/plugin-upload": "~2",
+ "lucide-react": "^0.542.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sonner": "^2.0.7",
"tailwindcss": "^4.0.2",
"tauri-plugin-macos-permissions-api": "^2.0.4",
- "zod": "^3.24.4"
+ "zod": "^3.24.4",
+ "zustand": "^5.0.8"
},
"devDependencies": {
"@tauri-apps/cli": "^2",
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index f0735228..904664e7 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -14,10 +14,10 @@
"windows": [
{
"title": "Handy",
- "width": 540,
- "height": 740,
- "minWidth": 540,
- "minHeight": 740,
+ "width": 680,
+ "height": 510,
+ "minWidth": 680,
+ "minHeight": 510,
"resizable": true,
"maximizable": false
}
diff --git a/src/App.tsx b/src/App.tsx
index e62631c0..b2c62fb9 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -6,15 +6,50 @@ import AccessibilityPermissions from "./components/AccessibilityPermissions";
import Footer from "./components/footer";
import HandyTextLogo from "./components/icons/HandyTextLogo";
import Onboarding from "./components/onboarding";
-import { Settings } from "./components/settings/Settings";
+import { Sidebar, SidebarSection, SECTIONS_CONFIG } from "./components/Sidebar";
+import { useSettings } from "./hooks/useSettings";
+
+const renderSettingsContent = (section: SidebarSection) => {
+ const ActiveComponent =
+ SECTIONS_CONFIG[section]?.component || SECTIONS_CONFIG.general.component;
+ return <ActiveComponent />;
+};
function App() {
const [showOnboarding, setShowOnboarding] = useState<boolean | null>(null);
+ const [currentSection, setCurrentSection] =
+ useState<SidebarSection>("general");
+ const { settings, updateSetting } = useSettings();
useEffect(() => {
checkOnboardingStatus();
}, []);
+ // Handle keyboard shortcuts for debug mode toggle
+ useEffect(() => {
+ const handleKeyDown = (event: KeyboardEvent) => {
+ // Check for Ctrl+Shift+D (Windows/Linux) or Cmd+Shift+D (macOS)
+ const isDebugShortcut =
+ event.shiftKey &&
+ event.key.toLowerCase() === "d" &&
+ (event.ctrlKey || event.metaKey);
+
+ if (isDebugShortcut) {
+ event.preventDefault();
+ const currentDebugMode = settings?.debug_mode ?? false;
+ updateSetting("debug_mode", !currentDebugMode);
+ }
+ };
+
+ // Add event listener when component mounts
+ document.addEventListener("keydown", handleKeyDown);
+
+ // Cleanup event listener when component unmounts
+ return () => {
+ document.removeEventListener("keydown", handleKeyDown);
+ };
+ }, [settings?.debug_mode, updateSetting]);
+
const checkOnboardingStatus = async () => {
try {
// Always check if they have any models available
@@ -33,23 +68,36 @@ function App() {
if (showOnboarding) {
return (
- <div className="min-h-screen flex flex-col w-full">
- <div className="flex flex-col items-center p-4 gap-4 flex-1">
+ <div className="h-screen flex flex-col">
+ <div className="flex-1 flex flex-col items-center justify-center p-4 gap-4">
<HandyTextLogo width={200} />
<Onboarding onModelSelected={handleModelSelected} />
</div>
+ <Footer />
</div>
);
}
return (
- <div className="min-h-screen flex flex-col w-full">
+ <div className="h-screen flex flex-col">
<Toaster />
- <div className="flex flex-col items-center p-4 gap-4 flex-1">
- <HandyTextLogo width={200} />
- <AccessibilityPermissions />
- <Settings />
+ {/* Main content area that takes remaining space */}
+ <div className="flex-1 flex overflow-hidden">
+ <Sidebar
+ activeSection={currentSection}
+ onSectionChange={setCurrentSection}
+ />
+ {/* Scrollable content area */}
+ <div className="flex-1 flex flex-col overflow-hidden">
+ <div className="flex-1 overflow-y-auto">
+ <div className="flex flex-col items-center p-4 gap-4">
+ <AccessibilityPermissions />
+ {renderSettingsContent(currentSection)}
+ </div>
+ </div>
+ </div>
</div>
+ {/* Fixed footer at bottom */}
<Footer />
</div>
);
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
new file mode 100644
index 00000000..5ae0d59b
--- /dev/null
+++ b/src/components/Sidebar.tsx
@@ -0,0 +1,105 @@
+import React from "react";
+import { Cog, FlaskConical, History, Info } from "lucide-react";
+import HandyTextLogo from "./icons/HandyTextLogo";
+import HandyHand from "./icons/HandyHand";
+import { useSettings } from "../hooks/useSettings";
+import {
+ GeneralSettings,
+ AdvancedSettings,
+ HistorySettings,
+ DebugSettings,
+ AboutSettings,
+} from "./settings";
+
+export type SidebarSection = keyof typeof SECTIONS_CONFIG;
+
+interface IconProps {
+ width?: number | string;
+ height?: number | string;
+ size?: number | string;
+ className?: string;
+ [key: string]: any;
+}
+
+interface SectionConfig {
+ label: string;
+ icon: React.ComponentType<IconProps>;
+ component: React.ComponentType;
+ enabled: (settings: any) => boolean;
+}
+
+export const SECTIONS_CONFIG = {
+ general: {
+ label: "General",
+ icon: HandyHand,
+ component: GeneralSettings,
+ enabled: () => true,
+ },
+ advanced: {
+ label: "Advanced",
+ icon: Cog,
+ component: AdvancedSettings,
+ enabled: () => true,
+ },
+ // history: {
+ // label: "History",
+ // icon: History,
+ // component: HistorySettings,
+ // enabled: () => true,
+ // },
+ debug: {
+ label: "Debug",
+ icon: FlaskConical,
+ component: DebugSettings,
+ enabled: (settings) => settings?.debug_mode ?? false,
+ },
+ about: {
+ label: "About",
+ icon: Info,
+ component: AboutSettings,
+ enabled: () => true,
+ },
+} as const satisfies Record<string, SectionConfig>;
+
+interface SidebarProps {
+ activeSection: SidebarSection;
+ onSectionChange: (section: SidebarSection) => void;
+}
+
+export const Sidebar: React.FC<SidebarProps> = ({
+ activeSection,
+ onSectionChange,
+}) => {
+ const { settings } = useSettings();
+
+ const availableSections = Object.entries(SECTIONS_CONFIG)
+ .filter(([_, config]) => config.enabled(settings))
+ .map(([id, config]) => ({ id: id as SidebarSection, ...config }));
+
+ return (
+ <div className="flex flex-col w-40 h-full border-r border-mid-gray/20 items-center px-2">
+ <HandyTextLogo width={120} className="m-4" />
+ <div className="flex flex-col w-full items-center gap-1 pt-2 border-t border-mid-gray/20">
+ {availableSections.map((section) => {
+ const Icon = section.icon;
+ const isActive = activeSection === section.id;
+
+ return (
+ <div
+ key={section.id}
+ className={`flex gap-2 items-center p-2 w-full rounded-lg cursor-pointer transition-colors ${
+ isActive
+ ? "bg-logo-primary/80"
+ : "hover:bg-mid-gray/20 hover:opacity-100 opacity-85"
+ }`}
+ onClick={() => onSectionChange(section.id)}
+ >
+ <Icon width={24} height={24} />
+ <p className="text-sm font-medium">{section.label}</p>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ );
+};
diff --git a/src/components/footer/Footer.tsx b/src/components/footer/Footer.tsx
index 3022dfdd..b901a048 100644
--- a/src/components/footer/Footer.tsx
+++ b/src/components/footer/Footer.tsx
@@ -22,7 +22,7 @@ const Footer: React.FC = () => {
}, []);
return (
- <div className="w-full border-t border-mid-gray/20 mt-4 pt-3">
+ <div className="w-full border-t border-mid-gray/20 pt-3">
<div className="flex justify-between items-center text-xs px-4 pb-3 text-text/60">
<div className="flex items-center gap-4">
<ModelSelector />
diff --git a/src/components/icons/HandyHand.tsx b/src/components/icons/HandyHand.tsx
new file mode 100644
index 00000000..fc115b63
--- /dev/null
+++ b/src/components/icons/HandyHand.tsx
@@ -0,0 +1,24 @@
+const HandyHand = ({
+ width,
+ height,
+}: {
+ width?: number | string;
+ height?: number | string;
+}) => (
+ <svg
+ width={width || 126}
+ height={height || 135}
+ viewBox="0 0 126 135"
+ className="fill-text stroke-text"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M59.037 128.521c-1.917-.168-4.593-.512-5.947-.766a83 83 0 0 1-5.164-1.192c-1.486-.402-3.495-1.032-4.465-1.4-.97-.369-2.695-1.149-3.833-1.734s-2.7-1.562-3.472-2.171-1.995-1.859-2.72-2.779c-.723-.92-1.547-2.199-1.831-2.842s-.621-1.904-.75-2.802c-.189-1.316-.173-1.972.083-3.384.214-1.18.57-2.28 1.093-3.37.54-1.129.74-1.756.66-2.07-.063-.248-.714-1.021-1.447-1.718s-2.017-2.176-2.853-3.286c-1.112-1.477-2.206-3.376-4.082-7.088-1.41-2.789-3.192-6.138-3.96-7.444a108 108 0 0 0-3.107-4.883c-.94-1.38-2.437-3.498-3.327-4.707A98 98 0 0 1 10.78 70.3c-1.033-1.626-1.784-3.122-2.36-4.696-.464-1.27-.914-2.818-1-3.44a27 27 0 0 1-.194-2.486c-.022-.84.093-1.859.301-2.676.185-.726.601-1.911.925-2.635.323-.723 1.077-1.904 1.675-2.623s1.627-1.727 2.286-2.24c.659-.51 1.698-1.185 2.308-1.497s1.694-.766 2.408-1.008c.714-.243 1.997-.524 2.85-.625.852-.101 2.266-.102 3.14-.001s2.157.365 2.85.588c.692.223 2.103.948 3.136 1.612s2.41 1.76 3.06 2.435c.651.676 1.578 1.803 2.06 2.505a70 70 0 0 1 2.028 3.22c.904 1.528 1.255 1.955 1.641 2 .449.05.497-.016.546-.743.029-.439-.417-2.99-.992-5.668-.574-2.678-1.587-6.822-2.252-9.21s-1.764-6.297-2.442-8.687c-.68-2.39-1.555-5.8-1.946-7.578s-.814-4.186-.94-5.35c-.177-1.641-.16-2.707.073-4.74.215-1.869.448-3.002.81-3.94.279-.723.778-1.736 1.11-2.251s1.044-1.4 1.582-1.964c.54-.566 1.466-1.33 2.06-1.7.593-.368 1.56-.854 2.148-1.08a20 20 0 0 1 2.245-.676c.646-.147 1.833-.293 2.636-.325.817-.033 2.418.1 3.632.299 1.505.247 2.536.533 3.357.933.652.317 1.68.983 2.284 1.48.603.496 1.43 1.33 1.836 1.853.406.524 1.085 1.641 1.51 2.485.424.843 1.012 2.359 1.307 3.368.294 1.01.712 2.988.928 4.396s.524 4.118.684 6.024.441 5.016.624 6.911c.182 1.895.51 4.689.727 6.207.218 1.519.582 3.48.809 4.358.227.879.636 1.899.908 2.267.371.502.672.69 1.195.75.567.066.841-.051 1.453-.62.415-.385.955-1.115 1.2-1.622s.707-1.616 1.025-2.466c.32-.849 1-3.215 1.513-5.257a451 451 0 0 0 1.766-7.339c.458-1.994 1.134-4.677 1.501-5.963.368-1.285.941-3.075 1.274-3.977s.953-2.307 1.378-3.122c.424-.816 1.281-2.083 1.904-2.817.624-.734 1.582-1.662 2.13-2.062s1.589-1.02 2.313-1.378 1.914-.763 2.645-.9c.73-.137 2.174-.255 3.21-.264 1.412-.01 2.274.088 3.456.396.867.226 2.18.702 2.917 1.057.737.356 1.802 1 2.366 1.432s1.47 1.336 2.015 2.008c.545.673 1.22 1.812 1.503 2.533s.59 1.75.683 2.289c.093.538.175 1.7.182 2.583.008 1.007-.148 2.412-.42 3.774a57 57 0 0 1-1.1 4.381c-.367 1.217-1.3 3.871-2.072 5.898s-2.074 5.416-2.892 7.531c-.818 2.116-1.9 5.152-2.403 6.748-.576 1.825-.988 3.539-1.113 4.623-.17 1.485-.148 1.78.167 2.139.355.404.383.407 1.104.12.406-.162 1.18-.76 1.718-1.327s1.466-1.688 2.063-2.49 1.867-2.547 2.823-3.875c.955-1.329 2.203-2.939 2.773-3.578s1.49-1.568 2.045-2.065a24 24 0 0 1 2.124-1.656c.614-.414 1.871-1.024 2.794-1.356.933-.336 2.385-.665 3.269-.74 1.304-.111 1.852-.066 3.042.253.798.214 1.939.627 2.536.917s1.501.882 2.008 1.315a15.6 15.6 0 0 1 1.696 1.755 14 14 0 0 1 1.341 2.119c.314.634.694 1.673.846 2.31.179.75.229 1.846.142 3.122-.096 1.398-.269 2.326-.601 3.219-.257.69-.964 2.026-1.571 2.968s-1.851 2.502-2.765 3.463a201 201 0 0 1-4.115 4.154c-1.35 1.323-2.931 2.968-3.513 3.656s-1.35 1.855-1.706 2.594-.89 2.367-1.186 3.62-.825 4.327-1.174 6.832-.823 5.392-1.053 6.416a81 81 0 0 1-.95 3.713c-.292 1.018-.959 2.882-1.483 4.144-.525 1.26-1.473 3.213-2.108 4.338s-1.701 2.749-2.37 3.608c-.667.86-1.928 2.257-2.8 3.106s-1.8 1.83-2.06 2.18c-.476.636-.476.636-.04 1.771.24.623.515 1.575.612 2.114.097.542.083 1.789-.032 2.792-.115.997-.405 2.33-.646 2.962-.24.631-.84 1.781-1.334 2.554-.689 1.078-1.34 1.753-2.795 2.897-1.16.912-2.566 1.791-3.616 2.26a37 37 0 0 1-3.67 1.356c-1.072.324-3.068.761-4.436.972a59 59 0 0 1-4.993.508c-1.378.069-3.817.107-5.419.086s-4.48-.176-6.397-.343Zm.715-2.726c2.899.29 6.13.53 7.18.533 1.051.003 3.193-.123 4.76-.279s3.803-.48 4.97-.719 2.904-.697 3.862-1.019 2.308-.882 3-1.246 1.872-1.17 2.621-1.792c.749-.621 1.65-1.568 2.004-2.103.353-.535.834-1.469 1.069-2.076.234-.606.478-1.553.54-2.104.063-.55.06-1.343-.006-1.762s-.323-1.068-.57-1.441c-.385-.581-.556-.679-1.172-.673-.398.004-1.905.453-3.35.998-1.447.545-3.695 1.205-4.997 1.467a82 82 0 0 1-4.309.733 61 61 0 0 1-3.864.363c-1.057.058-3.362.088-5.12.065-2.526-.031-4.264-.19-8.262-.754-2.785-.393-5.723-.882-6.529-1.088s-2.544-.728-3.861-1.159-3.313-1.187-4.434-1.678-3.19-1.496-4.6-2.233c-1.66-.869-2.728-1.319-3.036-1.278-.31.04-.641.347-.958.885-.265.453-.597 1.339-.736 1.97-.139.63-.215 1.694-.17 2.363.046.669.285 1.785.532 2.48.25.702.902 1.84 1.466 2.558.56.712 1.497 1.707 2.083 2.212a20 20 0 0 0 2.227 1.629c.639.391 1.923 1.027 2.854 1.415.93.387 2.538.976 3.57 1.309 1.034.333 2.761.805 3.84 1.049s2.447.534 3.043.645 3.455.44 6.353.73Zm-.352-14.434c1.472.183 4.027.396 5.676.473s3.883.109 4.963.071c1.08-.037 3.05-.17 4.377-.294 1.328-.125 3.288-.41 4.355-.633a65 65 0 0 0 4.128-1.05c1.202-.355 2.582-.841 3.067-1.08.484-.24 1.849-1.14 3.031-1.999s2.732-2.144 3.443-2.853c.71-.708 1.832-2.028 2.491-2.932.66-.903 1.63-2.447 2.156-3.43.526-.982 1.384-2.92 1.907-4.306.522-1.386 1.205-3.442 1.517-4.568.375-1.353.882-4.277 1.496-8.63.676-4.787 1.071-7.02 1.448-8.18a23 23 0 0 1 1.272-3.019c.414-.784 1.3-2.056 1.969-2.826.668-.771 2.641-2.786 4.384-4.477s3.78-3.837 4.527-4.767c.843-1.051 1.623-2.294 2.06-3.282.602-1.36.723-1.862.836-3.456.114-1.604.064-2.058-.36-3.243a7.9 7.9 0 0 0-1.465-2.498c-.589-.676-1.405-1.342-2.065-1.682-.6-.31-1.639-.726-2.308-.924-.913-.27-1.576-.34-2.664-.28-.824.046-1.979.29-2.682.566-.734.29-1.847 1-2.75 1.755-.835.698-2.205 2.089-3.046 3.091-.842 1.002-2.306 2.91-3.256 4.239s-2.209 3.028-2.799 3.775-1.685 1.88-2.434 2.517-1.737 1.28-2.197 1.43c-.46.148-1.174.233-1.587.188s-1.03-.237-1.368-.427c-.34-.19-.812-.64-1.05-1a6 6 0 0 1-.64-1.357c-.143-.489-.117-1.404.083-2.985.23-1.813.514-2.94 1.39-5.508.607-1.776 1.933-5.29 2.947-7.808a471 471 0 0 0 2.974-7.568c.62-1.644 1.431-4.026 1.801-5.295.426-1.459.774-3.192.948-4.719.157-1.376.21-2.852.124-3.435a11.6 11.6 0 0 0-.502-1.96c-.193-.515-.811-1.516-1.374-2.225-.634-.8-1.473-1.567-2.207-2.02a17 17 0 0 0-2.462-1.204c-.935-.348-1.882-.523-3.545-.652-2.026-.159-2.444-.126-3.917.309-1.27.375-2.014.76-3.237 1.681-1.182.89-1.808 1.542-2.45 2.552-.475.747-1.123 1.965-1.44 2.71-.316.743-.866 2.354-1.221 3.58a126 126 0 0 0-1.256 4.774c-.335 1.4-.995 4.311-1.466 6.47s-1.167 5.004-1.545 6.323c-.379 1.319-.945 3.064-1.26 3.878-.314.814-.91 2.042-1.325 2.73-.415.686-1.058 1.54-1.428 1.897s-1.11.842-1.645 1.078c-.697.307-1.233.395-1.893.309-.513-.067-1.248-.34-1.658-.614-.405-.271-1.027-.874-1.384-1.34-.356-.465-.887-1.573-1.18-2.462s-.714-2.794-.937-4.232-.557-4.442-.742-6.676-.499-5.839-.697-8.011-.547-5.064-.774-6.426c-.228-1.361-.749-3.451-1.159-4.643-.618-1.801-.96-2.437-2.022-3.766-1.078-1.35-1.5-1.713-2.702-2.327-1.063-.542-1.908-.809-3.325-1.048-1.368-.23-2.328-.275-3.43-.16-.843.089-2.272.42-3.178.738-.905.318-2.163.946-2.794 1.396a7.2 7.2 0 0 0-1.88 1.987c-.402.642-.911 1.799-1.131 2.57-.255.892-.439 2.17-.506 3.516-.064 1.274.024 3.046.22 4.463.18 1.293.773 4.092 1.32 6.222.545 2.13 1.474 5.557 2.064 7.616.59 2.06 1.51 5.424 2.046 7.477s1.408 5.802 1.938 8.331 1.138 5.84 1.35 7.357c.277 1.995.335 3.185.207 4.295-.097.845-.373 2.046-.614 2.668s-.779 1.625-1.194 2.228c-.416.602-1.156 1.456-1.645 1.897s-1.192.98-1.563 1.197c-.37.216-.878.43-1.126.475-.316.058-.563-.058-.821-.383-.26-.328-.315-.59-.183-.886.102-.231.668-.865 1.257-1.407s1.309-1.3 1.6-1.685c.372-.493.52-.894.498-1.36-.017-.362-.603-1.806-1.303-3.208s-1.8-3.51-2.448-4.683-1.806-2.949-2.577-3.944-1.89-2.205-2.488-2.688-1.566-1.118-2.151-1.41c-.686-.343-1.745-.643-2.978-.843-1.357-.22-2.363-.263-3.46-.148-.851.09-2.306.439-3.233.777a13.4 13.4 0 0 0-3.12 1.677c-.788.584-1.73 1.403-2.093 1.819s-.907 1.283-1.21 1.927c-.372.791-.607 1.673-.725 2.717-.096.85-.112 2.05-.036 2.667s.296 1.645.489 2.284.63 1.795.973 2.57 1.131 2.186 1.752 3.137c.62.95 2.34 3.394 3.821 5.43 1.48 2.036 3.31 4.642 4.066 5.793a75 75 0 0 1 2.588 4.314c.668 1.223 2.177 4.141 3.352 6.485 1.733 3.456 2.488 4.716 3.995 6.666 1.022 1.322 2.501 3.017 3.288 3.766s2.283 1.899 3.327 2.556a62 62 0 0 0 3.605 2.083c.94.489 2.614 1.274 3.722 1.746 1.108.471 2.624 1.058 3.37 1.305s2.238.66 3.314.917 2.665.615 3.53.795 2.776.478 4.249.662Z"
+ strokeWidth="6"
+ />
+ </svg>
+);
+
+export default HandyHand;
diff --git a/src/components/icons/HandyTextLogo.tsx b/src/components/icons/HandyTextLogo.tsx
index fc41bd57..008f89b2 100644
--- a/src/components/icons/HandyTextLogo.tsx
+++ b/src/components/icons/HandyTextLogo.tsx
@@ -3,14 +3,17 @@ import React from "react";
const HandyTextLogo = ({
width,
height,
+ className,
}: {
width?: number;
height?: number;
+ className?: string;
}) => {
return (
<svg
width={width}
height={height}
+ className={className}
viewBox="0 0 930 328"
fill="none"
xmlns="http://www.w3.org/2000/svg"
diff --git a/src/components/settings/AboutSettings.tsx b/src/components/settings/AboutSettings.tsx
new file mode 100644
index 00000000..c0b3ac8b
--- /dev/null
+++ b/src/components/settings/AboutSettings.tsx
@@ -0,0 +1,70 @@
+import React, { useState, useEffect } from "react";
+import { getVersion } from "@tauri-apps/api/app";
+import { openUrl } from "@tauri-apps/plugin-opener";
+import { SettingsGroup } from "../ui/SettingsGroup";
+import { SettingContainer } from "../ui/SettingContainer";
+import { Button } from "../ui/Button";
+
+export const AboutSettings: React.FC = () => {
+ const [version, setVersion] = useState("");
+
+ useEffect(() => {
+ const fetchVersion = async () => {
+ try {
+ const appVersion = await getVersion();
+ setVersion(appVersion);
+ } catch (error) {
+ console.error("Failed to get app version:", error);
+ setVersion("0.1.2");
+ }
+ };
+
+ fetchVersion();
+ }, []);
+
+ const handleDonateClick = async () => {
+ try {
+ await openUrl("https://handy.computer/donate");
+ } catch (error) {
+ console.error("Failed to open donate link:", error);
+ }
+ };
+
+ return (
+ <div className="max-w-3xl w-full mx-auto space-y-6">
+ <SettingsGroup title="About">
+ <SettingContainer
+ title="Version"
+ description="Current version of Handy"
+ grouped={true}
+ >
+ <span className="text-sm font-mono">v{version}</span>
+ </SettingContainer>
+
+ <SettingContainer
+ title="Support Development"
+ description="Help us continue building Handy"
+ grouped={true}
+ >
+ <Button variant="primary" size="md" onClick={handleDonateClick}>
+ Donate
+ </Button>
+ </SettingContainer>
+ </SettingsGroup>
+
+ <SettingsGroup title="Acknowledgments">
+ <SettingContainer
+ title="Whisper.cpp"
+ description="High-performance inference of OpenAI's Whisper automatic speech recognition model"
+ grouped={true}
+ layout="stacked"
+ >
+ <div className="text-sm text-mid-gray">
+ Handy uses Whisper.cpp for fast, local speech-to-text processing.
+ Thanks to the amazing work by Georgi Gerganov and contributors.
+ </div>
+ </SettingContainer>
+ </SettingsGroup>
+ </div>
+ );
+};
diff --git a/src/components/settings/AdvancedSettings.tsx b/src/components/settings/AdvancedSettings.tsx
new file mode 100644
index 00000000..2ca6c817
--- /dev/null
+++ b/src/components/settings/AdvancedSettings.tsx
@@ -0,0 +1,21 @@
+import React from "react";
+import { ShowOverlay } from "./ShowOverlay";
+import { TranslateToEnglish } from "./TranslateToEnglish";
+import { ModelUnloadTimeoutSetting } from "./ModelUnloadTimeout";
+import { CustomWords } from "./CustomWords";
+import { AlwaysOnMicrophone } from "./AlwaysOnMicrophone";
+import { SettingsGroup } from "../ui/SettingsGroup";
+
+export const AdvancedSettings: React.FC = () => {
+ return (
+ <div className="max-w-3xl w-full mx-auto space-y-6">
+ <SettingsGroup title="Advanced">
+ <ShowOverlay descriptionMode="tooltip" grouped={true} />
+ <TranslateToEnglish descriptionMode="tooltip" grouped={true} />
+ <ModelUnloadTimeoutSetting descriptionMode="tooltip" grouped={true} />
+ <CustomWords descriptionMode="tooltip" grouped />
+ <AlwaysOnMicrophone descriptionMode="tooltip" grouped={true} />
+ </SettingsGroup>
+ </div>
+ );
+};
diff --git a/src/components/settings/AudioFeedback.tsx b/src/components/settings/AudioFeedback.tsx
index 36524c11..7aeb53d5 100644
--- a/src/components/settings/AudioFeedback.tsx
+++ b/src/components/settings/AudioFeedback.tsx
@@ -15,15 +15,16 @@ export const AudioFeedback: React.FC<AudioFeedbackProps> = React.memo(({
const audioFeedbackEnabled = getSetting("audio_feedback") || false;
- return (
- <ToggleSwitch
- checked={audioFeedbackEnabled}
- onChange={(enabled) => updateSetting("audio_feedback", enabled)}
- isUpdating={isUpdating("audio_feedback")}
- label="Audio Feedback"
- description="Play sound when recording starts and stops"
- descriptionMode={descriptionMode}
- grouped={grouped}
- />
- );
-});
+ return (
+ <ToggleSwitch
+ checked={audioFeedbackEnabled}
+ onChange={(enabled) => updateSetting("audio_feedback", enabled)}
+ isUpdating={isUpdating("audio_feedback")}
+ label="Audio Feedback"
+ description="Play sound when recording starts and stops"
+ descriptionMode={descriptionMode}
+ grouped={grouped}
+ />
+ );
+ },
+);
diff --git a/src/components/settings/DebugSettings.tsx b/src/components/settings/DebugSettings.tsx
new file mode 100644
index 00000000..55ae57dd
--- /dev/null
+++ b/src/components/settings/DebugSettings.tsx
@@ -0,0 +1,15 @@
+import React from "react";
+import { WordCorrectionThreshold } from "./debug/WordCorrectionThreshold";
+import { AppDataDirectory } from "./AppDataDirectory";
+import { SettingsGroup } from "../ui/SettingsGroup";
+
+export const DebugSettings: React.FC = () => {
+ return (
+ <div className="max-w-3xl w-full mx-auto space-y-6">
+ <SettingsGroup title="Debug">
+ <WordCorrectionThreshold descriptionMode="tooltip" grouped={true} />
+ <AppDataDirectory descriptionMode="tooltip" grouped={true} />
+ </SettingsGroup>
+ </div>
+ );
+};
diff --git a/src/components/settings/GeneralSettings.tsx b/src/components/settings/GeneralSettings.tsx
new file mode 100644
index 00000000..5ff6af66
--- /dev/null
+++ b/src/components/settings/GeneralSettings.tsx
@@ -0,0 +1,31 @@
+import React from "react";
+import { MicrophoneSelector } from "./MicrophoneSelector";
+import { LanguageSelector } from "./LanguageSelector";
+import { HandyShortcut } from "./HandyShortcut";
+import { SettingsGroup } from "../ui/SettingsGroup";
+import { OutputDeviceSelector } from "./OutputDeviceSelector";
+import { PushToTalk } from "./PushToTalk";
+import { AudioFeedback } from "./AudioFeedback";
+import { useSettings } from "../../hooks/useSettings";
+
+export const GeneralSettings: React.FC = () => {
+ const { audioFeedbackEnabled } = useSettings();
+ return (
+ <div className="max-w-3xl w-full mx-auto space-y-6">
+ <SettingsGroup title="General">
+ <HandyShortcut descriptionMode="tooltip" grouped={true} />
+ <LanguageSelector descriptionMode="tooltip" grouped={true} />
+ <PushToTalk descriptionMode="tooltip" grouped={true} />
+ </SettingsGroup>
+ <SettingsGroup title="Sound">
+ <MicrophoneSelector descriptionMode="tooltip" grouped={true} />
+ <AudioFeedback descriptionMode="tooltip" grouped={true} />
+ <OutputDeviceSelector
+ descriptionMode="tooltip"
+ grouped={true}
+ disabled={!audioFeedbackEnabled}
+ />
+ </SettingsGroup>
+ </div>
+ );
+};
diff --git a/src/components/settings/HistorySettings.tsx b/src/components/settings/HistorySettings.tsx
new file mode 100644
index 00000000..87fbad09
--- /dev/null
+++ b/src/components/settings/HistorySettings.tsx
@@ -0,0 +1,12 @@
+import React from "react";
+import { SettingsGroup } from "../ui/SettingsGroup";
+
+export const HistorySettings: React.FC = () => {
+ return (
+ <div className="max-w-3xl w-full mx-auto space-y-6">
+ <SettingsGroup title="History">
+ <></>
+ </SettingsGroup>
+ </div>
+ );
+};
diff --git a/src/components/settings/OutputDeviceSelector.tsx b/src/components/settings/OutputDeviceSelector.tsx
index b0efd703..9613fd51 100644
--- a/src/components/settings/OutputDeviceSelector.tsx
+++ b/src/components/settings/OutputDeviceSelector.tsx
@@ -3,62 +3,79 @@ import { Dropdown } from "../ui/Dropdown";
import { SettingContainer } from "../ui/SettingContainer";
import { ResetButton } from "../ui/ResetButton";
import { useSettings } from "../../hooks/useSettings";
+import { AudioDevice } from "../../lib/types";
interface OutputDeviceSelectorProps {
descriptionMode?: "inline" | "tooltip";
grouped?: boolean;
+ disabled?: boolean;
}
-export const OutputDeviceSelector: React.FC<OutputDeviceSelectorProps> = React.memo(({
- descriptionMode = "tooltip",
- grouped = false,
-}) => {
- const {
- getSetting,
- updateSetting,
- resetSetting,
- isUpdating,
- isLoading,
- outputDevices,
- refreshOutputDevices,
- } = useSettings();
+export const OutputDeviceSelector: React.FC<OutputDeviceSelectorProps> =
+ React.memo(
+ ({ descriptionMode = "tooltip", grouped = false, disabled = false }) => {
+ const {
+ getSetting,
+ updateSetting,
+ resetSetting,
+ isUpdating,
+ isLoading,
+ outputDevices,
+ refreshOutputDevices,
+ } = useSettings();
- const selectedOutputDevice = getSetting("selected_output_device") === "default" ? "Default" : getSetting("selected_output_device") || "Default";
+ const selectedOutputDevice =
+ getSetting("selected_output_device") === "default"
+ ? "Default"
+ : getSetting("selected_output_device") || "Default";
- const handleOutputDeviceSelect = async (deviceName: string) => {
- await updateSetting("selected_output_device", deviceName);
- };
+ const handleOutputDeviceSelect = async (deviceName: string) => {
+ await updateSetting("selected_output_device", deviceName);
+ };
- const handleReset = async () => {
- await resetSetting("selected_output_device");
- };
+ const handleReset = async () => {
+ await resetSetting("selected_output_device");
+ };
- const outputDeviceOptions = outputDevices.map(device => ({
- value: device.name,
- label: device.name
- }));
+ const outputDeviceOptions = outputDevices.map((device: AudioDevice) => ({
+ value: device.name,
+ label: device.name,
+ }));
- return (
- <SettingContainer
- title="Output Device"
- description="Select your preferred audio output device for feedback sounds"
- descriptionMode={descriptionMode}
- grouped={grouped}
- >
- <div className="flex items-center space-x-1">
- <Dropdown
- options={outputDeviceOptions}
- selectedValue={selectedOutputDevice}
- onSelect={handleOutputDeviceSelect}
- placeholder={isLoading || outputDevices.length === 0 ? "Loading..." : "Select output device..."}
- disabled={isUpdating("selected_output_device") || isLoading || outputDevices.length === 0}
- onRefresh={refreshOutputDevices}
- />
- <ResetButton
- onClick={handleReset}
- disabled={isUpdating("selected_output_device") || isLoading}
- />
- </div>
- </SettingContainer>
+ return (
+ <SettingContainer
+ title="Output Device"
+ description="Select your preferred audio output device for feedback sounds"
+ descriptionMode={descriptionMode}
+ grouped={grouped}
+ disabled={disabled}
+ >
+ <div className="flex items-center space-x-1">
+ <Dropdown
+ options={outputDeviceOptions}
+ selectedValue={selectedOutputDevice}
+ onSelect={handleOutputDeviceSelect}
+ placeholder={
+ isLoading || outputDevices.length === 0
+ ? "Loading..."
+ : "Select output device..."
+ }
+ disabled={
+ disabled ||
+ isUpdating("selected_output_device") ||
+ isLoading ||
+ outputDevices.length === 0
+ }
+ onRefresh={refreshOutputDevices}
+ />
+ <ResetButton
+ onClick={handleReset}
+ disabled={
+ disabled || isUpdating("selected_output_device") || isLoading
+ }
+ />
+ </div>
+ </SettingContainer>
+ );
+ },
);
-});
diff --git a/src/components/settings/Settings.tsx b/src/components/settings/Settings.tsx
deleted file mode 100644
index db7bb4a0..00000000
--- a/src/components/settings/Settings.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-import React, { useEffect } from "react";
-import { MicrophoneSelector } from "./MicrophoneSelector";
-import { AlwaysOnMicrophone } from "./AlwaysOnMicrophone";
-import { PushToTalk } from "./PushToTalk";
-import { AudioFeedback } from "./AudioFeedback";
-import { OutputDeviceSelector } from "./OutputDeviceSelector";
-import { ShowOverlay } from "./ShowOverlay";
-import { HandyShortcut } from "./HandyShortcut";
-import { TranslateToEnglish } from "./TranslateToEnglish";
-import { LanguageSelector } from "./LanguageSelector";
-import { CustomWords } from "./CustomWords";
-import { ModelUnloadTimeoutSetting } from "./ModelUnloadTimeout";
-import { SettingsGroup } from "../ui/SettingsGroup";
-import { WordCorrectionThreshold } from "./debug/WordCorrectionThreshold";
-import { AppDataDirectory } from "./AppDataDirectory";
-import { useSettings } from "../../hooks/useSettings";
-
-export const Settings: React.FC = () => {
- const { settings, updateSetting } = useSettings();
-
- // Handle keyboard shortcuts for debug mode toggle
- useEffect(() => {
- const handleKeyDown = (event: KeyboardEvent) => {
- // Check for Ctrl+Shift+D (Windows/Linux) or Cmd+Shift+D (macOS)
- const isDebugShortcut =
- event.shiftKey &&
- event.key.toLowerCase() === "d" &&
- (event.ctrlKey || event.metaKey);
-
- if (isDebugShortcut) {
- event.preventDefault();
- const currentDebugMode = settings?.debug_mode ?? false;
- updateSetting("debug_mode", !currentDebugMode);
- }
- };
-
- // Add event listener when component mounts
- document.addEventListener("keydown", handleKeyDown);
-
- // Cleanup event listener when component unmounts
- return () => {
- document.removeEventListener("keydown", handleKeyDown);
- };
- }, [settings?.debug_mode, updateSetting]);
-
- return (
- <div className="max-w-3xl w-full mx-auto space-y-6">
- <SettingsGroup>
- <HandyShortcut descriptionMode="tooltip" grouped={true} />
- <MicrophoneSelector descriptionMode="tooltip" grouped={true} />
- <LanguageSelector descriptionMode="tooltip" grouped={true} />
- </SettingsGroup>
-
- <SettingsGroup title="Advanced">
- <PushToTalk descriptionMode="tooltip" grouped={true} />
- <AudioFeedback descriptionMode="tooltip" grouped={true} />
- <OutputDeviceSelector descriptionMode="tooltip" grouped={true} />
- <ShowOverlay descriptionMode="tooltip" grouped={true} />
- <TranslateToEnglish descriptionMode="tooltip" grouped={true} />
- <ModelUnloadTimeoutSetting descriptionMode="tooltip" grouped={true} />
- <CustomWords descriptionMode="tooltip" grouped />
- <AlwaysOnMicrophone descriptionMode="tooltip" grouped={true} />
- </SettingsGroup>
-
- {settings?.debug_mode && (
- <SettingsGroup title="Debug">
- <WordCorrectionThreshold descriptionMode="tooltip" grouped={true} />
- <AppDataDirectory descriptionMode="tooltip" grouped={true} />
- </SettingsGroup>
- )}
- </div>
- );
-};
diff --git a/src/components/settings/index.ts b/src/components/settings/index.ts
index ec094dea..19c7f69c 100644
--- a/src/components/settings/index.ts
+++ b/src/components/settings/index.ts
@@ -1,4 +1,11 @@
-export { Settings } from "./Settings";
+// Settings section components
+export { GeneralSettings } from "./GeneralSettings";
+export { AdvancedSettings } from "./AdvancedSettings";
+export { DebugSettings } from "./DebugSettings";
+export { HistorySettings } from "./HistorySettings";
+export { AboutSettings } from "./AboutSettings";
+
+// Individual setting components
export { MicrophoneSelector } from "./MicrophoneSelector";
export { OutputDeviceSelector } from "./OutputDeviceSelector";
export { AlwaysOnMicrophone } from "./AlwaysOnMicrophone";
diff --git a/src/components/ui/Button.tsx b/src/components/ui/Button.tsx
index 13462caf..abba8171 100644
--- a/src/components/ui/Button.tsx
+++ b/src/components/ui/Button.tsx
@@ -17,7 +17,7 @@ export const Button: React.FC<ButtonProps> = ({
const variantClasses = {
primary:
- "text-white bg-background-ui hover:bg-background-ui/90 focus:ring-1 focus:ring-background-ui",
+ "text-white bg-background-ui hover:bg-background-ui/80 focus:ring-1 focus:ring-background-ui",
secondary: "bg-mid-gray/10 hover:bg-background-ui/30 focus:outline-none",
danger:
"text-white bg-red-600 hover:bg-red-700 focus:ring-1 focus:ring-red-500",
diff --git a/src/components/ui/ResetButton.tsx b/src/components/ui/ResetButton.tsx
index 4f8a7d38..05328f2d 100644
--- a/src/components/ui/ResetButton.tsx
+++ b/src/components/ui/ResetButton.tsx
@@ -10,7 +10,11 @@ interface ResetButtonProps {
export const ResetButton: React.FC<ResetButtonProps> = React.memo(
({ onClick, disabled = false, className = "" }) => (
<button
- className={`p-1 hover:bg-logo-primary/30 active:bg-logo-primary/50 active:translate-y-[1px] rounded fill-text hover:cursor-pointer hover:border-logo-primary border border-transparent transition-all duration-150 text-text/80 ${className}`}
+ className={`p-1 rounded fill-text border border-transparent transition-all duration-150 ${
+ disabled
+ ? "opacity-50 cursor-not-allowed text-text/40"
+ : "hover:bg-logo-primary/30 active:bg-logo-primary/50 active:translate-y-[1px] hover:cursor-pointer hover:border-logo-primary text-text/80"
+ } ${className}`}
onClick={onClick}
disabled={disabled}
>
diff --git a/src/components/ui/SettingContainer.tsx b/src/components/ui/SettingContainer.tsx
index a50f5988..1a064c71 100644
--- a/src/components/ui/SettingContainer.tsx
+++ b/src/components/ui/SettingContainer.tsx
@@ -7,6 +7,7 @@ interface SettingContainerProps {
descriptionMode?: "inline" | "tooltip";
grouped?: boolean;
layout?: "horizontal" | "stacked";
+ disabled?: boolean;
}
export const SettingContainer: React.FC<SettingContainerProps> = ({
@@ -16,6 +17,7 @@ export const SettingContainer: React.FC<SettingContainerProps> = ({
descriptionMode = "tooltip",
grouped = false,
layout = "horizontal",
+ disabled = false,
}) => {
const [showTooltip, setShowTooltip] = useState(false);
const tooltipRef = useRef<HTMLDivElement>(null);
@@ -51,7 +53,11 @@ export const SettingContainer: React.FC<SettingContainerProps> = ({
return (
<div className={containerClasses}>
<div className="flex items-center gap-2 mb-2">
- <h3 className="text-sm font-medium">{title}</h3>
+ <h3
+ className={`text-sm font-medium ${disabled ? "opacity-50" : ""}`}
+ >
+ {title}
+ </h3>
<div
ref={tooltipRef}
className="relative"
@@ -99,8 +105,12 @@ export const SettingContainer: React.FC<SettingContainerProps> = ({
return (
<div className={containerClasses}>
<div className="mb-2">
- <h3 className="text-sm font-medium">{title}</h3>
- <p className="text-sm">{description}</p>
+ <h3 className={`text-sm font-medium ${disabled ? "opacity-50" : ""}`}>
+ {title}
+ </h3>
+ <p className={`text-sm ${disabled ? "opacity-50" : ""}`}>
+ {description}
+ </p>
</div>
<div className="w-full">{children}</div>
</div>
@@ -117,7 +127,11 @@ export const SettingContainer: React.FC<SettingContainerProps> = ({
<div className={horizontalContainerClasses}>
<div className="max-w-2/3">
<div className="flex items-center gap-2">
- <h3 className="text-sm font-medium ">{title}</h3>
+ <h3
+ className={`text-sm font-medium ${disabled ? "opacity-50" : ""}`}
+ >
+ {title}
+ </h3>
<div
ref={tooltipRef}
className="relative"
@@ -166,8 +180,12 @@ export const SettingContainer: React.FC<SettingContainerProps> = ({
return (
<div className={horizontalContainerClasses}>
<div className="max-w-2/3">
- <h3 className="text-sm font-medium ">{title}</h3>
- <p className="text-sm">{description}</p>
+ <h3 className={`text-sm font-medium ${disabled ? "opacity-50" : ""}`}>
+ {title}
+ </h3>
+ <p className={`text-sm ${disabled ? "opacity-50" : ""}`}>
+ {description}
+ </p>
</div>
<div className="relative">{children}</div>
</div>
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts
index 63ce38b0..2d8d5595 100644
--- a/src/hooks/useSettings.ts
+++ b/src/hooks/useSettings.ts
@@ -1,15 +1,7 @@
-import { useState, useEffect, useCallback } from "react";
-import { invoke } from "@tauri-apps/api/core";
+import { useEffect } from "react";
+import { useSettingsStore } from "../stores/settingsStore";
import { Settings, AudioDevice } from "../lib/types";
-interface SettingsState {
- settings: Settings | null;
- isLoading: boolean;
- isUpdating: Record<string, boolean>;
- audioDevices: AudioDevice[];
- outputDevices: AudioDevice[];
-}
-
interface UseSettingsReturn {
// State
settings: Settings | null;
@@ -17,6 +9,7 @@ interface UseSettingsReturn {
isUpdating: (key: string) => boolean;
audioDevices: AudioDevice[];
outputDevices: AudioDevice[];
+ audioFeedbackEnabled: boolean;
// Actions
updateSetting: <K extends keyof Settings>(
@@ -37,366 +30,29 @@ interface UseSettingsReturn {
}
export const useSettings = (): UseSettingsReturn => {
- const [state, setState] = useState<SettingsState>({
- settings: null,
- isLoading: true,
- isUpdating: {},
- audioDevices: [],
- outputDevices: [],
- });
-
- // Load settings from store
- const loadSettings = useCallback(async () => {
- try {
- const { load } = await import("@tauri-apps/plugin-store");
- const store = await load("settings_store.json", { autoSave: false });
- const settings = (await store.get("settings")) as Settings;
-
- // Load additional settings that come from invoke calls
- const [microphoneMode, selectedMicrophone, selectedOutputDevice] =
- await Promise.allSettled([
- invoke("get_microphone_mode"),
- invoke("get_selected_microphone"),
- invoke("get_selected_output_device"),
- ]);
-
- // Merge all settings
- const mergedSettings: Settings = {
- ...settings,
- always_on_microphone:
- microphoneMode.status === "fulfilled"
- ? (microphoneMode.value as boolean)
- : false,
- selected_microphone:
- selectedMicrophone.status === "fulfilled"
- ? (selectedMicrophone.value as string)
- : "Default",
- selected_output_device:
- selectedOutputDevice.status === "fulfilled"
- ? (selectedOutputDevice.value as string)
- : "Default",
- };
-
- setState((prev) => ({
- ...prev,
- settings: mergedSettings,
- isLoading: false,
- }));
- } catch (error) {
- console.error("Failed to load settings:", error);
- setState((prev) => ({
- ...prev,
- isLoading: false,
- }));
- }
- }, []);
-
- // Load audio devices
- const loadAudioDevices = useCallback(async () => {
- try {
- const devices: AudioDevice[] = await invoke("get_available_microphones");
-
- // Always ensure "Default" is available as the first option
- const devicesWithDefault = [
- { index: "default", name: "Default", is_default: true },
- ...devices.filter((d) => d.name !== "Default" && d.name !== "default"),
- ];
-
- setState((prev) => ({
- ...prev,
- audioDevices: devicesWithDefault,
- }));
- } catch (error) {
- console.error("Failed to load audio devices:", error);
- setState((prev) => ({
- ...prev,
- audioDevices: [{ index: "default", name: "Default", is_default: true }],
- }));
- }
- }, []);
-
- // Load output devices
- const loadOutputDevices = useCallback(async () => {
- try {
- const devices: AudioDevice[] = await invoke(
- "get_available_output_devices",
- );
-
- // Always ensure "Default" is available as the first option
- const devicesWithDefault = [
- { index: "default", name: "Default", is_default: true },
- ...devices.filter((d) => d.name !== "Default" && d.name !== "default"),
- ];
-
- setState((prev) => ({
- ...prev,
- outputDevices: devicesWithDefault,
- }));
- } catch (error) {
- console.error("Failed to load output devices:", error);
- setState((prev) => ({
- ...prev,
- outputDevices: [
- { index: "default", name: "Default", is_default: true },
- ],
- }));
- }
- }, []);
-
- // Update a specific setting
- const updateSetting = useCallback(
- async <K extends keyof Settings>(key: K, value: Settings[K]) => {
- const updateKey = String(key);
-
- // Set updating state
- setState((prev) => ({
- ...prev,
- isUpdating: { ...prev.isUpdating, [updateKey]: true },
- }));
+ const store = useSettingsStore();
- // Store original value for rollback
- const originalValue = state.settings?.[key];
-
- try {
- // Optimistic update
- setState((prev) => ({
- ...prev,
- settings: prev.settings ? { ...prev.settings, [key]: value } : null,
- }));
-
- // Invoke the appropriate backend method based on the setting
- switch (key) {
- case "always_on_microphone":
- await invoke("update_microphone_mode", { alwaysOn: value });
- break;
- case "audio_feedback":
- await invoke("change_audio_feedback_setting", { enabled: value });
- break;
- case "push_to_talk":
- await invoke("change_ptt_setting", { enabled: value });
- break;
- case "selected_microphone":
- // Map "Default" to "default" for backend compatibility
- const micDeviceName = value === "Default" ? "default" : value;
- await invoke("set_selected_microphone", {
- deviceName: micDeviceName,
- });
- break;
- case "selected_output_device":
- // Map "Default" to "default" for backend compatibility
- const outputDeviceName = value === "Default" ? "default" : value;
- await invoke("set_selected_output_device", {
- deviceName: outputDeviceName,
- });
- break;
- case "translate_to_english":
- await invoke("change_translate_to_english_setting", {
- enabled: value,
- });
- break;
- case "selected_language":
- await invoke("change_selected_language_setting", {
- language: value,
- });
- break;
- case "overlay_position":
- await invoke("change_overlay_position_setting", {
- position: value,
- });
- break;
- case "debug_mode":
- await invoke("change_debug_mode_setting", { enabled: value });
- break;
- case "custom_words":
- await invoke("update_custom_words", { words: value });
- break;
- case "word_correction_threshold":
- await invoke("change_word_correction_threshold_setting", {
- threshold: value,
- });
- break;
- case "bindings":
- // Handle bindings separately - they use their own invoke methods
- break;
- case "selected_model":
- // Handle model selection if needed
- break;
- default:
- console.warn(`No handler for setting: ${String(key)}`);
- }
-
- // console.log(`Setting ${String(key)} updated to:`, value);
- } catch (error) {
- console.error(`Failed to update setting ${String(key)}:`, error);
-
- // Rollback on error
- setState((prev) => ({
- ...prev,
- settings: prev.settings
- ? { ...prev.settings, [key]: originalValue }
- : null,
- }));
- } finally {
- // Clear updating state
- setState((prev) => ({
- ...prev,
- isUpdating: { ...prev.isUpdating, [updateKey]: false },
- }));
- }
- },
- [state.settings],
- );
-
- // Reset a setting to its default value
- const resetSetting = useCallback(
- async (key: keyof Settings) => {
- // Define default values
- const defaults: Partial<Settings> = {
- always_on_microphone: false,
- audio_feedback: true,
- push_to_talk: false,
- selected_microphone: "Default",
- selected_output_device: "Default",
- translate_to_english: false,
- selected_language: "auto",
- overlay_position: "bottom",
- debug_mode: false,
- custom_words: [],
- };
-
- const defaultValue = defaults[key];
- if (defaultValue !== undefined) {
- await updateSetting(key, defaultValue as any);
- }
- },
- [updateSetting],
- );
-
- // Convenience getter
- const getSetting = useCallback(
- <K extends keyof Settings>(key: K): Settings[K] | undefined => {
- return state.settings?.[key];
- },
- [state.settings],
- );
-
- // Update a specific binding
- const updateBinding = useCallback(
- async (id: string, binding: string) => {
- const updateKey = `binding_${id}`;
-
- // Set updating state
- setState((prev) => ({
- ...prev,
- isUpdating: { ...prev.isUpdating, [updateKey]: true },
- }));
-
- // Store original binding for rollback
- const originalBinding = state.settings?.bindings?.[id]?.current_binding;
-
- try {
- // Optimistic update
- setState((prev) => ({
- ...prev,
- settings: prev.settings
- ? {
- ...prev.settings,
- bindings: {
- ...prev.settings.bindings,
- [id]: {
- ...prev.settings.bindings[id],
- current_binding: binding,
- },
- },
- }
- : null,
- }));
-
- await invoke("change_binding", { id, binding });
- console.log(`Binding ${id} updated to: ${binding}`);
- } catch (error) {
- console.error(`Failed to update binding ${id}:`, error);
-
- // Rollback on error
- if (originalBinding) {
- setState((prev) => ({
- ...prev,
- settings: prev.settings
- ? {
- ...prev.settings,
- bindings: {
- ...prev.settings.bindings,
- [id]: {
- ...prev.settings.bindings[id],
- current_binding: originalBinding,
- },
- },
- }
- : null,
- }));
- }
- } finally {
- // Clear updating state
- setState((prev) => ({
- ...prev,
- isUpdating: { ...prev.isUpdating, [updateKey]: false },
- }));
- }
- },
- [state.settings],
- );
-
- // Reset a specific binding
- const resetBinding = useCallback(
- async (id: string) => {
- const updateKey = `binding_${id}`;
-
- // Set updating state
- setState((prev) => ({
- ...prev,
- isUpdating: { ...prev.isUpdating, [updateKey]: true },
- }));
-
- try {
- const result = await invoke("reset_binding", { id });
-
- // Refresh settings to get the updated binding
- await loadSettings();
-
- console.log(`Binding ${id} reset to default`);
- } catch (error) {
- console.error(`Failed to reset binding ${id}:`, error);
- } finally {
- // Clear updating state
- setState((prev) => ({
- ...prev,
- isUpdating: { ...prev.isUpdating, [updateKey]: false },
- }));
- }
- },
- [loadSettings],
- );
-
- // Initialize
+ // Initialize on first mount
useEffect(() => {
- loadSettings();
- loadAudioDevices();
- loadOutputDevices();
- }, [loadSettings, loadAudioDevices, loadOutputDevices]);
+ if (store.isLoading) {
+ store.initialize();
+ }
+ }, [store.initialize, store.isLoading]);
return {
- settings: state.settings,
- isLoading: state.isLoading,
- isUpdating: (key: string) => state.isUpdating[key] || false,
- audioDevices: state.audioDevices,
- outputDevices: state.outputDevices,
- updateSetting,
- resetSetting,
- refreshSettings: loadSettings,
- refreshAudioDevices: loadAudioDevices,
- refreshOutputDevices: loadOutputDevices,
- updateBinding,
- resetBinding,
- getSetting,
+ settings: store.settings,
+ isLoading: store.isLoading,
+ isUpdating: store.isUpdatingKey,
+ audioDevices: store.audioDevices,
+ outputDevices: store.outputDevices,
+ audioFeedbackEnabled: store.settings?.audio_feedback || false,
+ updateSetting: store.updateSetting,
+ resetSetting: store.resetSetting,
+ refreshSettings: store.refreshSettings,
+ refreshAudioDevices: store.refreshAudioDevices,
+ refreshOutputDevices: store.refreshOutputDevices,
+ updateBinding: store.updateBinding,
+ resetBinding: store.resetBinding,
+ getSetting: store.getSetting,
};
};
diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.ts
new file mode 100644
index 00000000..f89e2e84
--- /dev/null
+++ b/src/stores/settingsStore.ts
@@ -0,0 +1,300 @@
+import { create } from 'zustand';
+import { subscribeWithSelector } from 'zustand/middleware';
+import { invoke } from '@tauri-apps/api/core';
+import { Settings, AudioDevice } from '../lib/types';
+
+interface SettingsStore {
+ settings: Settings | null;
+ isLoading: boolean;
+ isUpdating: Record<string, boolean>;
+ audioDevices: AudioDevice[];
+ outputDevices: AudioDevice[];
+
+ // Actions
+ initialize: () => Promise<void>;
+ updateSetting: <K extends keyof Settings>(key: K, value: Settings[K]) => Promise<void>;
+ resetSetting: (key: keyof Settings) => Promise<void>;
+ refreshSettings: () => Promise<void>;
+ refreshAudioDevices: () => Promise<void>;
+ refreshOutputDevices: () => Promise<void>;
+ updateBinding: (id: string, binding: string) => Promise<void>;
+ resetBinding: (id: string) => Promise<void>;
+ getSetting: <K extends keyof Settings>(key: K) => Settings[K] | undefined;
+ isUpdatingKey: (key: string) => boolean;
+
+ // Internal state setters
+ setSettings: (settings: Settings | null) => void;
+ setLoading: (loading: boolean) => void;
+ setUpdating: (key: string, updating: boolean) => void;
+ setAudioDevices: (devices: AudioDevice[]) => void;
+ setOutputDevices: (devices: AudioDevice[]) => void;
+}
+
+const DEFAULT_SETTINGS: Partial<Settings> = {
+ always_on_microphone: false,
+ audio_feedback: true,
+ push_to_talk: false,
+ selected_microphone: "Default",
+ selected_output_device: "Default",
+ translate_to_english: false,
+ selected_language: "auto",
+ overlay_position: "bottom",
+ debug_mode: false,
+ custom_words: [],
+};
+
+const DEFAULT_AUDIO_DEVICE: AudioDevice = {
+ index: "default",
+ name: "Default",
+ is_default: true
+};
+
+export const useSettingsStore = create<SettingsStore>()(
+ subscribeWithSelector((set, get) => ({
+ settings: null,
+ isLoading: true,
+ isUpdating: {},
+ audioDevices: [],
+ outputDevices: [],
+
+ // Internal setters
+ setSettings: (settings) => set({ settings }),
+ setLoading: (isLoading) => set({ isLoading }),
+ setUpdating: (key, updating) =>
+ set((state) => ({
+ isUpdating: { ...state.isUpdating, [key]: updating }
+ })),
+ setAudioDevices: (audioDevices) => set({ audioDevices }),
+ setOutputDevices: (outputDevices) => set({ outputDevices }),
+
+ // Getters
+ getSetting: (key) => get().settings?.[key],
+ isUpdatingKey: (key) => get().isUpdating[key] || false,
+
+ // Load settings from store
+ refreshSettings: async () => {
+ try {
+ const { load } = await import("@tauri-apps/plugin-store");
+ const store = await load("settings_store.json", { autoSave: false });
+ const settings = (await store.get("settings")) as Settings;
+
+ // Load additional settings that come from invoke calls
+ const [microphoneMode, selectedMicrophone, selectedOutputDevice] =
+ await Promise.allSettled([
+ invoke("get_microphone_mode"),
+ invoke("get_selected_microphone"),
+ invoke("get_selected_output_device"),
+ ]);
+
+ // Merge all settings
+ const mergedSettings: Settings = {
+ ...settings,
+ always_on_microphone:
+ microphoneMode.status === "fulfilled"
+ ? (microphoneMode.value as boolean)
+ : false,
+ selected_microphone:
+ selectedMicrophone.status === "fulfilled"
+ ? (selectedMicrophone.value as string)
+ : "Default",
+ selected_output_device:
+ selectedOutputDevice.status === "fulfilled"
+ ? (selectedOutputDevice.value as string)
+ : "Default",
+ };
+
+ set({ settings: mergedSettings, isLoading: false });
+ } catch (error) {
+ console.error("Failed to load settings:", error);
+ set({ isLoading: false });
+ }
+ },
+
+ // Load audio devices
+ refreshAudioDevices: async () => {
+ try {
+ const devices: AudioDevice[] = await invoke("get_available_microphones");
+ const devicesWithDefault = [
+ DEFAULT_AUDIO_DEVICE,
+ ...devices.filter((d) => d.name !== "Default" && d.name !== "default"),
+ ];
+ set({ audioDevices: devicesWithDefault });
+ } catch (error) {
+ console.error("Failed to load audio devices:", error);
+ set({ audioDevices: [DEFAULT_AUDIO_DEVICE] });
+ }
+ },
+
+ // Load output devices
+ refreshOutputDevices: async () => {
+ try {
+ const devices: AudioDevice[] = await invoke("get_available_output_devices");
+ const devicesWithDefault = [
+ DEFAULT_AUDIO_DEVICE,
+ ...devices.filter((d) => d.name !== "Default" && d.name !== "default"),
+ ];
+ set({ outputDevices: devicesWithDefault });
+ } catch (error) {
+ console.error("Failed to load output devices:", error);
+ set({ outputDevices: [DEFAULT_AUDIO_DEVICE] });
+ }
+ },
+
+ // Update a specific setting
+ updateSetting: async <K extends keyof Settings>(key: K, value: Settings[K]) => {
+ const { settings, setUpdating, refreshSettings } = get();
+ const updateKey = String(key);
+ const originalValue = settings?.[key];
+
+ setUpdating(updateKey, true);
+
+ try {
+ // Optimistic update
+ set((state) => ({
+ settings: state.settings ? { ...state.settings, [key]: value } : null,
+ }));
+
+ // Invoke the appropriate backend method
+ switch (key) {
+ case "always_on_microphone":
+ await invoke("update_microphone_mode", { alwaysOn: value });
+ break;
+ case "audio_feedback":
+ await invoke("change_audio_feedback_setting", { enabled: value });
+ break;
+ case "push_to_talk":
+ await invoke("change_ptt_setting", { enabled: value });
+ break;
+ case "selected_microphone":
+ const micDeviceName = value === "Default" ? "default" : value;
+ await invoke("set_selected_microphone", { deviceName: micDeviceName });
+ break;
+ case "selected_output_device":
+ const outputDeviceName = value === "Default" ? "default" : value;
+ await invoke("set_selected_output_device", { deviceName: outputDeviceName });
+ break;
+ case "translate_to_english":
+ await invoke("change_translate_to_english_setting", { enabled: value });
+ break;
+ case "selected_language":
+ await invoke("change_selected_language_setting", { language: value });
+ break;
+ case "overlay_position":
+ await invoke("change_overlay_position_setting", { position: value });
+ break;
+ case "debug_mode":
+ await invoke("change_debug_mode_setting", { enabled: value });
+ break;
+ case "custom_words":
+ await invoke("update_custom_words", { words: value });
+ break;
+ case "word_correction_threshold":
+ await invoke("change_word_correction_threshold_setting", { threshold: value });
+ break;
+ case "bindings":
+ case "selected_model":
+ break;
+ default:
+ console.warn(`No handler for setting: ${String(key)}`);
+ }
+ } catch (error) {
+ console.error(`Failed to update setting ${String(key)}:`, error);
+
+ // Rollback on error
+ set((state) => ({
+ settings: state.settings
+ ? { ...state.settings, [key]: originalValue }
+ : null,
+ }));
+ } finally {
+ setUpdating(updateKey, false);
+ }
+ },
+
+ // Reset a setting to its default value
+ resetSetting: async (key) => {
+ const defaultValue = DEFAULT_SETTINGS[key];
+ if (defaultValue !== undefined) {
+ await get().updateSetting(key, defaultValue as any);
+ }
+ },
+
+ // Update a specific binding
+ updateBinding: async (id, binding) => {
+ const { settings, setUpdating } = get();
+ const updateKey = `binding_${id}`;
+ const originalBinding = settings?.bindings?.[id]?.current_binding;
+
+ setUpdating(updateKey, true);
+
+ try {
+ // Optimistic update
+ set((state) => ({
+ settings: state.settings
+ ? {
+ ...state.settings,
+ bindings: {
+ ...state.settings.bindings,
+ [id]: {
+ ...state.settings.bindings[id],
+ current_binding: binding,
+ },
+ },
+ }
+ : null,
+ }));
+
+ await invoke("change_binding", { id, binding });
+ } catch (error) {
+ console.error(`Failed to update binding ${id}:`, error);
+
+ // Rollback on error
+ if (originalBinding && get().settings) {
+ set((state) => ({
+ settings: state.settings
+ ? {
+ ...state.settings,
+ bindings: {
+ ...state.settings.bindings,
+ [id]: {
+ ...state.settings.bindings[id],
+ current_binding: originalBinding,
+ },
+ },
+ }
+ : null,
+ }));
+ }
+ } finally {
+ setUpdating(updateKey, false);
+ }
+ },
+
+ // Reset a specific binding
+ resetBinding: async (id) => {
+ const { setUpdating, refreshSettings } = get();
+ const updateKey = `binding_${id}`;
+
+ setUpdating(updateKey, true);
+
+ try {
+ await invoke("reset_binding", { id });
+ await refreshSettings();
+ } catch (error) {
+ console.error(`Failed to reset binding ${id}:`, error);
+ } finally {
+ setUpdating(updateKey, false);
+ }
+ },
+
+ // Initialize everything
+ initialize: async () => {
+ const { refreshSettings, refreshAudioDevices, refreshOutputDevices } = get();
+ await Promise.all([
+ refreshSettings(),
+ refreshAudioDevices(),
+ refreshOutputDevices(),
+ ]);
+ },
+ }))
+);