Files
Reims-Go/internal/plugin/builtin/install_guide.go
T

69 lines
2.2 KiB
Go

package builtin
import (
"context"
"github.com/Nwflower/reims-go/internal/macos/installguide"
"github.com/Nwflower/reims-go/internal/plugin"
)
// IDInstallGuide is the optional builtin extension that presents a floating
// step-by-step macOS installation and recovery guide on the VM window.
const IDInstallGuide = "builtin.install-guide"
// ServiceInstallGuide is the service name provided by IDInstallGuide.
const ServiceInstallGuide = "ui.install-guide"
func defInstallGuide(ver string, cb HostCallbacks, desiredFn func(string, bool) bool) plugin.PluginDef {
return plugin.PluginDef{
Manifest: plugin.Manifest{
Schema: 1,
ID: IDInstallGuide,
Version: ver,
Name: plugin.LocalizedText{ZhCN: "虚拟机窗口安装引导", EnUS: "VM Window Install Guide"},
Description: plugin.LocalizedText{
ZhCN: "在虚拟机窗口旁悬浮展示 macOS 安装与恢复分步引导,支持键入命令、退出恢复模式与重启续接",
EnUS: "Floating step-by-step macOS installation and recovery guide on the VM window, with command typing, recovery handoff and restart resume",
},
Publisher: "Reims-Go",
License: "Apache-2.0",
Provides: []plugin.ServiceProvision{{Service: ServiceInstallGuide, Version: "1.0.0"}},
Permissions: []string{"vm:read", "vm:control", "qmp:write", "ui:notify"},
DefaultEnabled: true,
},
Source: plugin.SourceBuiltin,
Trust: plugin.TrustOfficial,
Desired: desiredFn(IDInstallGuide, true),
Activate: func(_ context.Context, sc *plugin.Scope) error {
mgr := installguide.NewManager(cb.OnInstallGuidesChanged)
sc.Provide(ServiceInstallGuide, "1.0.0", mgr)
sc.OnDispose(func() {
mgr.Close()
})
hooks := sc.Registry().Hooks()
cancelVM := func(_ context.Context, raw any) (any, error) {
if ev, ok := raw.(plugin.VMEventPayload); ok && ev.VMName != "" {
mgr.Cancel(ev.VMName)
}
return nil, nil
}
hooks.Subscribe(sc, plugin.HookRegistration{
Event: plugin.EventVMAfterStop,
Builtin: true,
Handler: cancelVM,
})
hooks.Subscribe(sc, plugin.HookRegistration{
Event: plugin.EventVMDeleted,
Builtin: true,
Handler: cancelVM,
})
if cb.SyncInstallGuides != nil {
cb.SyncInstallGuides()
}
return nil
},
}
}