Add history calendar export view

This commit is contained in:
every_holiday
2026-06-30 11:03:17 +09:00
parent ae426244e0
commit 3ff33e40e3
4 changed files with 3506 additions and 255 deletions

View File

@@ -7,6 +7,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
"vrc_osc_go/internal/common"
)
@@ -32,14 +33,20 @@ type VrcLogConfig struct {
}
type GUIConfig struct {
TopMost bool
FontSize int
TopMost bool
FontSize int
AutoUnmuteOnSelfLeave bool
RefreshIntervalValue int
RefreshIntervalUnit string
HistoryRegex string
HistoryFromDate string
HistoryToDate string
}
func Load(path string) (*Config, error) {
cfg := &Config{
OSC: OSCConfig{Host: "127.0.0.1", Port: 9001},
GUI: GUIConfig{FontSize: 18},
GUI: GUIConfig{FontSize: 18, RefreshIntervalValue: 2, RefreshIntervalUnit: "sec"},
}
if path == "" {
path = filepath.Join(common.RootDir(), "config", "config.toml")
@@ -114,9 +121,29 @@ func Load(path string) (*Config, error) {
if n, err := strconv.Atoi(val); err == nil && n > 0 {
cfg.GUI.FontSize = n
}
case "auto_unmute_on_self_leave":
cfg.GUI.AutoUnmuteOnSelfLeave = parseBool(val, cfg.GUI.AutoUnmuteOnSelfLeave)
case "refresh_interval_value":
if n, err := strconv.Atoi(val); err == nil && n > 0 {
cfg.GUI.RefreshIntervalValue = n
}
case "refresh_interval_unit":
cfg.GUI.RefreshIntervalUnit = normalizeRefreshIntervalUnit(val)
case "history_regex":
cfg.GUI.HistoryRegex = val
case "history_from":
cfg.GUI.HistoryFromDate = normalizeHistoryDate(val)
case "history_to":
cfg.GUI.HistoryToDate = normalizeHistoryDate(val)
}
}
}
if cfg.GUI.RefreshIntervalValue <= 0 {
cfg.GUI.RefreshIntervalValue = 2
}
cfg.GUI.RefreshIntervalUnit = normalizeRefreshIntervalUnit(cfg.GUI.RefreshIntervalUnit)
cfg.GUI.HistoryFromDate = normalizeHistoryDate(cfg.GUI.HistoryFromDate)
cfg.GUI.HistoryToDate = normalizeHistoryDate(cfg.GUI.HistoryToDate)
if cfg.VrcLog.GuestFile != "" {
if !filepath.IsAbs(cfg.VrcLog.GuestFile) {
cfg.VrcLog.GuestFile = filepath.Join(common.RootDir(), cfg.VrcLog.GuestFile)
@@ -222,13 +249,56 @@ func upsertGUISection(existing string, gui GUIConfig) string {
}
func appendGUISection(out *[]string, gui GUIConfig) {
gui.RefreshIntervalUnit = normalizeRefreshIntervalUnit(gui.RefreshIntervalUnit)
if gui.RefreshIntervalValue <= 0 {
gui.RefreshIntervalValue = 2
}
*out = append(*out,
"[gui]",
fmt.Sprintf("top_most = %t", gui.TopMost),
fmt.Sprintf("font_size = %d", gui.FontSize),
fmt.Sprintf("auto_unmute_on_self_leave = %t", gui.AutoUnmuteOnSelfLeave),
fmt.Sprintf("refresh_interval_value = %d", gui.RefreshIntervalValue),
fmt.Sprintf("refresh_interval_unit = %q", gui.RefreshIntervalUnit),
fmt.Sprintf("history_regex = %q", gui.HistoryRegex),
fmt.Sprintf("history_from = %q", gui.HistoryFromDate),
fmt.Sprintf("history_to = %q", gui.HistoryToDate),
)
}
func normalizeRefreshIntervalUnit(unit string) string {
switch strings.ToLower(strings.TrimSpace(unit)) {
case "min", "minute", "minutes":
return "min"
default:
return "sec"
}
}
func (g GUIConfig) RefreshInterval() time.Duration {
value := g.RefreshIntervalValue
if value <= 0 {
value = 2
}
switch normalizeRefreshIntervalUnit(g.RefreshIntervalUnit) {
case "min":
return time.Duration(value) * time.Minute
default:
return time.Duration(value) * time.Second
}
}
func normalizeHistoryDate(value string) string {
value = strings.TrimSpace(value)
if value == "" {
return ""
}
if _, err := time.Parse("2006-01-02", value); err != nil {
return ""
}
return value
}
func loadLines(path string) ([]string, error) {
data, err := os.ReadFile(path)
if err != nil {