Skip to content

Commit

Permalink
feat: Return game title from RunURL and log it
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Aug 6, 2022
1 parent 154d9f0 commit 05e7be1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/joinme.click-launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ func main() {
Msg("Checked status for")
}
} else if len(args) == 1 {
err := gameRouter.RunURL(args[0])
title, err := gameRouter.RunURL(args[0])
if err != nil {
log.Error().
Err(err).
Str("game", title.String()).
Str("url", args[0]).
Msg("Game could not be launched")
} else {
log.Info().
Str("game", title.String()).
Str("url", args[0]).
Msg("Successfully launched game")
Msg("Game launched")
}
}

Expand Down
15 changes: 15 additions & 0 deletions internal/domain/game_title.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package domain

import (
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -58,6 +59,13 @@ func (t GameTitle) GetMod(slug string) *GameMod {
return nil
}

func (t *GameTitle) String() string {
if t == nil {
return "nil"
}
return fmt.Sprintf("%s (%s)", t.Name, t.ProtocolScheme)
}

func MakeMod(name string, slug string, finderConfigs []software_finder.Config) GameMod {
return GameMod{
Name: name,
Expand Down Expand Up @@ -85,3 +93,10 @@ func (m GameMod) ComputeFinderConfigs(gameInstallPath string) []software_finder.
}
return computedConfigs
}

func (m *GameMod) String() string {
if m == nil {
return "nil"
}
return fmt.Sprintf("%s (%s)", m.Name, strings.ToLower(m.Slug))
}
16 changes: 8 additions & 8 deletions internal/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,31 +212,31 @@ func (r GameRouter) getHandlerCommand() (string, error) {
return fmt.Sprintf("\"%s\" \"%%1\"", launcherPath), nil
}

func (r GameRouter) RunURL(commandLineUrl string) error {
func (r GameRouter) RunURL(commandLineUrl string) (*domain.GameTitle, error) {
u, err := url.Parse(commandLineUrl)
if err != nil {
return err
return nil, err
}

gameTitle, ok := r.GameTitles[u.Scheme]
if !ok {
return fmt.Errorf("game not supported: %s", u.Scheme)
return nil, fmt.Errorf("game not supported: %s", u.Scheme)
}

if err = r.ensurePrerequisites(gameTitle, u); err != nil {
return err
return &gameTitle, err
}

action, err := r.getActionFromURL(u)
if err != nil {
return err
return &gameTitle, err
}

switch action {
case ActionLaunchOnly:
return r.startGame(gameTitle, u, game_launcher.LaunchTypeLaunchOnly)
return &gameTitle, r.startGame(gameTitle, u, game_launcher.LaunchTypeLaunchOnly)
default:
return r.startGame(gameTitle, u, game_launcher.LaunchTypeLaunchAndJoin)
return &gameTitle, r.startGame(gameTitle, u, game_launcher.LaunchTypeLaunchAndJoin)
}
}

Expand Down Expand Up @@ -303,7 +303,7 @@ func (r GameRouter) ensureModIsSupportedAndInstalledIfGiven(gameTitle domain.Gam
return err
}
if !modInstalled {
return fmt.Errorf("mod not installed: %s (%s)", mod.Name, strings.ToLower(mod.Slug))
return fmt.Errorf("mod not installed: %s", mod.Name)
}

return nil
Expand Down

0 comments on commit 05e7be1

Please sign in to comment.