()
| 40 | import { isLinux, isMac, isWindows } from "./utils/platform"; |
| 41 | |
| 42 | export default function App() { |
| 43 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 44 | const [_, _setMaximized] = useAtom(isWindowMaxsizedAtom); |
| 45 | |
| 46 | const [tabs, setTabs] = useAtom(tabsAtom); |
| 47 | const [activeTab, setActiveTab] = useAtom(activeTabAtom); |
| 48 | // const [isWide, setIsWide] = useState(false); |
| 49 | const [telemetryEventSent, setTelemetryEventSent] = useState(false); |
| 50 | const [isClassroomMode, setIsClassroomMode] = useAtom(isClassroomModeAtom); |
| 51 | const [showQuickSettingsToolbar, setShowQuickSettingsToolbar] = useState(Settings.showQuickSettingsToolbar); |
| 52 | const [windowBackgroundAlpha, setWindowBackgroundAlpha] = useState(Settings.windowBackgroundAlpha); |
| 53 | const [uiScalePercent, setUiScalePercent] = useState(Settings.uiScalePercent); |
| 54 | |
| 55 | const contextMenuTriggerRef = useRef<HTMLDivElement>(null); |
| 56 | |
| 57 | // const { t } = useTranslation("app"); |
| 58 | |
| 59 | useEffect(() => { |
| 60 | // 设置兼容性提示依赖 Dialog UI,必须在应用挂载后再触发。 |
| 61 | void flushSettingsLoadErrors(); |
| 62 | |
| 63 | // 先修复老用户的快捷键缓存问题(F11快捷键) |
| 64 | (async () => { |
| 65 | await checkAndFixShortcutStorage(); |
| 66 | })(); |
| 67 | // 注册UI级别快捷键 |
| 68 | KeyBindsUI.registerAllUIKeyBinds(); |
| 69 | KeyBindsUI.uiStartListen(); |
| 70 | |
| 71 | // 在捕获阶段无条件禁止浏览器/WebView 原生右键菜单弹出。 |
| 72 | // 使用 capture:true 确保在任何子元素(包括 Radix UI Portal)处理事件之前就拦截, |
| 73 | // 防止快速连续右键或右键双击时浏览器菜单与应用自定义菜单混合弹出。 |
| 74 | // 应用自定义菜单由 mouseup 事件驱动,不依赖 contextmenu 事件,不受影响。 |
| 75 | window.addEventListener( |
| 76 | "contextmenu", |
| 77 | (event) => { |
| 78 | event.preventDefault(); |
| 79 | }, |
| 80 | true, // capture 阶段,优先于所有子元素 |
| 81 | ); |
| 82 | |
| 83 | // 全局错误处理 |
| 84 | window.addEventListener("error", (event) => { |
| 85 | Telemetry.event("未知错误", String(event.error)); |
| 86 | }); |
| 87 | |
| 88 | // 监听主题样式切换 |
| 89 | Settings.watch("theme", (value) => { |
| 90 | Themes.applyThemeById(value); |
| 91 | }); |
| 92 | |
| 93 | // 监听主题模式切换 |
| 94 | Settings.watch("themeMode", (value) => { |
| 95 | const targetTheme = value === "light" ? Settings.lightTheme : Settings.darkTheme; |
| 96 | if (Settings.theme !== targetTheme) { |
| 97 | Settings.theme = targetTheme; |
| 98 | } |
| 99 | }); |
nothing calls this directly
no test coverage detected