GODT-1158: adding cache on disk signals

This commit is contained in:
Jakub
2021-09-13 17:04:41 +02:00
parent f65e050588
commit 85c06809d2
2 changed files with 33 additions and 4 deletions

View File

@ -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() {

View File

@ -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) })