Files
Reims-Go/internal/plugin/builtin/bootstrap.go
T
千川白浪 e0ff794b0e feat: add experimental macOS desktop support on Apple Silicon (#207)
* feat: add experimental Apple Silicon support with Nivfold

Integrate the standalone Nivfold protocol 1 runner; tested against Nivfold f436fb6. The Windows Reims vGPU runtime remains independent.

* fix: open QQ invites and VM SSH on macOS

* fix: move VM, View and Help to the macOS menu bar

* feat(macos): add resumable Apple restore image downloads

Expose the compatible restore image in the VM wizard and Images page, validate downloads before caching, and fix macOS memory reporting and plugin SVG rendering.

* fix(macos): localize the native application menu

* fix(macos): address native desktop review findings
2026-12-06 00:47:07 +08:00

105 lines
3.3 KiB
Go

package builtin
import (
"fmt"
"github.com/Nwflower/reims-go/internal/driver"
"github.com/Nwflower/reims-go/internal/host"
"github.com/Nwflower/reims-go/internal/i18n"
"github.com/Nwflower/reims-go/internal/plugin"
"github.com/Nwflower/reims-go/internal/version"
)
// KernelBootstrapOptions configures the shared GUI/CLI plugin-kernel and
// driver-router composition root.
type KernelBootstrapOptions struct {
DataRoot string
DataRootFn func() string
SafeMode bool
LocaleFn func() i18n.Locale
Logger func(source, line string)
HostHandlers func(pluginID string) map[string]plugin.RPCRequestHandler
OnSettingsChanged func(pluginID, vmName string)
OnSidecarStopped func(pluginID string)
VMInventories []driver.VMInventory
Callbacks HostCallbacks
RegisterGuest func(reg *plugin.Registry, cb HostCallbacks, desired func(id string, defaultEnabled bool) bool) error
// StrictRegister causes builtin/guest registration errors to abort bootstrap
// instead of logging warnings (used by CLI commands).
StrictRegister bool
}
// BootstrapKernel creates and wires the plugin manager, driver router,
// built-in extensions, optional guest plugin, and external plugins in one
// canonical order shared by both the desktop app and the CLI.
func BootstrapKernel(opts KernelBootstrapOptions) (*plugin.Manager, *driver.Router, error) {
logf := opts.Logger
if logf == nil {
logf = func(string, string) {}
}
mgr, err := plugin.NewManager(plugin.ManagerOptions{
DataRoot: opts.DataRoot,
HostVersion: version.Version,
SafeMode: opts.SafeMode,
RedactFn: host.RedactText,
LocaleFn: opts.LocaleFn,
Logger: logf,
HostHandlers: opts.HostHandlers,
OnSettingsChanged: opts.OnSettingsChanged,
OnSidecarStopped: opts.OnSidecarStopped,
SidecarDriverFactory: func(contrib plugin.GuestDriverContribution, sup *plugin.SidecarSupervisor) any {
return driver.NewSidecarDriver(contrib, sup)
},
})
if err != nil {
if opts.StrictRegister || mgr == nil {
if mgr != nil {
mgr.Close()
}
return nil, nil, err
}
logf("plugin", "Plugin state warning: "+err.Error())
}
dataRootFn := opts.DataRootFn
if dataRootFn == nil {
root := opts.DataRoot
dataRootFn = func() string { return root }
}
router := driver.NewRouter(mgr.Registry(), dataRootFn, opts.VMInventories...)
mgr.Registry().SetInUseChecker(router.PluginInUseChecker())
mgr.Registry().SetBusyChecker(router.PluginBusyChecker())
cb := opts.Callbacks
if cb.Log == nil {
cb.Log = logf
}
if cb.GetSetting == nil {
cb.GetSetting = func(pluginID, vmName, key string) (any, bool) {
v, ok := mgr.GetSettings(pluginID, vmName, false)[key]
return v, ok
}
}
if err := RegisterAll(mgr.Registry(), cb, mgr.DesiredFor); err != nil {
if opts.StrictRegister {
mgr.Close()
return nil, nil, err
}
logf("plugin", "Builtin extension register error: "+err.Error())
}
if opts.RegisterGuest != nil {
if err := opts.RegisterGuest(mgr.Registry(), cb, mgr.DesiredFor); err != nil {
if opts.StrictRegister {
mgr.Close()
return nil, nil, err
}
logf("plugin", "macOS guest plugin register error: "+err.Error())
}
}
if err := mgr.LoadExternal(); err != nil {
logf("plugin", fmt.Sprintf("External plugin load warning: %v", err))
}
return mgr, router, nil
}