Kaynağa Gözat

Check for version updates on connecting

If the version has changed, show a dialog and reload the page on
confirmation.
Danilo Bargen 8 yıl önce
ebeveyn
işleme
a06e073f7e

+ 4 - 0
public/i18n/de.json

@@ -217,5 +217,9 @@
             "SHOW_PREVIEW": "Nachrichteninhalt in Benachrichtigungen anzeigen",
             "PLAY_SOUND": "Ton abspielen"
         }
+    },
+    "version": {
+        "NEW_VERSION": "Neue Version Verfügbar",
+        "NEW_VERSION_BODY": "Eine neue Version von Threema Web ({version}) ist verfügbar. Drücken Sie \"OK\" um die Seite neu zu laden."
     }
 }

+ 5 - 1
public/i18n/en.json

@@ -212,12 +212,16 @@
         "CHANGELOG_LINK_AFTER": "."
     },
     "settings": {
-        "SETTINGS":"Settings",
+        "SETTINGS": "Settings",
         "notifications": {
             "NOTIFICATIONS": "Notifications",
             "SHOW_NOTIFICATIONS": "Show desktop notifications",
             "SHOW_PREVIEW": "Show message contents in notifications",
             "PLAY_SOUND": "Play sound"
         }
+    },
+    "version": {
+        "NEW_VERSION": "New Version Available",
+        "NEW_VERSION_BODY": "A new version of Threema Web ({version}) is available. Click \"OK\" to reload the page."
     }
 }

+ 6 - 1
src/partials/welcome.ts

@@ -20,6 +20,7 @@ import {ControllerService} from '../services/controller';
 import {TrustedKeyStoreService} from '../services/keystore';
 import {PushService} from '../services/push';
 import {StateService} from '../services/state';
+import {VersionService} from '../services/version';
 import {WebClientService} from '../services/webclient';
 
 class DialogController {
@@ -68,7 +69,7 @@ class WelcomeController {
 
     public static $inject = [
         '$scope', '$state', '$stateParams', '$timeout', '$interval', '$log', '$window', '$mdDialog', '$translate',
-        'WebClientService', 'TrustedKeyStore', 'StateService', 'PushService', 'BrowserService',
+        'WebClientService', 'TrustedKeyStore', 'StateService', 'PushService', 'BrowserService', 'VersionService',
         'BROWSER_MIN_VERSIONS', 'ControllerService',
     ];
     constructor($scope: ng.IScope, $state: ng.ui.IStateService, $stateParams: threema.WelcomeStateParams,
@@ -78,6 +79,7 @@ class WelcomeController {
                 webClientService: WebClientService, TrustedKeyStore: TrustedKeyStoreService,
                 stateService: StateService, pushService: PushService,
                 browserService: BrowserService,
+                versionService: VersionService,
                 minVersions: threema.BrowserMinVersions,
                 controllerService: ControllerService) {
         controllerService.setControllerName('welcome');
@@ -130,6 +132,9 @@ class WelcomeController {
             this.showLocalStorageWarning();
         }
 
+        // Determine current version
+        versionService.initVersion();
+
         // Clear cache
         this.webClientService.clearCache();
 

+ 39 - 0
src/services/version.ts

@@ -44,6 +44,11 @@ export class VersionService {
      * Set the version by fetching the version.txt file.
      */
     public initVersion(): void {
+        if (this.version !== undefined) {
+            this.checkForUpdate();
+            return;
+        }
+
         this.fetchVersion()
             .then((version: string) => {
                 this.version = version;
@@ -82,4 +87,38 @@ export class VersionService {
         });
     }
 
+    /**
+     * Check for a version update. If the version was updated, show a dialog.
+     */
+    public checkForUpdate(): void {
+        this.$log.debug(this.logTag, 'Checking for version update...');
+        this.fetchVersion()
+            .then((version: string) => {
+                if (version !== this.version) {
+                    this.$log.warn(this.logTag,
+                        'A new version of Threema Web is available:',
+                        this.version, '->', version);
+                    this.notifyNewVersion(version);
+                }
+            })
+            .catch((error: string) => {
+                this.$log.error('Could not fetch version.txt:', error);
+            });
+    }
+
+    /**
+     * A new version is available!
+     */
+    private notifyNewVersion(version: string): void {
+        const confirm = this.$mdDialog.alert()
+            .title(this.$translate.instant('version.NEW_VERSION', {version: version}))
+            .textContent(this.$translate.instant('version.NEW_VERSION_BODY', {version: version}))
+            .ok(this.$translate.instant('common.OK'));
+        this.$mdDialog.show(confirm).then(() => {
+            this.$window.location.reload();
+        }, () => {
+            this.$window.location.reload();
+        });
+    }
+
 }

+ 1 - 1
src/services/webclient.ts

@@ -451,7 +451,7 @@ export class WebClientService {
                     this._requestInitialData();
 
                     // Fetch current version
-                    this.versionService.initVersion();
+                    this.versionService.checkForUpdate();
 
                     // Notify state service about data loading
                     this.stateService.updateConnectionBuildupState('loading');