Pārlūkot izejas kodu

Enhance BrowserService.description for use in TroubleshootingController

Lennart Grahl 6 gadi atpakaļ
vecāks
revīzija
bc4e00fffe

+ 2 - 9
src/controllers/troubleshooting.ts

@@ -135,15 +135,8 @@ export class TroubleshootingController extends DialogController {
 
         // Send as file to *SUPPORT
         const browser = this.browserService.getBrowser();
-        let browserShortInfo = 'unknown';
-        if (browser.wasDetermined()) {
-            browserShortInfo = `${browser.name}-${browser.version}`;
-            if (browser.mobile) {
-                browserShortInfo += '-mobile';
-            }
-        }
         const message: threema.FileMessageData = {
-            name: `webclient-${this.config.VERSION}-${browserShortInfo}.log`,
+            name: `webclient-${this.config.VERSION}-${browser.description('-')}.log`,
             fileType: 'text/plain',
             size: log.byteLength,
             data: arrayToBuffer(log),
@@ -190,7 +183,7 @@ export class TroubleshootingController extends DialogController {
     }
 
     /**
-     * Serialise the memory log.
+     * Serialise the memory log and add some metadata.
      */
     private getLog(): string {
         const records = this.logService.memory.getRecords();

+ 2 - 2
src/helpers/browser_info.ts

@@ -38,7 +38,7 @@ export class BrowserInfo {
         return this.name !== null && this.version !== null;
     }
 
-    public description(): string {
+    public description(separator: string = ' '): string {
         if (this.name === null) {
             return 'Unknown';
         }
@@ -72,7 +72,7 @@ export class BrowserInfo {
         if (this.mobile) {
             description += ' [Mobile]';
         }
-        return description;
+        return description.split(' ').join(separator);
     }
 
     /**

+ 10 - 0
tests/service/browser.js

@@ -135,4 +135,14 @@ describe('BrowserService', function() {
         expect(browser.description()).toEqual('Safari 10 [Mobile]');
     });
 
+    it('with dash as separator', () => {
+        const ua = 'Mozilla/5.0 (iPad; CPU OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) FxiOS/8.3b5826 Mobile/14A403 Safari/602.1.50';
+        const service = testUserAgent(ua);
+        const browser = service.getBrowser();
+        expect(browser.name).toBe(BrowserName.FirefoxIos);
+        expect(browser.version).toEqual(8);
+        expect(browser.mobile).toBe(true);
+        expect(browser.description('-')).toEqual('Firefox-(iOS)-8-[Mobile]');
+    });
+
 });