GODT-1508: Splash screen for rebranding.

* Use old keychain until manual update.
* Improve desktop files migration for windows and linux.
* Revert, need admin rights to change desktop and start menu files.
This commit is contained in:
Jakub
2022-05-04 09:58:44 +02:00
parent 7d41062ae9
commit 865ac44037
15 changed files with 3240 additions and 252 deletions

View File

@ -18,16 +18,11 @@
package base
import (
"errors"
"os"
"path/filepath"
"runtime"
"github.com/Masterminds/semver/v3"
"github.com/ProtonMail/proton-bridge/internal/config/settings"
"github.com/ProtonMail/proton-bridge/internal/constants"
"github.com/ProtonMail/proton-bridge/internal/locations"
"github.com/ProtonMail/proton-bridge/pkg/keychain"
"github.com/sirupsen/logrus"
)
@ -112,122 +107,6 @@ func migrateUpdatesFrom16x(configName string, locations *locations.Locations) er
return moveIfExists(oldUpdatesPath, newUpdatesPath)
}
// migrateMacKeychainBefore220 deals with write access restriction to mac
// keychain passwords which are caused by application renaming. The old
// passwords are copied under new name in order to have write access afer
// renaming.
func migrateMacKeychainBefore220(settingsObj *settings.Settings, keychainName string) error {
l := logrus.WithField("pkg", "app/base/migration")
if runtime.GOOS != "darwin" {
return nil
}
if shouldContinue, err := isBefore220(settingsObj); !shouldContinue || err != nil {
return err
}
l.Warn("Migrating mac keychain")
helperConstructor, ok := keychain.Helpers["macos-keychain"]
if !ok {
return errors.New("cannot find macos-keychain helper")
}
oldKC, err := helperConstructor("ProtonMailBridgeService")
if err != nil {
l.WithError(err).Error("Keychain constructor failed")
return err
}
idByURL, err := oldKC.List()
if err != nil {
l.WithError(err).Error("List old keychain failed")
return err
}
newKC, err := keychain.NewKeychain(settingsObj, keychainName)
if err != nil {
return err
}
for url, id := range idByURL {
li := l.WithField("id", id).WithField("url", url)
userID, secret, err := oldKC.Get(url)
if err != nil {
li.WithField("userID", userID).
WithField("err", err).
Error("Faild to get old item")
continue
}
if _, _, err := newKC.Get(userID); err == nil {
li.Warn("Skipping migration, item already exists.")
continue
}
if err := newKC.Put(userID, secret); err != nil {
li.WithError(err).Error("Failed to migrate user")
}
li.Info("Item migrated")
}
return nil
}
// migrateStartup220 removes old startup links. The creation of new links is
// handled by bridge initialisation.
func migrateStartup220(settingsObj *settings.Settings) error {
if shouldContinue, err := isBefore220(settingsObj); !shouldContinue || err != nil {
return err
}
logrus.WithField("pkg", "app/base/migration").Warn("Migrating autostartup links")
path, err := os.UserHomeDir()
if err != nil {
return err
}
switch runtime.GOOS {
case "windows":
path = filepath.Join(path, `AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ProtonMail Bridge.lnk`)
case "linux":
path = filepath.Join(path, `.config/autostart/ProtonMail Bridge.desktop`)
case "darwin":
path = filepath.Join(path, `Library/LaunchAgents/ProtonMail Bridge.plist`)
default:
return errors.New("unknown GOOS")
}
return os.Remove(path)
}
// isBefore220 decide if last used version was older than 2.2.0. If cannot decide it returns false with error.
func isBefore220(settingsObj *settings.Settings) (bool, error) {
lastUsedVersion := settingsObj.Get(settings.LastVersionKey)
// Skipping migration: it is first bridge start or cache was cleared.
if lastUsedVersion == "" {
return false, nil
}
v220 := semver.MustParse("2.2.0")
lastVer, err := semver.NewVersion(lastUsedVersion)
// Skipping migration: Should not happen but cannot decide what to do.
if err != nil {
return false, err
}
// Skipping migration: 2.2.0>= was already used hence old stuff was already migrated.
if !lastVer.LessThan(v220) {
return false, nil
}
return true, nil
}
func moveIfExists(source, destination string) error {
l := logrus.WithField("source", source).WithField("destination", destination)