add button to Advanced settings tab to clear caches
This commit is contained in:
+17
-1
@@ -32,6 +32,7 @@ const (
|
||||
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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user