Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c56192141 |
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"fyne.io/systray"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
@@ -120,19 +121,34 @@ func toggleMute(dg *discordgo.Session, cfg *Config, muted bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func run() {
|
||||
// Log to file next to the executable so errors are visible even without a console.
|
||||
func setupLogging() {
|
||||
// Try exe directory first, fall back to temp dir (e.g. if installed in Program Files).
|
||||
var dirs []string
|
||||
if exe, err := os.Executable(); err == nil {
|
||||
logPath := filepath.Join(filepath.Dir(exe), "discord-lobby-mute.log")
|
||||
if f, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644); err == nil {
|
||||
dirs = append(dirs, filepath.Dir(exe))
|
||||
}
|
||||
dirs = append(dirs, os.TempDir())
|
||||
|
||||
for _, dir := range dirs {
|
||||
logPath := filepath.Join(dir, "discord-lobby-mute.log")
|
||||
f, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
log.SetOutput(io.MultiWriter(os.Stderr, f))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func run() {
|
||||
setupLogging()
|
||||
log.Println("starting")
|
||||
|
||||
cfg, err := loadConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("config loaded")
|
||||
|
||||
dg, err := discordgo.New("Bot " + cfg.Token)
|
||||
if err != nil {
|
||||
@@ -145,13 +161,18 @@ func run() {
|
||||
close(ready)
|
||||
})
|
||||
|
||||
log.Println("connecting to Discord...")
|
||||
if err := dg.Open(); err != nil {
|
||||
log.Fatalf("connect to Discord: %v", err)
|
||||
}
|
||||
defer dg.Close()
|
||||
|
||||
<-ready
|
||||
log.Println("Connected to Discord.")
|
||||
select {
|
||||
case <-ready:
|
||||
case <-time.After(30 * time.Second):
|
||||
log.Fatal("timed out waiting for Discord ready — check token and network connection")
|
||||
}
|
||||
log.Println("connected to Discord")
|
||||
|
||||
keydownCh, err := startHotkey(cfg.Keybind)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user