mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-09-24 16:29:01 +08:00
feat: Enhance Wails desktop app key handling for page reload
- Introduced a check for Wails desktop environment to conditionally intercept Cmd/Ctrl+R key presses, preventing full page reloads that could lead to a white screen. - Updated event listener management to ensure key handling is only active in the Wails desktop context, improving user experience by maintaining application state during refresh actions. - Added comments for clarity on the purpose of these changes and their impact on different deployment environments.
This commit is contained in:
@@ -36,7 +36,15 @@ const reloadApp = () => {
|
||||
}
|
||||
provide('app:reload', reloadApp)
|
||||
|
||||
// 仅在 Wails 桌面端运行时拦截 Cmd/Ctrl+R:
|
||||
// 桌面端没有浏览器地址栏,整页重载会白屏,所以用前端软刷新替代。
|
||||
// 浏览器(含 Web 版 / 非 Lite 部署)里不拦截,交给浏览器做真正的整页刷新,
|
||||
// 否则会出现左侧菜单、全局设置、Pinia store 等不随"刷新"一起重置的问题。
|
||||
// @ts-ignore
|
||||
const isWailsDesktop = typeof window !== 'undefined' && !!(window as any).runtime?.EventsOn
|
||||
|
||||
const handleGlobalKeyDown = (e: KeyboardEvent) => {
|
||||
if (!isWailsDesktop) return
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'r') {
|
||||
e.preventDefault()
|
||||
reloadApp()
|
||||
@@ -140,9 +148,8 @@ onMounted(() => {
|
||||
document.addEventListener('dragover', handleGlobalDragOver, true);
|
||||
document.addEventListener('dragleave', handleGlobalDragLeave, true);
|
||||
document.addEventListener('drop', handleGlobalDrop, true);
|
||||
window.addEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
if (window.runtime?.EventsOn) {
|
||||
if (isWailsDesktop) {
|
||||
window.addEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
window.runtime.EventsOn('app:reload', () => {
|
||||
reloadApp()
|
||||
@@ -156,11 +163,13 @@ onUnmounted(() => {
|
||||
document.removeEventListener('dragover', handleGlobalDragOver, true);
|
||||
document.removeEventListener('dragleave', handleGlobalDragLeave, true);
|
||||
document.removeEventListener('drop', handleGlobalDrop, true);
|
||||
window.removeEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
if (window.runtime?.EventsOff) {
|
||||
if (isWailsDesktop) {
|
||||
window.removeEventListener('keydown', handleGlobalKeyDown);
|
||||
// @ts-ignore
|
||||
window.runtime.EventsOff('app:reload')
|
||||
if (window.runtime?.EventsOff) {
|
||||
// @ts-ignore
|
||||
window.runtime.EventsOff('app:reload')
|
||||
}
|
||||
}
|
||||
dragCounter = 0;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user