summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/components/titlebar.tsx
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-12 09:49:14 -0600
committerGitHub <[email protected]>2026-02-12 09:49:14 -0600
commitff4414bb152acfddb5c0eb073c38bedc1df4ae14 (patch)
tree78381c67d21ef6f089647f6b19e7aa2976840dbc /packages/app/src/components/titlebar.tsx
parent56ad2db02055955f926fda0e4a89055b22ead6f9 (diff)
downloadopencode-ff4414bb152acfddb5c0eb073c38bedc1df4ae14.tar.gz
opencode-ff4414bb152acfddb5c0eb073c38bedc1df4ae14.zip
chore: refactor packages/app files (#13236)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Frank <[email protected]>
Diffstat (limited to 'packages/app/src/components/titlebar.tsx')
-rw-r--r--packages/app/src/components/titlebar.tsx48
1 files changed, 25 insertions, 23 deletions
diff --git a/packages/app/src/components/titlebar.tsx b/packages/app/src/components/titlebar.tsx
index e7b8066ae..039a25fae 100644
--- a/packages/app/src/components/titlebar.tsx
+++ b/packages/app/src/components/titlebar.tsx
@@ -13,6 +13,28 @@ import { useCommand } from "@/context/command"
import { useLanguage } from "@/context/language"
import { applyPath, backPath, forwardPath } from "./titlebar-history"
+type TauriDesktopWindow = {
+ startDragging?: () => Promise<void>
+ toggleMaximize?: () => Promise<void>
+}
+
+type TauriThemeWindow = {
+ setTheme?: (theme?: "light" | "dark" | null) => Promise<void>
+}
+
+type TauriApi = {
+ window?: {
+ getCurrentWindow?: () => TauriDesktopWindow
+ }
+ webviewWindow?: {
+ getCurrentWebviewWindow?: () => TauriThemeWindow
+ }
+}
+
+const tauriApi = () => (window as unknown as { __TAURI__?: TauriApi }).__TAURI__
+const currentDesktopWindow = () => tauriApi()?.window?.getCurrentWindow?.()
+const currentThemeWindow = () => tauriApi()?.webviewWindow?.getCurrentWebviewWindow?.()
+
export function Titlebar() {
const layout = useLayout()
const platform = usePlatform()
@@ -82,22 +104,7 @@ export function Titlebar() {
const getWin = () => {
if (platform.platform !== "desktop") return
-
- const tauri = (
- window as unknown as {
- __TAURI__?: {
- window?: {
- getCurrentWindow?: () => {
- startDragging?: () => Promise<void>
- toggleMaximize?: () => Promise<void>
- }
- }
- }
- }
- ).__TAURI__
- if (!tauri?.window?.getCurrentWindow) return
-
- return tauri.window.getCurrentWindow()
+ return currentDesktopWindow()
}
createEffect(() => {
@@ -106,13 +113,8 @@ export function Titlebar() {
const scheme = theme.colorScheme()
const value = scheme === "system" ? null : scheme
- const tauri = (window as unknown as { __TAURI__?: { webviewWindow?: { getCurrentWebviewWindow?: () => unknown } } })
- .__TAURI__
- const get = tauri?.webviewWindow?.getCurrentWebviewWindow
- if (!get) return
-
- const win = get() as { setTheme?: (theme?: "light" | "dark" | null) => Promise<void> }
- if (!win.setTheme) return
+ const win = currentThemeWindow()
+ if (!win?.setTheme) return
void win.setTheme(value).catch(() => undefined)
})