添加应用退出功能,支持通过长按触摸事件触发退出

This commit is contained in:
yuchenglong
2025-12-05 16:36:56 +08:00
parent 2bea4b2025
commit 4725950933
4 changed files with 12 additions and 1 deletions

View File

@@ -372,6 +372,14 @@ app.whenReady().then(() => {
app.relaunch(); app.relaunch();
app.exit(0); app.exit(0);
}); });
ipcMain.on("quit-app", () => {
try {
app.quit();
} catch (err) {
// 最后手段:强制退出
app.exit(0);
}
});
app.on("activate", () => { app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) { if (BrowserWindow.getAllWindows().length === 0) {

View File

@@ -20,4 +20,5 @@ contextBridge.exposeInMainWorld("electronAPI", {
ipcRenderer.removeAllListeners("idcard-error"); ipcRenderer.removeAllListeners("idcard-error");
}, },
restartApp: () => ipcRenderer.send("restart-app"), restartApp: () => ipcRenderer.send("restart-app"),
quitApp: () => ipcRenderer.send("quit-app"),
}); });

View File

@@ -39,7 +39,8 @@ function App() {
const handleTouchStart = () => { const handleTouchStart = () => {
restartTimerRef.current = window.setTimeout(() => { restartTimerRef.current = window.setTimeout(() => {
window.electronAPI.restartApp(); // 长按 5 秒改为关闭应用
window.electronAPI.quitApp();
}, 5000); }, 5000);
}; };

1
src/electron.d.ts vendored
View File

@@ -28,6 +28,7 @@ interface ElectronAPI {
log: (level: string, message: any) => void; log: (level: string, message: any) => void;
removeIdCardListeners: () => void; removeIdCardListeners: () => void;
restartApp: () => void; restartApp: () => void;
quitApp: () => void;
} }
interface Window { interface Window {