155 lines
4.3 KiB
Go
155 lines
4.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"embed"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"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/windows"
|
|
)
|
|
|
|
//go:embed all:frontend/dist
|
|
var assets embed.FS
|
|
|
|
//go:embed 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) {
|
|
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,
|
|
Frameless: true,
|
|
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())
|
|
}
|
|
}
|