Danilo Bargen преди 8 години
родител
ревизия
17d44d6b70
променени са 6 файла, в които са добавени 104 реда и са изтрити 42 реда
  1. 3 0
      karma.conf.js
  2. 2 0
      src/services.ts
  3. 85 0
      src/services/version.ts
  4. 8 42
      src/services/webclient.ts
  5. 3 0
      tests/service/webclient.js
  6. 3 0
      tests/testsuite.html

+ 3 - 0
karma.conf.js

@@ -6,6 +6,9 @@ module.exports = function(config) {
             'node_modules/angular/angular.js',
             'node_modules/angular-mocks/angular-mocks.js',
             'node_modules/angular-translate/dist/angular-translate.min.js',
+            'node_modules/angular-aria/angular-aria.min.js',
+            'node_modules/angular-animate/angular-animate.min.js',
+            'node_modules/angular-material/angular-material.min.js',
             'dist/app.js',
             'tests/filters.js',
             'tests/service/message.js',

+ 2 - 0
src/services.ts

@@ -33,6 +33,7 @@ import {StateService} from './services/state';
 import {StringService} from './services/string';
 import {TitleService} from './services/title';
 import {UriService} from './services/uri';
+import {VersionService} from './services/version';
 import {WebClientService} from './services/webclient';
 
 // Create services for the controller
@@ -58,4 +59,5 @@ angular.module('3ema.services', [])
 .service('SettingsService', SettingsService)
 .service('MediaboxService', MediaboxService)
 .service('UriService', UriService)
+.service('VersionService', VersionService)
 ;

+ 85 - 0
src/services/version.ts

@@ -0,0 +1,85 @@
+/**
+ * This file is part of Threema Web.
+ *
+ * Threema Web is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+export class VersionService {
+    public static $inject = ['$log', '$http', '$mdDialog', '$translate', '$window'];
+
+    private logTag: string = '[VersionService]';
+
+    private $log: ng.ILogService;
+    private $http: ng.IHttpService;
+    private $mdDialog: ng.material.IDialogService;
+    private $translate: ng.translate.ITranslateService;
+    private $window: ng.IWindowService;
+
+    private version: string;
+
+    constructor($log: ng.ILogService,
+                $http: ng.IHttpService,
+                $mdDialog: ng.material.IDialogService,
+                $translate: ng.translate.ITranslateService,
+                $window: ng.IWindowService) {
+        this.$log = $log;
+        this.$http = $http;
+        this.$mdDialog = $mdDialog;
+        this.$translate = $translate;
+        this.$window = $window;
+    }
+
+    /**
+     * Set the version by fetching the version.txt file.
+     */
+    public initVersion(): void {
+        this.fetchVersion()
+            .then((version: string) => {
+                this.version = version;
+                this.$log.info(this.logTag, 'Using Threema Web version', this.version);
+            })
+            .catch((error: string) => {
+                this.$log.error(this.logTag, 'Could not fetch version.txt:', error);
+            });
+    }
+
+    /**
+     * Fetch the version.txt file.
+     */
+    private fetchVersion(): Promise<string> {
+        return new Promise((resolve, reject) => {
+            const cacheBust = Math.floor(Math.random() * 1000000000);
+            this.$http({
+                method: 'GET',
+                url: 'version.txt?' + cacheBust,
+                cache: false,
+                responseType: 'text',
+                transformResponse: (data: string, headersGetter, statusCode) => {
+                    if (statusCode !== 200) {
+                        return reject('HTTP ' + statusCode);
+                    }
+                    return data.trim();
+                },
+            }).then(
+                (successResponse: ng.IHttpPromiseCallbackArg<string>) => {
+                    return resolve(successResponse.data);
+                },
+                (error: Error) => {
+                    return reject(error);
+                },
+            );
+        });
+    }
+
+}

+ 8 - 42
src/services/webclient.ts

@@ -29,6 +29,7 @@ import {QrCodeService} from './qrcode';
 import {ReceiverService} from './receiver';
 import {StateService} from './state';
 import {TitleService} from './title';
+import {VersionService} from './version';
 
 class WebClientDefault {
     private avatar: threema.AvatarRegistry = {
@@ -132,7 +133,6 @@ export class WebClientService {
     private $translate: ng.translate.ITranslateService;
     private $filter: any;
     private $timeout: ng.ITimeoutService;
-    private $http: ng.IHttpService;
 
     // Custom services
     private notificationService: NotificationService;
@@ -144,6 +144,7 @@ export class WebClientService {
     private qrCodeService: QrCodeService;
     private mimeService: MimeService;
     private receiverService: ReceiverService;
+    private versionService: VersionService;
 
     // State handling
     private startupPromise: ng.IDeferred<{}> = null; // TODO: deferred type
@@ -176,7 +177,7 @@ export class WebClientService {
     private pcHelper: PeerConnectionHelper = null;
     private deviceInfo: string = null;
     private trustedKeyStore: TrustedKeyStoreService;
-    private version = null;
+    public version = null;
 
     private blobCache = new Map<String, ArrayBuffer>();
     private loadingMessages = new Map<String, boolean>();
@@ -192,11 +193,11 @@ export class WebClientService {
     private requestPromises: Map<string, threema.PromiseCallbacks> = new Map();
 
     public static $inject = [
-        '$log', '$rootScope', '$q', '$state', '$window', '$translate', '$filter',
-        '$timeout', '$http',
+        '$log', '$rootScope', '$q', '$state', '$window', '$translate', '$filter', '$timeout',
         'Container', 'TrustedKeyStore',
         'StateService', 'NotificationService', 'MessageService', 'PushService', 'BrowserService',
         'TitleService', 'FingerPrintService', 'QrCodeService', 'MimeService', 'ReceiverService',
+        'VersionService',
         'CONFIG',
     ];
     constructor($log: ng.ILogService,
@@ -207,7 +208,6 @@ export class WebClientService {
                 $translate: ng.translate.ITranslateService,
                 $filter: ng.IFilterService,
                 $timeout: ng.ITimeoutService,
-                $http: ng.IHttpService,
                 container: threema.Container.Factory,
                 trustedKeyStore: TrustedKeyStoreService,
                 stateService: StateService,
@@ -220,6 +220,7 @@ export class WebClientService {
                 qrCodeService: QrCodeService,
                 mimeService: MimeService,
                 receiverService: ReceiverService,
+                VersionService: VersionService,
                 CONFIG: threema.Config) {
 
         // Angular services
@@ -231,7 +232,6 @@ export class WebClientService {
         this.$translate = $translate;
         this.$filter = $filter;
         this.$timeout = $timeout;
-        this.$http = $http;
 
         // Own services
         this.notificationService = notificationService;
@@ -243,6 +243,7 @@ export class WebClientService {
         this.qrCodeService = qrCodeService;
         this.mimeService = mimeService;
         this.receiverService = receiverService;
+        this.versionService = VersionService;
 
         // Configuration object
         this.config = CONFIG;
@@ -450,14 +451,7 @@ export class WebClientService {
                     this._requestInitialData();
 
                     // Fetch current version
-                    this.fetchVersion()
-                        .then((version: string) => {
-                            this.version = version;
-                            this.$log.info(this.logTag, 'Using Threema Web version', this.version);
-                        })
-                        .catch((error: string) => {
-                            this.$log.error(this.logTag, 'Could not fetch version.txt:', error);
-                        });
+                    this.versionService.initVersion();
 
                     // Notify state service about data loading
                     this.stateService.updateConnectionBuildupState('loading');
@@ -1309,34 +1303,6 @@ export class WebClientService {
         this.requestConversations();
     }
 
-    /**
-     * Fetch the version.txt file.
-     */
-    private fetchVersion(): Promise<string> {
-        return new Promise((resolve, reject) => {
-            const cacheBust = Math.floor(Math.random() * 1000000000);
-            this.$http({
-                method: 'GET',
-                url: 'version.txt?' + cacheBust,
-                cache: false,
-                responseType: 'text',
-                transformResponse: (data: string, headersGetter, statusCode) => {
-                    if (statusCode !== 200) {
-                        this.$log.error('Could not fetch version.txt: HTTP', statusCode);
-                    }
-                    return data.trim();
-                },
-            }).then(
-                (successResponse: ng.IHttpPromiseCallbackArg<string>) => {
-                    resolve(successResponse.data);
-                },
-                (error: Error) => {
-                    reject(error);
-                },
-            );
-        });
-    }
-
     private _receiveResponseReceivers(message: threema.WireMessage) {
         this.$log.debug('Received receiver response');
 

+ 3 - 0
tests/service/webclient.js

@@ -27,6 +27,9 @@ describe('WebClientService', function() {
         });
 
         // Load modules
+        module('ngAria');
+        module('ngAnimate');
+        module('ngMaterial');
         module('3ema.services');
         module('3ema.container');
 

+ 3 - 0
tests/testsuite.html

@@ -14,6 +14,9 @@
         <script src="../node_modules/angular/angular.js"></script>
         <script src="../node_modules/angular-mocks/angular-mocks.js"></script>
         <script src="../node_modules/angular-translate/dist/angular-translate.min.js"></script>
+        <script src="../node_modules/angular-material/angular-material.min.js"></script>
+        <script src="../node_modules/angular-animate/angular-animate.min.js"></script>
+        <script src="../node_modules/angular-aria/angular-aria.min.js"></script>
 
         <script src="../dist/app.js"></script>