diff --git a/backend/app.go b/backend/app.go index e5cf402..dbef621 100644 --- a/backend/app.go +++ b/backend/app.go @@ -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) diff --git a/res/translations/en.json b/res/translations/en.json index a3ded54..a0c3299 100644 --- a/res/translations/en.json +++ b/res/translations/en.json @@ -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", diff --git a/res/translations/es.json b/res/translations/es.json index 187bcf3..bb52125 100644 --- a/res/translations/es.json +++ b/res/translations/es.json @@ -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", diff --git a/res/translations/fr.json b/res/translations/fr.json index b57c904..7dc1b94 100644 --- a/res/translations/fr.json +++ b/res/translations/fr.json @@ -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", diff --git a/ui/controller/controller.go b/ui/controller/controller.go index 83b56e5..03263b4 100644 --- a/ui/controller/controller.go +++ b/ui/controller/controller.go @@ -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() { diff --git a/ui/dialogs/settingsdialog.go b/ui/dialogs/settingsdialog.go index bd252e7..2e81666 100644 --- a/ui/dialogs/settingsdialog.go +++ b/ui/dialogs/settingsdialog.go @@ -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) {