Tighten verbose comments in Wails UI Go code

Shorten over-long godoc/inline comments across the client/ui tray and
services code: drop narrative restatement, legacy-Fyne tangents, and text
already evident from signatures and names. Keep only the non-obvious why
(concurrency/lock ordering, platform quirks, ordering constraints, the
profile-switch state table). No code changes.
This commit is contained in:
Zoltan Papp
2026-06-13 00:22:27 +02:00
parent c2b43b9cf0
commit edf7e2d04d
58 changed files with 972 additions and 2156 deletions
+19 -36
View File
@@ -2,21 +2,10 @@
package main
// Linux panel-theme detection for the monochrome tray icons.
//
// Wails v3's Linux SNI backend does not honour SetDarkModeIcon — its
// setDarkModeIcon just calls setIcon, so the last write wins regardless of
// panel theme (see pkg/application/systemtray_linux.go). The SNI spec itself
// also carries no reliable "panel is dark/light" hint for clients. So we
// detect the desktop's colour scheme ourselves and pick the black or white
// silhouette in iconForState.
//
// This file holds the (stateless) dark/light decision helpers; the live
// watcher that seeds and repaints on change lives in
// tray_theme_watcher_linux.go.
//
// color-scheme values (per the freedesktop appearance spec):
// 0 = no preference, 1 = prefer dark, 2 = prefer light.
// Wails v3's Linux SNI backend ignores SetDarkModeIcon (it just calls setIcon,
// last write wins) and SNI carries no panel dark/light hint, so we detect the
// desktop colour scheme ourselves and pick the silhouette in iconForState.
// The live watcher is in tray_theme_watcher_linux.go.
import (
"bufio"
@@ -28,17 +17,15 @@ import (
log "github.com/sirupsen/logrus"
)
// startTrayTheme wires the Linux panel-theme watcher into the tray: it seeds
// t.panelDark from the freedesktop Settings portal and repaints the icon on
// every live colour-scheme flip. Called from NewTray before the first
// applyIcon so the initial paint already uses the right silhouette.
// startTrayTheme seeds t.panelDark and repaints on colour-scheme flips. Must
// run before the first applyIcon so the initial paint uses the right silhouette.
func (t *Tray) startTrayTheme() {
w := startThemeWatcher(func() { t.applyIcon() })
t.panelDark = w.IsDark
}
// isKDE reports whether the current desktop is KDE Plasma. XDG_CURRENT_DESKTOP
// is a colon-separated list (e.g. "KDE", "ubuntu:KDE"), so we match the token.
// is a colon-separated list (e.g. "ubuntu:KDE"), so match per token.
func isKDE() bool {
for _, d := range strings.Split(os.Getenv("XDG_CURRENT_DESKTOP"), ":") {
if strings.EqualFold(strings.TrimSpace(d), "KDE") {
@@ -48,11 +35,9 @@ func isKDE() bool {
return false
}
// kdeglobalsPath returns the user kdeglobals path ($XDG_CONFIG_HOME/kdeglobals,
// or ~/.config/kdeglobals), the highest-priority file in KDE's config cascade.
// We read only this file rather than replaying the full XDG_CONFIG_DIRS +
// kdedefaults cascade: the user file is where Plasma writes the active scheme,
// and if the Complementary group is absent here we fall back to the portal.
// kdeglobalsPath returns the user kdeglobals path. We read only this file, not
// the full XDG_CONFIG_DIRS cascade: Plasma writes the active scheme here, and a
// missing Complementary group falls back to the portal.
func kdeglobalsPath() string {
if dir := os.Getenv("XDG_CONFIG_HOME"); dir != "" {
return filepath.Join(dir, "kdeglobals")
@@ -64,11 +49,10 @@ func kdeglobalsPath() string {
return filepath.Join(home, ".config", "kdeglobals")
}
// kdePanelIsDark reports whether the KDE Plasma panel is dark, reading the
// Breeze "Complementary" background — the colour Plasma actually paints the
// panel/system-tray with — from kdeglobals and deciding by its luma. The
// second return is false when this isn't KDE or the colour can't be read, so
// readDarkMode falls through to the portal/GTK path.
// kdePanelIsDark reports whether the KDE Plasma panel is dark by the luma of
// its "Complementary" background (the colour Plasma paints the tray with). ok
// is false when this isn't KDE or the colour can't be read, so the caller falls
// through to the portal/GTK path.
func kdePanelIsDark() (dark, ok bool) {
if !isKDE() {
return false, false
@@ -115,7 +99,7 @@ func readKdeComplementaryBackground(path string) (rgb [3]uint8, ok bool) {
return rgb, false
}
// parseRGB parses a "r,g,b" triple (KDE's colour format) into bytes.
// parseRGB parses KDE's "r,g,b" colour triple into bytes.
func parseRGB(s string) (rgb [3]uint8, ok bool) {
parts := strings.Split(s, ",")
if len(parts) != 3 {
@@ -131,16 +115,15 @@ func parseRGB(s string) (rgb [3]uint8, ok bool) {
return rgb, true
}
// isDarkRGB reports whether a colour is dark using the Rec. 601 relative luma.
// The 128 midpoint matches the perceptual split between needing a light vs a
// dark foreground.
// isDarkRGB reports whether a colour is dark via Rec. 601 luma, split at the
// 128 midpoint.
func isDarkRGB(r, g, b uint8) bool {
luma := (299*int(r) + 587*int(g) + 114*int(b)) / 1000
return luma < 128
}
// gtkThemeIsDark inspects the GTK_THEME env var. Empty (no override) is
// treated as dark to match the default-dark fallback used elsewhere.
// gtkThemeIsDark inspects the GTK_THEME env var. Empty (no override) is treated
// as dark to match the default-dark fallback used elsewhere.
func gtkThemeIsDark() bool {
theme := os.Getenv("GTK_THEME")
if theme == "" {