添加重启应用功能,支持通过触摸事件触发重启

This commit is contained in:
yuchenglong
2025-12-04 13:50:20 +08:00
parent 1e0822c1a0
commit 34e9c58392
4 changed files with 34 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
import { Routes, Route } from "react-router-dom";
import { useEffect, useState } from "react";
import { useEffect, useState, useRef } from "react";
// import { listen } from "@tauri-apps/api/event";
import "./App.css";
import icon from "./assets/icon.png";
@@ -16,6 +16,7 @@ import UI81 from "./pages/UI81/UI81";
function App() {
const [time, setTime] = useState<string>(() => formatDate(new Date()));
const restartTimerRef = useRef<number | null>(null);
useEffect(() => {
const id = setInterval(() => setTime(formatDate(new Date())), 1000);
@@ -36,13 +37,35 @@ function App() {
};
}, []);
const handleTouchStart = () => {
restartTimerRef.current = window.setTimeout(() => {
window.electronAPI.restartApp();
}, 5000);
};
const handleTouchEnd = () => {
if (restartTimerRef.current) {
clearTimeout(restartTimerRef.current);
restartTimerRef.current = null;
}
};
return (
<div className="app-container">
{/* 全局背景层 */}
<div className="global-background">
{/* 顶部固定区域 - 始终显示 */}
<div className="global-header">
<img className="header-logo" alt="logo" src={icon} />
<img
className="header-logo"
alt="logo"
src={icon}
onMouseDown={handleTouchStart}
onMouseUp={handleTouchEnd}
onMouseLeave={handleTouchEnd}
onTouchStart={handleTouchStart}
onTouchEnd={handleTouchEnd}
/>
<span className="header-title"></span>
</div>
<span className="header-time">{time}</span>

1
src/electron.d.ts vendored
View File

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