diff --git a/backend/ficsitcli/wrapper.go b/backend/ficsitcli/wrapper.go index ef1a782c..8e9a575e 100644 --- a/backend/ficsitcli/wrapper.go +++ b/backend/ficsitcli/wrapper.go @@ -23,22 +23,27 @@ type ficsitCLI struct { isGameRunning bool } -var FicsitCLI = &ficsitCLI{} +var FicsitCLI *ficsitCLI -func (f *ficsitCLI) Init() error { - if f.ficsitCli != nil { - return fmt.Errorf("FicsitCLIWrapper already initialized") +func Init() error { + if FicsitCLI != nil { + return nil } - var err error - f.ficsitCli, err = cli.InitCLI(false) + ficsitCli, err := cli.InitCLI(false) if err != nil { return fmt.Errorf("failed to initialize ficsit-cli: %w", err) } - f.ficsitCli.Provider.(*provider.MixedProvider).Offline = settings.Settings.Offline - err = f.initInstallations() + ficsitCli.Provider.(*provider.MixedProvider).Offline = settings.Settings.Offline + + FicsitCLI = &ficsitCLI{ficsitCli: ficsitCli} + err = FicsitCLI.initInstallations() if err != nil { return fmt.Errorf("failed to initialize installations: %w", err) } + return nil +} + +func (f *ficsitCLI) StartGameRunningWatcher() { gameRunningTicker := time.NewTicker(5 * time.Second) go func() { for range gameRunningTicker.C { @@ -57,7 +62,6 @@ func (f *ficsitCLI) Init() error { wailsRuntime.EventsEmit(appCommon.AppContext, "isGameRunning", f.isGameRunning) } }() - return nil } func (f *ficsitCLI) setProgress(p *Progress) { diff --git a/main.go b/main.go index a5c32fef..e05c834d 100644 --- a/main.go +++ b/main.go @@ -61,6 +61,13 @@ func main() { } } + err = ficsitcli.Init() + if err != nil { + slog.Error("failed to initialize ficsit-cli", slog.Any("error", err)) + _ = dialog.Error("Failed to initialize ficsit-cli: %s", err.Error()) + os.Exit(1) + } + windowStartState := options.Normal if settings.Settings.Maximized { windowStartState = options.Maximised @@ -98,12 +105,7 @@ func main() { app.App.WatchWindow() //nolint:contextcheck go websocket.ListenAndServeWebsocket() - err := ficsitcli.FicsitCLI.Init() //nolint:contextcheck - if err != nil { - slog.Error("failed to create bindings", slog.Any("error", err)) - _ = dialog.Error("Failed to create bindings: %s", err.Error()) - os.Exit(1) - } + ficsitcli.FicsitCLI.StartGameRunningWatcher() //nolint:contextcheck }, OnDomReady: func(ctx context.Context) { backend.ProcessArguments(os.Args[1:]) //nolint:contextcheck