GODT-1412: Refactor paths and links

This commit is contained in:
Alexander Bilyak
2021-11-19 09:40:02 +00:00
committed by Jakub
parent 41f2ffa4ec
commit 551f5c3c18
10 changed files with 61 additions and 46 deletions

View File

@ -141,8 +141,8 @@ func (f *FrontendQt) NotifyManualUpdate(version updater.VersionInfo, canInstall
func (f *FrontendQt) SetVersion(version updater.VersionInfo) {
f.newVersionInfo = version
f.qml.SetReleaseNotesLink(version.ReleaseNotesPage)
f.qml.SetLandingPageLink(version.LandingPage)
f.qml.SetReleaseNotesLink(core.NewQUrl3(version.ReleaseNotesPage, core.QUrl__TolerantMode))
f.qml.SetLandingPageLink(core.NewQUrl3(version.LandingPage, core.QUrl__TolerantMode))
}
func (f *FrontendQt) NotifySilentUpdateInstalled() {

View File

@ -15,11 +15,14 @@
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
//go:build build_qt
// +build build_qt
package qt
import "github.com/therecipe/qt/core"
import (
"github.com/therecipe/qt/core"
)
func (f *FrontendQt) setVersion() {
f.qml.SetVersion(f.programVersion)
@ -31,11 +34,12 @@ func (f *FrontendQt) setLogsPath() {
f.log.WithError(err).Error("Cannot update path folder")
return
}
f.qml.SetLogsPath(path)
f.qml.SetLogsPath(core.QUrl_FromLocalFile(path))
}
func (f *FrontendQt) setLicensePath() {
f.qml.SetLicensePath(f.locations.GetLicenseFilePath())
f.qml.SetLicensePath(core.QUrl_FromLocalFile(f.locations.GetLicenseFilePath()))
}
func (f *FrontendQt) setCurrentEmailClient() {

View File

@ -21,12 +21,14 @@
package qt
import (
"runtime"
"time"
"github.com/ProtonMail/proton-bridge/internal/config/settings"
"github.com/ProtonMail/proton-bridge/internal/frontend/clientconfig"
"github.com/ProtonMail/proton-bridge/pkg/keychain"
"github.com/ProtonMail/proton-bridge/pkg/ports"
"github.com/therecipe/qt/core"
)
func (f *FrontendQt) setIsDiskCacheEnabled() {
@ -34,10 +36,10 @@ func (f *FrontendQt) setIsDiskCacheEnabled() {
}
func (f *FrontendQt) setDiskCachePath() {
f.qml.SetDiskCachePath(f.settings.Get(settings.CacheLocationKey))
f.qml.SetDiskCachePath(core.QUrl_FromLocalFile(f.settings.Get(settings.CacheLocationKey)))
}
func (f *FrontendQt) changeLocalCache(enableDiskCache bool, diskCachePath string) {
func (f *FrontendQt) changeLocalCache(enableDiskCache bool, diskCachePath *core.QUrl) {
defer f.qml.ChangeLocalCacheFinished()
defer f.setIsDiskCacheEnabled()
defer f.setDiskCachePath()
@ -54,18 +56,23 @@ func (f *FrontendQt) changeLocalCache(enableDiskCache bool, diskCachePath string
}
}
_diskCachePath := diskCachePath.Path(core.QUrl__FullyDecoded)
if (runtime.GOOS == "windows") && (_diskCachePath[0] == '/') {
_diskCachePath = _diskCachePath[1:]
}
// If disk cache not enabled, or path not changed then no need to change location
if !enableDiskCache || diskCachePath == f.settings.Get(settings.CacheLocationKey) {
if !enableDiskCache || _diskCachePath == f.settings.Get(settings.CacheLocationKey) {
return
}
if err := f.bridge.MigrateCache(f.settings.Get(settings.CacheLocationKey), diskCachePath); err != nil {
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.settings.Set(settings.CacheLocationKey, _diskCachePath)
f.qml.CacheLocationChangeSuccess()
f.restart()
}

View File

@ -80,14 +80,14 @@ type QMLBackend struct {
_ func() `slot:"checkUpdates"`
_ func() `signal:"checkUpdatesFinished"`
_ bool `property:"isDiskCacheEnabled"`
_ string `property:"diskCachePath"`
_ func() `signal:"cacheUnavailable"`
_ func() `signal:"cacheCantMove"`
_ func() `signal:"cacheLocationChangeSuccess"`
_ func() `signal:"diskFull"`
_ func(enableDiskCache bool, diskCachePath string) `slot:"changeLocalCache"`
_ func() `signal:"changeLocalCacheFinished"`
_ bool `property:"isDiskCacheEnabled"`
_ core.QUrl `property:"diskCachePath"`
_ func() `signal:"cacheUnavailable"`
_ func() `signal:"cacheCantMove"`
_ func() `signal:"cacheLocationChangeSuccess"`
_ func() `signal:"diskFull"`
_ func(enableDiskCache bool, diskCachePath core.QUrl) `slot:"changeLocalCache"`
_ func() `signal:"changeLocalCacheFinished"`
_ bool `property:"isAutomaticUpdateOn"`
_ func(makeItActive bool) `slot:"toggleAutomaticUpdate"`
@ -118,11 +118,11 @@ type QMLBackend struct {
_ func() `slot:"triggerReset"`
_ func() `signal:"resetFinished"`
_ string `property:"version"`
_ string `property:"logsPath"`
_ string `property:"licensePath"`
_ string `property:"releaseNotesLink"`
_ string `property:"landingPageLink"`
_ string `property:"version"`
_ core.QUrl `property:"logsPath"`
_ core.QUrl `property:"licensePath"`
_ core.QUrl `property:"releaseNotesLink"`
_ core.QUrl `property:"landingPageLink"`
_ string `property:"currentEmailClient"`
_ func() `slot:"updateCurrentMailClient"`
@ -207,7 +207,7 @@ func (q *QMLBackend) setup(f *FrontendQt) {
f.setIsDiskCacheEnabled()
f.setDiskCachePath()
q.ConnectChangeLocalCache(func(e bool, d string) {
q.ConnectChangeLocalCache(func(e bool, d *core.QUrl) {
go func() {
defer f.panicHandler.HandlePanic()
f.changeLocalCache(e, d)