跳到主要内容

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

浏览文件

start-at-login_unix.go

63 行 · 1.7 KB历史下载
1//go:build !windows
2
3// SPDX-FileCopyrightText: Copyright The Lima Authors
4// SPDX-License-Identifier: Apache-2.0
5
6package main
7
8import (
9 "errors"
10 "fmt"
11 "os"
12
13 "github.com/sirupsen/logrus"
14 "github.com/spf13/cobra"
15
16 "github.com/lima-vm/lima/v2/pkg/autostart"
17 "github.com/lima-vm/lima/v2/pkg/store"
18)
19
20func startAtLoginAction(cmd *cobra.Command, args []string) error {
21 ctx := cmd.Context()
22 instName := DefaultInstanceName
23 if len(args) > 0 {
24 instName = args[0]
25 }
26
27 inst, err := store.Inspect(ctx, instName)
28 if err != nil {
29 if errors.Is(err, os.ErrNotExist) {
30 logrus.Infof("Instance %#q not found", instName)
31 return nil
32 }
33 return err
34 }
35
36 flags := cmd.Flags()
37 startAtLogin, err := flags.GetBool("enabled")
38 if err != nil {
39 return err
40 }
41 if registered, err := autostart.IsRegistered(ctx, inst); err != nil {
42 return fmt.Errorf("failed to check if the autostart entry for instance %#q is registered: %w", inst.Name, err)
43 } else if startAtLogin {
44 verb := "create"
45 if registered {
46 verb = "update"
47 }
48 if err := autostart.RegisterToStartAtLogin(ctx, inst); err != nil {
49 return fmt.Errorf("failed to %s the autostart entry for instance %#q: %w", verb, inst.Name, err)
50 }
51 logrus.Infof("The autostart entry for instance %#q has been %sd", inst.Name, verb)
52 } else {
53 if !registered {
54 logrus.Infof("The autostart entry for instance %#q is not registered", inst.Name)
55 } else if err := autostart.UnregisterFromStartAtLogin(ctx, inst); err != nil {
56 return fmt.Errorf("failed to unregister the autostart entry for instance %#q: %w", inst.Name, err)
57 } else {
58 logrus.Infof("The autostart entry for instance %#q has been unregistered", inst.Name)
59 }
60 }
61
62 return nil
63}