Add Windows desktop app menu (#28420)
This commit is contained in:
@@ -21,7 +21,7 @@ import { createEffect, createResource, onCleanup, onMount, Show } from "solid-js
|
||||
import { render } from "solid-js/web"
|
||||
import pkg from "../../package.json"
|
||||
import { initI18n, t } from "./i18n"
|
||||
import { webviewZoom } from "./webview-zoom"
|
||||
import { resetZoom, webviewZoom, zoomIn, zoomOut } from "./webview-zoom"
|
||||
import "./styles.css"
|
||||
import { useTheme } from "@opencode-ai/ui/theme"
|
||||
|
||||
@@ -100,6 +100,22 @@ const createPlatform = (): Platform => {
|
||||
return window.api.wslPath(result, "linux").catch(() => result) as any
|
||||
}
|
||||
|
||||
const runDesktopMenuAction: Platform["runDesktopMenuAction"] = (action) => {
|
||||
switch (action) {
|
||||
case "view.resetZoom":
|
||||
resetZoom()
|
||||
return
|
||||
case "view.zoomIn":
|
||||
zoomIn()
|
||||
return
|
||||
case "view.zoomOut":
|
||||
zoomOut()
|
||||
return
|
||||
}
|
||||
|
||||
return window.api.runDesktopMenuAction(action)
|
||||
}
|
||||
|
||||
const storage = (() => {
|
||||
const cache = new Map<string, AsyncStorage>()
|
||||
|
||||
@@ -254,6 +270,8 @@ const createPlatform = (): Platform => {
|
||||
|
||||
webviewZoom,
|
||||
|
||||
runDesktopMenuAction,
|
||||
|
||||
checkAppExists: async (appName: string) => {
|
||||
return window.api.checkAppExists(appName)
|
||||
},
|
||||
|
||||
@@ -33,23 +33,27 @@ const applyZoom = (next: number) => {
|
||||
})
|
||||
}
|
||||
|
||||
const resetZoom = () => applyZoom(1)
|
||||
const zoomIn = () => applyZoom(clamp(requestedZoom + 0.2))
|
||||
const zoomOut = () => applyZoom(clamp(requestedZoom - 0.2))
|
||||
|
||||
window.addEventListener("keydown", (event) => {
|
||||
if (!(OS_NAME === "macos" ? event.metaKey : event.ctrlKey)) return
|
||||
|
||||
if (event.key === "-") {
|
||||
event.preventDefault()
|
||||
applyZoom(clamp(requestedZoom - 0.2))
|
||||
zoomOut()
|
||||
return
|
||||
}
|
||||
if (event.key === "=" || event.key === "+") {
|
||||
event.preventDefault()
|
||||
applyZoom(clamp(requestedZoom + 0.2))
|
||||
zoomIn()
|
||||
return
|
||||
}
|
||||
if (event.key === "0") {
|
||||
event.preventDefault()
|
||||
applyZoom(1)
|
||||
resetZoom()
|
||||
}
|
||||
})
|
||||
|
||||
export { webviewZoom }
|
||||
export { webviewZoom, resetZoom, zoomIn, zoomOut }
|
||||
|
||||
Reference in New Issue
Block a user