66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"conjure-os/lib/inputs"
|
|
"conjure-os/lib/models"
|
|
"conjure-os/lib/provider"
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
var games []models.Game
|
|
|
|
// App struct
|
|
type App struct {
|
|
ctx context.Context
|
|
}
|
|
|
|
// NewApp creates a new App application struct
|
|
func NewApp() *App {
|
|
return &App{}
|
|
}
|
|
|
|
// startup is called when the app starts. The context is saved
|
|
// so we can call the runtime methods
|
|
func (a *App) startup(ctx context.Context) {
|
|
a.ctx = ctx
|
|
inputs.Start()
|
|
provider.Update()
|
|
}
|
|
|
|
func (a *App) StartGame(id string) {
|
|
for _, game := range games {
|
|
if game.Id == id {
|
|
gamePath := provider.ExtractGame(game)
|
|
cmd := exec.Command(gamePath)
|
|
|
|
// Optional: attach current terminal's std streams
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
cmd.Stdin = os.Stdin
|
|
|
|
// Start the process
|
|
if err := cmd.Start(); err != nil {
|
|
fmt.Println("Failed to start:", err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Process started with PID %d\n", cmd.Process.Pid)
|
|
|
|
// Optional: wait for it to finish
|
|
if err := cmd.Wait(); err != nil {
|
|
fmt.Println("Process exited with error:", err)
|
|
} else {
|
|
fmt.Println("Process exited successfully.")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (a *App) LoadGames() []models.Game {
|
|
games = provider.GetConjureGameInfo()
|
|
return games
|
|
}
|