跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

windows_host_manager_service_windows.go

60 行 · 1.5 KB历史下载
1//go:build windows
2
3package guestos
4
5import (
6 "context"
7 "errors"
8 "golang.org/x/sys/windows/svc"
9)
10
11type windowsHostManagerHandler struct{ bindingPath string }
12
13func (handler windowsHostManagerHandler) Execute(_ []string, requests <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) {
14 status <- svc.Status{State: svc.StartPending, WaitHint: 30000}
15 ctx, cancel := context.WithCancel(context.Background())
16 defer cancel()
17 done := make(chan error, 1)
18 ready := make(chan struct{})
19 go func() { done <- serveWindowsHostManager(ctx, handler.bindingPath, ready) }()
20 select {
21 case <-ready:
22 case <-done:
23 return true, 1
24 }
25 status <- svc.Status{State: svc.Running, Accepts: svc.AcceptStop | svc.AcceptShutdown}
26 for {
27 select {
28 case err := <-done:
29 if err != nil {
30 return true, 1
31 }
32 return false, 0
33 case request := <-requests:
34 switch request.Cmd {
35 case svc.Interrogate:
36 status <- request.CurrentStatus
37 case svc.Stop, svc.Shutdown:
38 status <- svc.Status{State: svc.StopPending}
39 cancel()
40 err := <-done
41 if err != nil {
42 return true, 1
43 }
44 return false, 0
45 }
46 }
47 }
48}
49
50func RunWindowsHostManagerService(path string) error {
51 service, err := svc.IsWindowsService()
52 if err != nil || !service {
53 return errors.New("manager_requires_scm")
54 }
55 binding, err := LoadWindowsHostManagerBinding(path)
56 if err != nil {
57 return err
58 }
59 return svc.Run(WindowsHostManagerServiceName(binding.VMID), windowsHostManagerHandler{bindingPath: path})
60}