拆分后台服务、浏览器安装器和桌面托盘控制器,支持 Windows Service、macOS LaunchAgent 以及 Linux systemd 部署。 新增 Windows Inno Setup 安装器、macOS Intel/Apple Silicon 通用 pkg、Linux 多架构安装脚本,并在安装过程中自动准备 Playwright Chromium。 新增仅 codex/desktop-packaging 分支触发的桌面端 CI/CD,覆盖 Go 测试、交叉编译和 Windows/macOS/Linux 安装包构建;保持现有 Docker 工作流不变。 补充数据密钥持久化、托盘图标、安装文档及相关测试。
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"golang.org/x/sys/windows/svc"
|
|
)
|
|
|
|
type windowsServiceHandler struct {
|
|
run func(context.Context) error
|
|
}
|
|
|
|
func runPlatformService(name string, run func(context.Context) error) error {
|
|
if err := svc.Run(name, windowsServiceHandler{run: run}); err != nil {
|
|
return fmt.Errorf("Windows Service %q: %w", name, err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (h windowsServiceHandler) Execute(_ []string, requests <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) {
|
|
const accepted = svc.AcceptStop | svc.AcceptShutdown
|
|
status <- svc.Status{State: svc.StartPending}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
done := make(chan error, 1)
|
|
go func() { done <- h.run(ctx) }()
|
|
status <- svc.Status{State: svc.Running, Accepts: accepted}
|
|
|
|
for {
|
|
select {
|
|
case request := <-requests:
|
|
switch request.Cmd {
|
|
case svc.Stop, svc.Shutdown:
|
|
status <- svc.Status{State: svc.StopPending, Accepts: accepted}
|
|
cancel()
|
|
}
|
|
case err := <-done:
|
|
cancel()
|
|
if err != nil {
|
|
return true, 1
|
|
}
|
|
return false, 0
|
|
}
|
|
}
|
|
}
|