conjure-os/app.go
2025-06-30 20:43:07 -04:00

70 lines
1.4 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
}
func (a *App) LoadImage(gameId string, imageSrc string) provider.FileBlob {
return *provider.LoadImage(gameId, imageSrc)
}