Skip to content

Commit

Permalink
Fix ficsit-cli not being initialized early enough in production
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Feb 4, 2024
1 parent 74d4adf commit 45dc26f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
22 changes: 13 additions & 9 deletions backend/ficsitcli/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -57,7 +62,6 @@ func (f *ficsitCLI) Init() error {
wailsRuntime.EventsEmit(appCommon.AppContext, "isGameRunning", f.isGameRunning)
}
}()
return nil
}

func (f *ficsitCLI) setProgress(p *Progress) {
Expand Down
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 45dc26f

Please sign in to comment.