Files
egutierrez 23c933bfa2 feat: persist last user + diagnostics + logging + icon + defensive whoami
Backend:
- last_user.go: writes/reads <UserConfigDir>/matrix_client_pc/last_user.txt.
  Login persists; Logout clears.
- GetLastUserID bind replaces fragile localStorage in App.tsx.
- GetDiagnostics bind: live snapshot (started, client_ready, crypto_init,
  sync_active, rooms_count, encrypted_rooms, dms_count, last_error).
- applog.go: slog to stderr + <UserConfigDir>/matrix_client_pc/app.log.
  GetLogTail + GetLogPath binds.
- matrix_service.go logs throughout Login/Start. After MatrixClientInit,
  if client.DeviceID empty -> retry whoami + persist back (defensive).
- main.go inits logger before wails.Run, OnShutdown logs close.

Frontend:
- App.tsx awaits GetLastUserID() instead of localStorage.
- HomeScreen.tsx Health modal (green stethoscope button) with HealthRow
  status dots — comprobar chats.
- Auto-relogin on token-rejected error in Start().

Icon:
- appicon.ico (Phosphor chat-circle + #7c3aed) generated via generate_app_icon.
- build/windows/icon.ico replaced (Wails embeds via windres).
- build/appicon.png regenerated from ico (256x256).

Refs: issues 0147 + 0148 + 0150 (partial). Fixes M_UNKNOWN_TOKEN auto-recovery.
2026-05-25 17:20:52 +02:00

42 lines
905 B
Go

package main
import (
"os"
"path/filepath"
"strings"
)
// lastUserFilePath returns the path to the file storing the last-logged-in user ID.
// Lives in <UserConfigDir>/matrix_client_pc/last_user.txt.
func lastUserFilePath() string {
cfg, err := os.UserConfigDir()
if err != nil {
cfg = filepath.Join(os.Getenv("HOME"), ".config")
}
return filepath.Join(cfg, "matrix_client_pc", "last_user.txt")
}
func readLastUser() string {
b, err := os.ReadFile(lastUserFilePath())
if err != nil {
return ""
}
return strings.TrimSpace(string(b))
}
func writeLastUser(userID string) error {
path := lastUserFilePath()
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
return err
}
return os.WriteFile(path, []byte(userID), 0o600)
}
func clearLastUser() error {
path := lastUserFilePath()
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil
}
return os.Remove(path)
}