Restore VRTW_Tool title; note discord mute regression
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user