mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 03:24:54 +00:00
66 lines
2 KiB
TypeScript
66 lines
2 KiB
TypeScript
import { lazy, onCleanup, Suspense } from "solid-js"
|
|
import { Command, SettingsPage, type Plugin } from "@opencode/plugin/gui"
|
|
import { onIdle } from "@opencode/plugin/gui/builtin"
|
|
import { Pairing } from "./contract"
|
|
import type definition from "./index"
|
|
|
|
const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
if (!ctx.desktop) return
|
|
const layout = ctx.layout
|
|
const servers = ctx.servers
|
|
const pairing = ctx.use(Pairing)
|
|
const Page = lazy(() => import("./page"))
|
|
// Settings rows are small; load them while idle so settings opens without a blank row.
|
|
onCleanup(onIdle(() => void Page.preload()))
|
|
|
|
// The desktop's own server. Its ref is already authenticated in this window, so codes need no main process.
|
|
const local = () =>
|
|
servers
|
|
.list()
|
|
.map((id) => servers.get(id))
|
|
.find((server) => server?.builtin)
|
|
|
|
ctx.add(SettingsPage, {
|
|
id: "pairing",
|
|
icon: "outline-pair",
|
|
get title() {
|
|
return ctx.t("title")
|
|
},
|
|
get entries() {
|
|
const pairingEntry = { id: "pairing", title: ctx.t("title"), keywords: "pair device qr phone remote" }
|
|
|
|
// Remote access and the display setting exist only while pairing's main side answers.
|
|
if (pairing().status !== "active") return [pairingEntry]
|
|
|
|
return [
|
|
pairingEntry,
|
|
{
|
|
id: "settings-remote-access",
|
|
title: ctx.t("remote.title"),
|
|
description: ctx.t("remote.description"),
|
|
keywords: "internet tunnel opentunnel",
|
|
},
|
|
{
|
|
id: "settings-keep-screen-active",
|
|
title: ctx.t("screenActive.title"),
|
|
description: ctx.t("screenActive.description"),
|
|
keywords: "display sleep awake local",
|
|
},
|
|
]
|
|
},
|
|
render: () => (
|
|
<Suspense>
|
|
<Page server={local} pairing={pairing} />
|
|
</Suspense>
|
|
),
|
|
})
|
|
|
|
ctx.add(Command, () => ({
|
|
id: "open",
|
|
title: ctx.t("command.title"),
|
|
group: ctx.t("command.category.server"),
|
|
run: () => layout.settings("pairing"),
|
|
}))
|
|
}
|
|
|
|
export default setup
|