diff --git a/internal/frontend/qt/frontend_settings.go b/internal/frontend/qt/frontend_settings.go index 82a80233..3cdb8c84 100644 --- a/internal/frontend/qt/frontend_settings.go +++ b/internal/frontend/qt/frontend_settings.go @@ -29,15 +29,44 @@ import ( ) func (f *FrontendQt) setIsDiskCacheEnabled() { - //TODO + f.qml.SetIsDiskCacheEnabled(f.settings.GetBool(settings.CacheEnabledKey)) } func (f *FrontendQt) setDiskCachePath() { - //TODO + f.qml.SetDiskCachePath(f.settings.Get(settings.CacheLocationKey)) } func (f *FrontendQt) changeLocalCache(enableDiskCache bool, diskCachePath string) { - //TODO + defer f.qml.ChangeLocalCacheFinished() + defer f.setIsDiskCacheEnabled() + defer f.setDiskCachePath() + + if enableDiskCache != f.settings.GetBool(settings.CacheEnabledKey) { + if enableDiskCache { + if err := f.bridge.EnableCache(); err != nil { + f.log.WithError(err).Error("Cannot enable disk cache") + } + } else { + if err := f.bridge.DisableCache(); err != nil { + f.log.WithError(err).Error("Cannot disable disk cache") + } + } + } + + // If disk cache not enabled, or path not changed then no need to change location + if !enableDiskCache || diskCachePath == f.settings.Get(settings.CacheLocationKey) { + return + } + + if err := f.bridge.MigrateCache(f.settings.Get(settings.CacheLocationKey), diskCachePath); err != nil { + f.log.WithError(err).Error("The local cache location could not be changed.") + f.qml.CacheCantMove() + return + } + + f.settings.Set(settings.CacheLocationKey, diskCachePath) + f.qml.CacheLocationChangeSuccess() + f.restart() } func (f *FrontendQt) setIsAutostartOn() { diff --git a/internal/frontend/qt/qml_backend.go b/internal/frontend/qt/qml_backend.go index 01f9ce32..05a5fe03 100644 --- a/internal/frontend/qt/qml_backend.go +++ b/internal/frontend/qt/qml_backend.go @@ -164,7 +164,7 @@ func (q *QMLBackend) setup(f *FrontendQt) { f.setIsDiskCacheEnabled() f.setDiskCachePath() - q.ConnectChangeLocalCache(f.changeLocalCache) + q.ConnectChangeLocalCache(func(e bool, d string) { go f.changeLocalCache(e, d) }) f.setIsAutomaticUpdateOn() q.ConnectToggleAutomaticUpdate(func(m bool) { go f.toggleAutomaticUpdate(m) })