Add -reload-theme CLI flag to re-apply the current theme file (#860)
* Add -reload-theme CLI flag to re-apply theme via IPC Sends a reload-theme IPC message to a running instance, causing it to call fyne.CurrentApp().Settings().SetTheme(m.theme). Follows the same callback pattern as -show (OnReactivate) and quit (OnExit). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * actually re-read theme file --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
497c61e724
commit
e21908cd24
+11
-1
@@ -60,6 +60,7 @@ type App struct {
|
||||
// UI callbacks to be set in main
|
||||
OnReactivate func()
|
||||
OnExit func()
|
||||
OnReloadTheme func()
|
||||
|
||||
appName string
|
||||
displayAppName string
|
||||
@@ -227,7 +228,8 @@ func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleas
|
||||
ipcRatingHandler,
|
||||
a.ServerManager,
|
||||
a.callOnReactivate,
|
||||
func() { _ = a.callOnExit() })
|
||||
func() { _ = a.callOnExit() },
|
||||
a.callOnReloadTheme)
|
||||
go a.ipcServer.Serve(listener)
|
||||
} else {
|
||||
log.Printf("error starting IPC server: %s", err.Error())
|
||||
@@ -336,6 +338,12 @@ func (a *App) callOnReactivate() {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) callOnReloadTheme() {
|
||||
if a.OnReloadTheme != nil {
|
||||
a.OnReloadTheme()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) callOnExit() error {
|
||||
if a.OnExit == nil {
|
||||
return errors.New("no quit handler registered")
|
||||
@@ -658,6 +666,8 @@ func (a *App) checkFlagsAndSendIPCMsg(cli *ipc.Client) error {
|
||||
return cli.PauseAfterCurrent()
|
||||
case *FlagShow:
|
||||
return cli.Show()
|
||||
case *FlagReloadTheme:
|
||||
return cli.ReloadTheme()
|
||||
case VolumeCLIArg >= 0:
|
||||
return cli.SetVolume(VolumeCLIArg)
|
||||
case VolumePctCLIArg != 0:
|
||||
|
||||
@@ -32,6 +32,7 @@ var (
|
||||
FlagPauseAfterCurrent = flag.Bool("pause-after-current", false, "pause playback after current track")
|
||||
FlagStartMinimized = flag.Bool("start-minimized", false, "start app minimized")
|
||||
FlagShow = flag.Bool("show", false, "show minimized app")
|
||||
FlagReloadTheme = flag.Bool("reload-theme", false, "reload the current theme")
|
||||
FlagShuffle = flag.Bool("shuffle", false, "shuffle the tracklist (to be used with either -play-album-by-id or -play-playlist-by-id)")
|
||||
FlagVersion = flag.Bool("version", false, "print app version and exit")
|
||||
FlagHelp = flag.Bool("help", false, "print command line options and exit")
|
||||
|
||||
@@ -26,6 +26,7 @@ const (
|
||||
VolumePath = "/volume" // ?v=<vol>
|
||||
VolumeAdjustPath = "/volume/adjust" // ?pct=<+/- percentage>
|
||||
ShowPath = "/window/show"
|
||||
ReloadThemePath = "/window/reload-theme"
|
||||
QuitPath = "/window/quit"
|
||||
RateCurrentTrackPath = "/current_track/rate" // ?r=<rating 0-5>
|
||||
)
|
||||
|
||||
@@ -128,6 +128,11 @@ func (c *Client) Show() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) ReloadTheme() error {
|
||||
_, err := c.sendRequest(ReloadThemePath)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) Quit() error {
|
||||
_, err := c.sendRequest(QuitPath)
|
||||
return err
|
||||
|
||||
@@ -47,10 +47,11 @@ type serverImpl struct {
|
||||
sm ServerManager
|
||||
showFn func()
|
||||
quitFn func()
|
||||
reloadThemeFn func()
|
||||
}
|
||||
|
||||
func NewServer(pbHandler PlaybackHandler, rateFn func(int), sm ServerManager, showFn, quitFn func()) IPCServer {
|
||||
s := &serverImpl{pbHandler: pbHandler, rateFn: rateFn, sm: sm, showFn: showFn, quitFn: quitFn}
|
||||
func NewServer(pbHandler PlaybackHandler, rateFn func(int), sm ServerManager, showFn, quitFn, reloadThemeFn func()) IPCServer {
|
||||
s := &serverImpl{pbHandler: pbHandler, rateFn: rateFn, sm: sm, showFn: showFn, quitFn: quitFn, reloadThemeFn: reloadThemeFn}
|
||||
s.server = &http.Server{
|
||||
Handler: s.createHandler(),
|
||||
}
|
||||
@@ -77,6 +78,7 @@ func (s *serverImpl) createHandler() http.Handler {
|
||||
m.HandleFunc(ShowPath, s.makeSimpleEndpointHandler(func() {
|
||||
s.showFn()
|
||||
}))
|
||||
m.HandleFunc(ReloadThemePath, s.makeSimpleEndpointHandler(s.reloadThemeFn))
|
||||
m.HandleFunc(QuitPath, s.makeSimpleEndpointHandler(func() {
|
||||
s.quitFn()
|
||||
}))
|
||||
|
||||
@@ -110,6 +110,7 @@ func main() {
|
||||
mainWindow.Window.SetMaster()
|
||||
myApp.OnReactivate = util.FyneDoFunc(mainWindow.Show)
|
||||
myApp.OnExit = util.FyneDoFunc(mainWindow.Quit)
|
||||
myApp.OnReloadTheme = util.FyneDoFunc(mainWindow.ReloadTheme)
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
windowStartupTasks := sync.OnceFunc(func() {
|
||||
|
||||
@@ -273,6 +273,11 @@ func (m *MainWindow) setInitialSize() {
|
||||
m.Window.Resize(m.DesiredSize())
|
||||
}
|
||||
|
||||
func (m *MainWindow) ReloadTheme() {
|
||||
m.theme.ReloadThemeFile()
|
||||
fyne.CurrentApp().Settings().SetTheme(m.theme)
|
||||
}
|
||||
|
||||
func (m *MainWindow) StartupPage() controller.Route {
|
||||
switch m.App.Config.Application.StartupPage {
|
||||
case "Artists":
|
||||
|
||||
@@ -110,6 +110,11 @@ func NewMyTheme(config *backend.ThemeConfig, themeFileDir string) *MyTheme {
|
||||
return m
|
||||
}
|
||||
|
||||
// ReloadThemeFile reloads the currently loaded theme file.
|
||||
func (m *MyTheme) ReloadThemeFile() {
|
||||
m.loadedThemeFile = nil
|
||||
}
|
||||
|
||||
func (m *MyTheme) Color(name fyne.ThemeColorName, defVariant fyne.ThemeVariant) color.Color {
|
||||
// load theme file if necessary
|
||||
if m.loadedThemeFile == nil || m.config.ThemeFile != m.loadedThemeFilename {
|
||||
|
||||
Reference in New Issue
Block a user