| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | package autostart |
| 6 | |
| 7 | import ( |
| 8 | "context" |
| 9 | "sync" |
| 10 | |
| 11 | "github.com/lima-vm/lima/v2/pkg/limatype" |
| 12 | ) |
| 13 | |
| 14 | |
| 15 | func IsRegistered(ctx context.Context, inst *limatype.Instance) (bool, error) { |
| 16 | return manager().IsRegistered(ctx, inst) |
| 17 | } |
| 18 | |
| 19 | |
| 20 | func RegisterToStartAtLogin(ctx context.Context, inst *limatype.Instance) error { |
| 21 | return manager().RegisterToStartAtLogin(ctx, inst) |
| 22 | } |
| 23 | |
| 24 | |
| 25 | func UnregisterFromStartAtLogin(ctx context.Context, inst *limatype.Instance) error { |
| 26 | return manager().UnregisterFromStartAtLogin(ctx, inst) |
| 27 | } |
| 28 | |
| 29 | |
| 30 | func AutoStartedIdentifier() string { |
| 31 | return manager().AutoStartedIdentifier() |
| 32 | } |
| 33 | |
| 34 | |
| 35 | func RequestStart(ctx context.Context, inst *limatype.Instance) error { |
| 36 | return manager().RequestStart(ctx, inst) |
| 37 | } |
| 38 | |
| 39 | |
| 40 | func RequestStop(ctx context.Context, inst *limatype.Instance) (bool, error) { |
| 41 | return manager().RequestStop(ctx, inst) |
| 42 | } |
| 43 | |
| 44 | type autoStartManager interface { |
| 45 | |
| 46 | IsRegistered(ctx context.Context, inst *limatype.Instance) (bool, error) |
| 47 | RegisterToStartAtLogin(ctx context.Context, inst *limatype.Instance) error |
| 48 | UnregisterFromStartAtLogin(ctx context.Context, inst *limatype.Instance) error |
| 49 | |
| 50 | |
| 51 | AutoStartedIdentifier() string |
| 52 | |
| 53 | |
| 54 | |
| 55 | RequestStart(ctx context.Context, inst *limatype.Instance) error |
| 56 | |
| 57 | RequestStop(ctx context.Context, inst *limatype.Instance) (bool, error) |
| 58 | } |
| 59 | |
| 60 | var manager = sync.OnceValue(Manager) |