synor/apps/desktop-wallet/src/hooks/useTrayEvents.ts
Gulshan Yadav ce5c996b35 feat(desktop-wallet): add system tray and auto-updater
- Add system tray with menu: Show, Hide, Lock, Check Updates, Quit
- Integrate tauri-plugin-updater for seamless auto-updates
- Add UpdateBanner component for update notifications
- Add useAutoUpdater hook for update state management
- Add useTrayEvents hook for tray event handling
- Add Updates section to Settings page for manual update checks
- Configure updater endpoints in tauri.conf.json
- Exclude desktop-wallet from Cargo workspace (uses own Tauri deps)
2026-01-10 06:55:44 +05:30

40 lines
1.1 KiB
TypeScript

/**
* System tray event hook for desktop wallet.
*
* Handles events triggered from the system tray menu.
*/
import { useEffect } from 'react';
import { listen } from '@tauri-apps/api/event';
import { useNavigate } from 'react-router-dom';
import { useWalletStore } from '../store/wallet';
export function useTrayEvents() {
const navigate = useNavigate();
const { lockWallet, isUnlocked } = useWalletStore();
useEffect(() => {
const unlisteners: (() => void)[] = [];
// Handle wallet lock from tray
listen('wallet-lock', async () => {
if (isUnlocked) {
await lockWallet();
navigate('/unlock');
}
}).then((unlisten) => unlisteners.push(unlisten));
// Handle app quit from tray
listen('app-quit', async () => {
// Perform cleanup if wallet is unlocked
if (isUnlocked) {
await lockWallet();
}
// The backend will handle the actual quit
}).then((unlisten) => unlisteners.push(unlisten));
return () => {
unlisteners.forEach((unlisten) => unlisten());
};
}, [isUnlocked, lockWallet, navigate]);
}