Skip to content

Commit dcffffb

Browse files
committed
fix: address CodeRabbit review comments
1 parent f689f4d commit dcffffb

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

frontend/src-tauri/src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use tauri::path::BaseDirectory;
99
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
1010
use tauri::{Manager, Window, WindowEvent};
1111
use tauri_plugin_autostart::ManagerExt;
12-
use tauri_plugin_shell::ShellExt;
1312

1413
const ENDPOINTS: [(&str, &str, &str); 2] = [
1514
(
@@ -137,6 +136,7 @@ fn prod(app: &tauri::AppHandle, resource_path: &std::path::Path) -> Result<(), S
137136
println!("Sync spawned with PID {}", sync_child.pid());
138137

139138
use tauri_plugin_shell::process::CommandEvent;
139+
use tauri_plugin_shell::ShellExt;
140140
tauri::async_runtime::spawn(async move {
141141
while let Some(event) = backend_rx.recv().await {
142142
match event {
@@ -240,9 +240,14 @@ fn main() {
240240
let menu = Menu::with_items(app, &[&show_item, &separator, &quit_item])?;
241241

242242
TrayIconBuilder::new()
243-
.icon(app.default_window_icon().unwrap().clone())
243+
.icon(
244+
app.default_window_icon()
245+
.ok_or("no default window icon")?
246+
.clone(),
247+
)
244248
.tooltip("PictoPy")
245249
.menu(&menu)
250+
.menu_on_left_click(false)
246251
.on_menu_event(|app, event| match event.id.as_ref() {
247252
"show" => {
248253
if let Some(w) = app.get_webview_window("main") {

frontend/src/pages/SettingsPage/components/SystemSettingsCard.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,35 @@ import { invoke } from '@tauri-apps/api/core';
44
import SettingsCard from './SettingsCard';
55

66
const SystemSettingsCard: React.FC = () => {
7-
const [autostart, setAutostart] = useState(false);
7+
// null = unknown / error reading state
8+
const [autostart, setAutostart] = useState<boolean | null>(null);
89
const [loading, setLoading] = useState(true);
10+
const [pending, setPending] = useState(false);
911

1012
useEffect(() => {
1113
invoke<boolean>('is_autostart_enabled')
1214
.then(setAutostart)
13-
.catch(() => setAutostart(false))
15+
.catch(() => setAutostart(null))
1416
.finally(() => setLoading(false));
1517
}, []);
1618

1719
const handleToggle = async () => {
20+
if (autostart === null) return;
1821
const next = !autostart;
22+
setPending(true);
1923
try {
2024
await invoke(next ? 'enable_autostart' : 'disable_autostart');
2125
setAutostart(next);
2226
} catch (err) {
2327
console.error('Failed to toggle autostart:', err);
28+
} finally {
29+
setPending(false);
2430
}
2531
};
2632

33+
const isDisabled = loading || pending || autostart === null;
34+
const isChecked = autostart === true;
35+
2736
return (
2837
<SettingsCard
2938
icon={Monitor}
@@ -32,24 +41,28 @@ const SystemSettingsCard: React.FC = () => {
3241
>
3342
<div className="flex items-center justify-between py-1">
3443
<div>
35-
<div className="font-medium">Launch at startup</div>
36-
<div className="text-muted-foreground text-sm">
44+
<div id="autostart-label" className="font-medium">
45+
Launch at startup
46+
</div>
47+
<div id="autostart-desc" className="text-muted-foreground text-sm">
3748
Automatically start PictoPy when you log in. The window starts
3849
minimized to the system tray.
3950
</div>
4051
</div>
4152

4253
<button
4354
role="switch"
44-
aria-checked={autostart}
45-
disabled={loading}
55+
aria-checked={isChecked}
56+
aria-labelledby="autostart-label"
57+
aria-describedby="autostart-desc"
58+
disabled={isDisabled}
4659
onClick={handleToggle}
4760
className={[
4861
'relative inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full',
4962
'transition-colors duration-200 ease-in-out',
5063
'focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',
5164
'disabled:cursor-not-allowed disabled:opacity-50',
52-
autostart
65+
isChecked
5366
? 'bg-primary focus-visible:ring-primary'
5467
: 'bg-gray-200 focus-visible:ring-gray-500 dark:bg-gray-700',
5568
].join(' ')}
@@ -58,7 +71,7 @@ const SystemSettingsCard: React.FC = () => {
5871
className={[
5972
'inline-block h-4 w-4 rounded-full bg-white shadow-md',
6073
'transition-transform duration-200 ease-in-out',
61-
autostart ? 'translate-x-6' : 'translate-x-1',
74+
isChecked ? 'translate-x-6' : 'translate-x-1',
6275
].join(' ')}
6376
/>
6477
</button>

0 commit comments

Comments
 (0)