Remove unused assets, refactor migration handling, and add crash reporting
- Deleted obsolete icons, layout files, and SVG assets. - Added `useAutoUpdate` hook for streamlined update logic. - Introduced `auto_migrate_electron` and migration commands for Electron-to-Tauri data migration. - Implemented `init_panic_hook` for improved crash reporting. - Updated `.gitignore` for Tauri build output and IDE-specific files.
This commit is contained in:
67
hooks/useAutoUpdate.ts
Normal file
67
hooks/useAutoUpdate.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import {useEffect, useState} from 'react';
|
||||
import {check, Update} from '@tauri-apps/plugin-updater';
|
||||
import {relaunch} from '@tauri-apps/plugin-process';
|
||||
|
||||
export interface UpdateState {
|
||||
available: boolean;
|
||||
version: string;
|
||||
notes: string;
|
||||
downloading: boolean;
|
||||
progress: number;
|
||||
install: () => Promise<void>;
|
||||
dismiss: () => void;
|
||||
}
|
||||
|
||||
export function useAutoUpdate(): UpdateState {
|
||||
const [available, setAvailable] = useState(false);
|
||||
const [version, setVersion] = useState('');
|
||||
const [notes, setNotes] = useState('');
|
||||
const [downloading, setDownloading] = useState(false);
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [update, setUpdate] = useState<Update | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
async function checkForUpdate() {
|
||||
try {
|
||||
const result = await check();
|
||||
if (cancelled || !result) return;
|
||||
setUpdate(result);
|
||||
setAvailable(true);
|
||||
setVersion(result.version);
|
||||
setNotes(result.body ?? '');
|
||||
} catch (_) {
|
||||
// silently fail — no update or offline
|
||||
}
|
||||
}
|
||||
|
||||
checkForUpdate();
|
||||
return () => { cancelled = true; };
|
||||
}, []);
|
||||
|
||||
async function install() {
|
||||
if (!update) return;
|
||||
setDownloading(true);
|
||||
try {
|
||||
await update.downloadAndInstall((event) => {
|
||||
if (event.event === 'Started' && event.data.contentLength) {
|
||||
setProgress(0);
|
||||
} else if (event.event === 'Progress') {
|
||||
setProgress((prev) => prev + event.data.chunkLength);
|
||||
} else if (event.event === 'Finished') {
|
||||
setProgress(100);
|
||||
}
|
||||
});
|
||||
await relaunch();
|
||||
} catch (_) {
|
||||
setDownloading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function dismiss() {
|
||||
setAvailable(false);
|
||||
}
|
||||
|
||||
return {available, version, notes, downloading, progress, install, dismiss};
|
||||
}
|
||||
Reference in New Issue
Block a user