Restore VRTW_Tool title; note discord mute regression
This commit is contained in:
@@ -2,9 +2,14 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"vrc_osc_go/internal/common"
|
||||
)
|
||||
|
||||
type GuestStatus struct {
|
||||
@@ -48,6 +53,7 @@ func (t *GuestTracker) MarkJoin(name string, at time.Time) {
|
||||
s.Present = true
|
||||
s.LastJoin = at
|
||||
s.AbsentFor = ""
|
||||
_ = t.persistLocked()
|
||||
}
|
||||
|
||||
func (t *GuestTracker) MarkLeave(name string, at time.Time) {
|
||||
@@ -59,6 +65,7 @@ func (t *GuestTracker) MarkLeave(name string, at time.Time) {
|
||||
if !s.LastJoin.IsZero() {
|
||||
s.AbsentFor = humanSince(at)
|
||||
}
|
||||
_ = t.persistLocked()
|
||||
}
|
||||
|
||||
func (t *GuestTracker) Snapshot(now time.Time) []GuestStatus {
|
||||
@@ -76,6 +83,26 @@ func (t *GuestTracker) Snapshot(now time.Time) []GuestStatus {
|
||||
return out
|
||||
}
|
||||
|
||||
func (t *GuestTracker) persistLocked() error {
|
||||
dir := filepath.Join(common.RootDir(), "runtime")
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
snapshot := make([]GuestStatus, 0, len(t.items))
|
||||
for _, s := range t.items {
|
||||
cp := *s
|
||||
snapshot = append(snapshot, cp)
|
||||
}
|
||||
f, err := os.Create(filepath.Join(dir, "guest_snapshot.json"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
enc := json.NewEncoder(f)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(snapshot)
|
||||
}
|
||||
|
||||
func (t *GuestTracker) ensure(name string) *GuestStatus {
|
||||
if s, ok := t.items[name]; ok {
|
||||
return s
|
||||
|
||||
Reference in New Issue
Block a user