add button to Advanced settings tab to clear caches

This commit is contained in:
Drew Weymouth
2025-11-07 19:48:09 -08:00
parent 360391e832
commit 0ff57513c2
6 changed files with 34 additions and 5 deletions
+21 -5
View File
@@ -28,10 +28,11 @@ import (
)
const (
configFile = "config.toml"
portableDir = "supersonic_portable"
savedQueueFile = "saved_queue.json"
themesDir = "themes"
configFile = "config.toml"
portableDir = "supersonic_portable"
savedQueueFile = "saved_queue.json"
themesDir = "themes"
audioCacheSubdir = "audio"
)
var (
@@ -146,7 +147,7 @@ func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleas
a.ServerManager = NewServerManager(appName, appVersion, a.Config, !portableMode && a.Config.Application.EnablePasswordStorage)
a.ImageManager = NewImageManager(a.bgrndCtx, a.ServerManager, cacheDir)
if a.Config.Playback.UseWaveformSeekbar {
ac, err := NewAudioCache(a.bgrndCtx, a.ServerManager, filepath.Join(cacheDir, "audio"))
ac, err := NewAudioCache(a.bgrndCtx, a.ServerManager, filepath.Join(cacheDir, audioCacheSubdir))
if err != nil {
log.Printf("failed to create audio cache: %s", err.Error())
}
@@ -247,6 +248,21 @@ func (a *App) ThemesDir() string {
return filepath.Join(a.configDir, themesDir)
}
func (a *App) ClearCaches() {
if a.cacheDir != "" {
entries, _ := os.ReadDir(a.cacheDir)
for _, e := range entries {
// The audio cache directory is necessary for
// proper playback of enqueued tracks, and also
// doesn't accumulate more than a few entries.
// Leave it alone.
if e.Name() != audioCacheSubdir {
_ = os.RemoveAll(filepath.Join(a.cacheDir, e.Name()))
}
}
}
}
func checkPortablePath() string {
if p, err := os.Executable(); err == nil {
pdirPath := path.Join(filepath.Dir(p), portableDir)
+1
View File
@@ -47,6 +47,7 @@
"Cast to device": "Cast to device",
"Channels": "Channels",
"Check for Updates": "Check for Updates",
"Clear caches": "Clear caches",
"Close": "Close",
"Close to system tray": "Close to system tray",
"Comment": "Comment",
+1
View File
@@ -35,6 +35,7 @@
"Broadcast": "Transmisión",
"Cancel": "Cancelar",
"Check for Updates": "Buscar actualizaciones",
"Clear caches": "Borrar cachés",
"Close": "Cerrar",
"Close to system tray": "Cerrar a la bandeja del sistema",
"Comment": "Comentario",
+1
View File
@@ -47,6 +47,7 @@
"Cast to device": "Diffuser sur un appareil",
"Channels": "Canaux",
"Check for Updates": "Vérifier les mises à jour",
"Clear caches": "Vider les caches",
"Close": "Fermer",
"Close to system tray": "Réduire dans la barre d'état à la fermeture",
"Comment": "Commentaire",
+1
View File
@@ -347,6 +347,7 @@ func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func(), themeFiles map
c.App.LocalPlayer.SetEqualizer(eq)
}
dlg.OnPageNeedsRefresh = c.RefreshPageFunc
dlg.OnClearCaches = func() { go c.App.ClearCaches() }
pop := widget.NewModalPopUp(dlg, c.MainWindow.Canvas())
fynetooltip.AddPopUpToolTipLayer(pop)
dlg.OnDismiss = func() {
+9
View File
@@ -38,6 +38,7 @@ type SettingsDialog struct {
OnDismiss func()
OnEqualizerSettingsChanged func()
OnPageNeedsRefresh func()
OnClearCaches func()
config *backend.Config
audioDevices []mpv.AudioDevice
@@ -610,10 +611,18 @@ func (s *SettingsDialog) createAdvancedTab() *container.TabItem {
}
percentEntry.Text = strconv.Itoa(s.config.Application.MaxImageCacheSizeMB)
clearCaches := widget.NewButton(lang.L("Clear caches"), func() {
if s.OnClearCaches != nil {
s.OnClearCaches()
}
})
imgCacheCfg := container.NewHBox(
widget.NewLabel(lang.L("Maximum image cache size")),
percentEntry,
widget.NewLabel("MB"),
layout.NewSpacer(),
clearCaches,
)
osMediaAPIs := widget.NewCheck(lang.L("Enable OS media player integration"), func(b bool) {