Restore VRTW_Tool title; note discord mute regression

This commit is contained in:
every_holiday
2026-06-24 03:08:30 +09:00
parent ab9551c241
commit 63700d9d29
7 changed files with 202 additions and 42 deletions

View File

@@ -4,6 +4,8 @@ import (
"flag"
"log"
"os"
"os/exec"
"path/filepath"
"vrc_osc_go/internal/app"
)
@@ -11,12 +13,30 @@ import (
func main() {
var configPath string
var mode string
var noGUI bool
flag.StringVar(&configPath, "config", "config/config.toml", "path to config.toml")
flag.StringVar(&mode, "mode", "", "generate-json or extract-log")
flag.BoolVar(&noGUI, "no-gui", false, "do not launch the GUI companion")
flag.Parse()
if mode == "" && !noGUI {
launchGUI()
}
if err := app.Run(configPath, mode); err != nil {
log.SetOutput(os.Stderr)
log.Fatalf("vrc_osc_go: %v", err)
}
}
func launchGUI() {
exe, err := os.Executable()
if err != nil {
return
}
gui := filepath.Join(filepath.Dir(exe), "vrc_osc_gui.exe")
if _, err := os.Stat(gui); err != nil {
return
}
_ = exec.Command(gui).Start()
}

View File

@@ -5,20 +5,21 @@ import (
"fmt"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"
"vrc_osc_go/internal/app"
)
func main() {
go func() {
if err := app.Run("config/config.toml", ""); err != nil {
log.Printf("backend stopped: %v", err)
}
}()
func runtimeDir() string {
exe, err := os.Executable()
if err != nil {
return "runtime"
}
return filepath.Join(filepath.Dir(exe), "runtime")
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", handleIndex)
mux.HandleFunc("/api/state", handleState)
@@ -36,7 +37,7 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="3">
<title>VRC_OSC GUI</title>
<title>VRTW_Tool</title>
<style>
body{font-family:sans-serif;background:#111;color:#eee;margin:20px}
.grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
@@ -49,7 +50,7 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
</style>
</head>
<body>
<h1>VRC_OSC GUI</h1>
<h1>VRTW_Tool</h1>
<div id="root">loading...</div>
<script>
const sortKey = 'vrc_osc_gui_sort';
@@ -149,19 +150,42 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
}
func handleState(w http.ResponseWriter, r *http.Request) {
s := app.SnapshotRuntime()
guests := []app.GuestStatus{}
if t := app.GetGuestTracker(); t != nil {
guests = t.Snapshot(time.Now())
statePath := filepath.Join(runtimeDir(), "state.json")
body, err := os.ReadFile(statePath)
if err != nil {
_ = json.NewEncoder(w).Encode(map[string]any{
"world": "",
"discord_muted": false,
"ocr": "",
"translate": "",
"guests": []any{},
"guest_count": 0,
"error": err.Error(),
})
return
}
_ = json.NewEncoder(w).Encode(map[string]any{
"world": s.CurrentWorld,
"discord_muted": s.DiscordMuted,
"ocr": s.LastOCRText,
"translate": s.LastTranslate,
"guests": guests,
"guest_count": len(guests),
})
var state map[string]any
if err := json.Unmarshal(body, &state); err != nil {
_ = json.NewEncoder(w).Encode(map[string]any{"error": err.Error()})
return
}
guests := loadGuestSnapshot()
state["guests"] = guests
state["guest_count"] = len(guests)
_ = json.NewEncoder(w).Encode(state)
}
func loadGuestSnapshot() []map[string]any {
statePath := filepath.Join(runtimeDir(), "guest_snapshot.json")
body, err := os.ReadFile(statePath)
if err != nil {
return []map[string]any{}
}
var guests []map[string]any
if err := json.Unmarshal(body, &guests); err != nil {
return []map[string]any{}
}
return guests
}
func openBrowser(url string) {