Files
Reims-Go/main.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

162 lines
4.6 KiB
Go

package main
import (
"context"
"embed"
"errors"
"fmt"
"os"
"runtime"
"time"
"github.com/Nwflower/reims-go/internal/app"
"github.com/Nwflower/reims-go/internal/cli"
"github.com/Nwflower/reims-go/internal/config"
"github.com/Nwflower/reims-go/internal/host"
"github.com/Nwflower/reims-go/internal/selfupdate"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed build/assets/logo.png
var trayIconPNG []byte
//go:embed LICENSE
var licenseText string
//go:embed NOTICE.md
var noticeText string
func main() {
args := os.Args[1:]
if len(args) == 3 && args[0] == host.QEMUASLRHelperArg {
if err := host.ApplyQEMUASLR(args[1], args[2]); err != nil {
fmt.Fprintln(os.Stderr, err)
if errors.Is(err, host.ErrQEMUASLRImagePolicy) {
os.Exit(host.QEMUASLRImagePolicyExitCode)
}
os.Exit(1)
}
return
}
if cli.IsCommand(args) {
cli.AttachConsole()
os.Exit(cli.Main(args))
}
launch, _ := cli.ParseWindowArgs(args)
if launch.CloseVM != "" {
if !cli.ForwardVMClose(launch.CloseVM) {
os.Exit(1)
}
return
}
if launch.WaitPID != 0 {
// Relaunched by an in-app update: let the old window exit first, or the
// single-instance lock below hands this launch back to it.
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
_ = host.WaitProcessExit(ctx, launch.WaitPID, "")
cancel()
}
if err := config.CheckFirstRunIsolation(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
firstRun := os.Getenv("REIMS_GO_FIRST_RUN") == "1"
releaseStartup := func() {}
if !firstRun && !launch.TakeoverRelaunch && selfupdate.Supported() == nil {
release, err := selfupdate.LockDesktopStartup(cli.InstanceID)
if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
releaseStartup = release
defer release()
if !launch.Background && launch.WaitPID == 0 && launch.StartVM == "" && launch.ResumeVM == "" {
pid := cli.WindowForUpdate()
relaunch := launch
relaunch.TakeoverRelaunch = true
restarted, err := selfupdate.Takeover(pid, relaunch.Args(), cli.DesktopWindowPID)
if restarted {
return
}
if err != nil {
release()
selfupdate.ReportTakeoverError(err)
}
}
}
}
app.RegisterLicenseTexts(licenseText, noticeText)
desktopApp, hooks := app.New(trayIconPNG, launch)
// A simulated first launch must open its own window even when an installed
// instance is already running. The test mode requires a separate location file.
instanceLock := &options.SingleInstanceLock{
UniqueId: cli.InstanceID,
OnSecondInstanceLaunch: hooks.OnSecondInstanceLaunch,
}
if firstRun {
instanceLock = nil
}
err := wails.Run(&options.App{
Title: "Reims-Go",
StartHidden: launch.Background,
SingleInstanceLock: instanceLock,
Width: 1120,
Height: 740,
MinWidth: 920,
MinHeight: 600,
// macOS extends content behind a titled native window; a frameless
// window would also remove the system traffic-light controls.
Frameless: runtime.GOOS != "darwin",
Mac: &mac.Options{
TitleBar: mac.TitleBarHidden(),
},
DragAndDrop: &options.DragAndDrop{
EnableFileDrop: true,
DisableWebViewDrop: true,
CSSDropProperty: "--wails-drop-target",
CSSDropValue: "drop",
},
AssetServer: &assetserver.Options{
Assets: assets,
Handler: desktopApp.PluginAssetHandler(),
},
BackgroundColour: &options.RGBA{R: 28, G: 28, B: 30, A: 255},
Windows: &windows.Options{
Theme: windows.Dark,
WebviewIsTransparent: false,
WindowIsTranslucent: false,
// Disable WebView2's GPU process: Reims-Go's desktop UI is a lightweight
// control panel, and software compositing avoids WebView2 GPU process crashes,
// DXGI surface loss on sleep/resume, and VRAM/TDR contention with reims-vgpu.
WebviewGpuIsDisabled: true,
OnSuspend: hooks.OnSuspend,
OnResume: hooks.OnResume,
CustomTheme: &windows.ThemeSettings{
DarkModeTitleBar: windows.RGB(28, 28, 30),
DarkModeTitleText: windows.RGB(245, 245, 247),
DarkModeBorder: windows.RGB(58, 58, 62),
},
},
OnStartup: func(ctx context.Context) {
releaseStartup()
hooks.OnStartup(ctx)
},
OnBeforeClose: hooks.OnBeforeClose,
OnShutdown: hooks.OnShutdown,
Bind: []any{
desktopApp,
},
})
if err != nil {
println("Error:", err.Error())
}
}