Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move getDefaultDeviceName into the Platforms #2643

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/vector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -262,7 +248,7 @@ async function loadApp() {
startingFragmentQueryParams={fragparts.params}
enableGuest={true}
onLoadCompleted={onLoadCompleted}
defaultDeviceDisplayName={getDefaultDeviceDisplayName()}
defaultDeviceDisplayName={PlatformPeg.get().getDefaultDeviceDisplayName()}
/>,
document.getElementById('matrixchat')
);
Expand Down
25 changes: 25 additions & 0 deletions src/vector/platform/ElectronPlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MacOS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope: http://www.apple.com/uk/macos/sierra/ #branding #lowercase #flatdesign

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#bollocks

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);
Expand Down Expand Up @@ -101,4 +122,8 @@ export default class ElectronPlatform extends VectorBasePlatform {
// it should exit.
electron.ipcRenderer.send('install_update');
}

getDefaultDeviceDisplayName() {
return "Riot Desktop on " + platformFriendlyName();
}
}
8 changes: 8 additions & 0 deletions src/vector/platform/VectorBasePlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
15 changes: 15 additions & 0 deletions src/vector/platform/WebPlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}