From c786980454f6648de45a8193f0ec08d41ed71c0f Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 24 Nov 2016 16:46:15 +0000 Subject: [PATCH] Move getDefaultDeviceName into the Platforms So we can have a sensible device name on Electron --- src/vector/index.js | 16 +-------------- src/vector/platform/ElectronPlatform.js | 25 +++++++++++++++++++++++ src/vector/platform/VectorBasePlatform.js | 8 ++++++++ src/vector/platform/WebPlatform.js | 15 ++++++++++++++ 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 0ced93d57d..b791783b98 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -54,7 +54,6 @@ var UpdateChecker = require("./updater"); var q = require('q'); var request = require('browser-request'); -import UAParser from 'ua-parser-js'; import url from 'url'; import {parseQs, parseQsFromFragment} from './url_utils'; @@ -144,19 +143,6 @@ var makeRegistrationUrl = function() { '#/register'; } - -function getDefaultDeviceDisplayName() { - // strip query-string and fragment from uri - let u = url.parse(window.location.href); - u.search = ""; - u.hash = ""; - let app_name = u.format(); - - let ua = new UAParser(); - return app_name + " via " + ua.getBrowser().name + - " on " + ua.getOS().name; -} - window.addEventListener('hashchange', onHashChange); function getConfig() { @@ -262,7 +248,7 @@ async function loadApp() { startingFragmentQueryParams={fragparts.params} enableGuest={true} onLoadCompleted={onLoadCompleted} - defaultDeviceDisplayName={getDefaultDeviceDisplayName()} + defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()} />, document.getElementById('matrixchat') ); diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index c7455a7100..3894896a01 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -35,6 +35,27 @@ function onUpdateDownloaded(ev, releaseNotes, ver, date, updateURL) { }); } +function platformFriendlyName() { + console.log(window.process); + switch (window.process.platform) { + case 'darwin': + return 'macOS'; + case 'freebsd': + return 'FreeBSD'; + case 'openbsd': + return 'OpenBSD'; + case 'sunos': + return 'SunOS'; + case 'win32': + return 'Windows'; + default: + // Sorry, Linux users: you get lumped into here, + // but only because Linux's capitalisation is + // normal. We do care about you. + return window.process.platform[0].toUpperCase + window.process.platform.slice(1); + } +} + export default class ElectronPlatform extends VectorBasePlatform { setNotificationCount(count: number) { super.setNotificationCount(count); @@ -101,4 +122,8 @@ export default class ElectronPlatform extends VectorBasePlatform { // it should exit. electron.ipcRenderer.send('install_update'); } + + getDefaultDeviceDisplayName() { + return "Riot Desktop on " + platformFriendlyName(); + } } diff --git a/src/vector/platform/VectorBasePlatform.js b/src/vector/platform/VectorBasePlatform.js index d2ed8c344c..5240f3f583 100644 --- a/src/vector/platform/VectorBasePlatform.js +++ b/src/vector/platform/VectorBasePlatform.js @@ -39,4 +39,12 @@ export default class VectorBasePlatform extends BasePlatform { */ installUpdate() { } + + /** + * Get a sensible default display name for the + * device Vector is running on + */ + getDefaultDeviceDisplayName() { + return "Unknown device"; + } } diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index dec15869e7..9998f7c78f 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -23,6 +23,9 @@ import request from 'browser-request'; import dis from 'matrix-react-sdk/lib/dispatcher.js'; import q from 'q'; +import url from 'url'; +import UAParser from 'ua-parser-js'; + export default class WebPlatform extends VectorBasePlatform { constructor() { super(); @@ -180,4 +183,16 @@ export default class WebPlatform extends VectorBasePlatform { installUpdate() { window.location.reload(); } + + getDefaultDeviceDisplayName() { + // strip query-string and fragment from uri + let u = url.parse(window.location.href); + u.search = ""; + u.hash = ""; + let app_name = u.format(); + + let ua = new UAParser(); + return app_name + " via " + ua.getBrowser().name + + " on " + ua.getOS().name; + } }