tidy and fix flow notation

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2017-05-02 21:29:19 +01:00
parent 61c338a233
commit 6367344181
3 changed files with 30 additions and 33 deletions

View File

@ -20,13 +20,11 @@ limitations under the License.
import VectorBasePlatform from './VectorBasePlatform'; import VectorBasePlatform from './VectorBasePlatform';
import dis from 'matrix-react-sdk/lib/dispatcher'; import dis from 'matrix-react-sdk/lib/dispatcher';
import q from 'q'; import q from 'q';
import electron, {remote} from 'electron';
const electron = require('electron');
const remote = electron.remote;
remote.autoUpdater.on('update-downloaded', onUpdateDownloaded); remote.autoUpdater.on('update-downloaded', onUpdateDownloaded);
function onUpdateDownloaded(ev, releaseNotes, ver, date, updateURL) { function onUpdateDownloaded(ev: Event, releaseNotes: string, ver: string, date: Date, updateURL: string) {
dis.dispatch({ dis.dispatch({
action: 'new_version', action: 'new_version',
currentVersion: remote.app.getVersion(), currentVersion: remote.app.getVersion(),
@ -35,7 +33,7 @@ function onUpdateDownloaded(ev, releaseNotes, ver, date, updateURL) {
}); });
} }
function platformFriendlyName() { function platformFriendlyName(): string {
console.log(window.process); console.log(window.process);
switch (window.process.platform) { switch (window.process.platform) {
case 'darwin': case 'darwin':
@ -72,11 +70,11 @@ export default class ElectronPlatform extends VectorBasePlatform {
} }
} }
supportsNotifications() : boolean { supportsNotifications(): boolean {
return true; return true;
} }
maySendNotifications() : boolean { maySendNotifications(): boolean {
return true; return true;
} }
@ -100,7 +98,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
icon: avatarUrl, icon: avatarUrl,
tag: 'vector', tag: 'vector',
silent: true, // we play our own sounds silent: true, // we play our own sounds
} },
); );
notification.onclick = function() { notification.onclick = function() {
@ -123,7 +121,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
notif.close(); notif.close();
} }
getAppVersion() { getAppVersion(): Promise<string> {
return q(remote.app.getVersion()); return q(remote.app.getVersion());
} }
@ -140,15 +138,15 @@ export default class ElectronPlatform extends VectorBasePlatform {
electron.ipcRenderer.send('install_update'); electron.ipcRenderer.send('install_update');
} }
getDefaultDeviceDisplayName() { getDefaultDeviceDisplayName(): string {
return 'Riot Desktop on ' + platformFriendlyName(); return 'Riot Desktop on ' + platformFriendlyName();
} }
screenCaptureErrorString() { screenCaptureErrorString(): ?string {
return null; return null;
} }
requestNotificationPermission() : Promise { requestNotificationPermission(): Promise<string> {
return q('granted'); return q('granted');
} }

View File

@ -44,7 +44,7 @@ export default class VectorBasePlatform extends BasePlatform {
* Get a sensible default display name for the * Get a sensible default display name for the
* device Vector is running on * device Vector is running on
*/ */
getDefaultDeviceDisplayName() { getDefaultDeviceDisplayName(): string {
return "Unknown device"; return "Unknown device";
} }
} }

View File

@ -52,7 +52,7 @@ export default class WebPlatform extends VectorBasePlatform {
} }
this.favicon.badge(notif, { this.favicon.badge(notif, {
bgColor: bgColor bgColor: bgColor,
}); });
} catch (e) { } catch (e) {
console.warn(`Failed to set badge count: ${e.message}`); console.warn(`Failed to set badge count: ${e.message}`);
@ -75,7 +75,7 @@ export default class WebPlatform extends VectorBasePlatform {
* Returns true if the platform supports displaying * Returns true if the platform supports displaying
* notifications, otherwise false. * notifications, otherwise false.
*/ */
supportsNotifications() : boolean { supportsNotifications(): boolean {
return Boolean(global.Notification); return Boolean(global.Notification);
} }
@ -83,8 +83,8 @@ export default class WebPlatform extends VectorBasePlatform {
* Returns true if the application currently has permission * Returns true if the application currently has permission
* to display notifications. Otherwise false. * to display notifications. Otherwise false.
*/ */
maySendNotifications() : boolean { maySendNotifications(): boolean {
return global.Notification.permission == 'granted'; return global.Notification.permission === 'granted';
} }
/** /**
@ -94,7 +94,7 @@ export default class WebPlatform extends VectorBasePlatform {
* that is 'granted' if the user allowed the request or * that is 'granted' if the user allowed the request or
* 'denied' otherwise. * 'denied' otherwise.
*/ */
requestNotificationPermission() : Promise { requestNotificationPermission(): Promise<string> {
// annoyingly, the latest spec says this returns a // annoyingly, the latest spec says this returns a
// promise, but this is only supported in Chrome 46 // promise, but this is only supported in Chrome 46
// and Firefox 47, so adapt the callback API. // and Firefox 47, so adapt the callback API.
@ -113,13 +113,13 @@ export default class WebPlatform extends VectorBasePlatform {
icon: avatarUrl, icon: avatarUrl,
tag: "vector", tag: "vector",
silent: true, // we play our own sounds silent: true, // we play our own sounds
} },
); );
notification.onclick = function() { notification.onclick = function() {
dis.dispatch({ dis.dispatch({
action: 'view_room', action: 'view_room',
room_id: room.roomId room_id: room.roomId,
}); });
global.focus(); global.focus();
notification.close(); notification.close();
@ -132,7 +132,7 @@ export default class WebPlatform extends VectorBasePlatform {
}, 5 * 1000); }, 5 * 1000);
} }
_getVersion() { _getVersion(): Promise<string> {
const deferred = q.defer(); const deferred = q.defer();
// We add a cachebuster to the request to make sure that we know about // We add a cachebuster to the request to make sure that we know about
@ -148,19 +148,19 @@ export default class WebPlatform extends VectorBasePlatform {
}, },
(err, response, body) => { (err, response, body) => {
if (err || response.status < 200 || response.status >= 300) { if (err || response.status < 200 || response.status >= 300) {
if (err == null) err = { status: response.status }; if (err === null) err = { status: response.status };
deferred.reject(err); deferred.reject(err);
return; return;
} }
const ver = body.trim(); const ver = body.trim();
deferred.resolve(ver); deferred.resolve(ver);
} },
); );
return deferred.promise; return deferred.promise;
} }
getAppVersion() { getAppVersion(): Promise<string> {
if (this.runningVersion !== null) { if (this.runningVersion !== null) {
return q(this.runningVersion); return q(this.runningVersion);
} }
@ -169,9 +169,9 @@ export default class WebPlatform extends VectorBasePlatform {
pollForUpdate() { pollForUpdate() {
this._getVersion().done((ver) => { this._getVersion().done((ver) => {
if (this.runningVersion == null) { if (this.runningVersion === null) {
this.runningVersion = ver; this.runningVersion = ver;
} else if (this.runningVersion != ver) { } else if (this.runningVersion !== ver) {
dis.dispatch({ dis.dispatch({
action: 'new_version', action: 'new_version',
currentVersion: this.runningVersion, currentVersion: this.runningVersion,
@ -187,19 +187,18 @@ export default class WebPlatform extends VectorBasePlatform {
window.location.reload(); window.location.reload();
} }
getDefaultDeviceDisplayName() { getDefaultDeviceDisplayName(): string {
// strip query-string and fragment from uri // strip query-string and fragment from uri
let u = url.parse(window.location.href); const u = url.parse(window.location.href);
u.search = ""; u.search = "";
u.hash = ""; u.hash = "";
let app_name = u.format(); const appName = u.format();
let ua = new UAParser(); const ua = new UAParser();
return app_name + " via " + ua.getBrowser().name + return `${appName} via ${ua.getBrowser().name} on ${ua.getOS().name}`;
" on " + ua.getOS().name;
} }
screenCaptureErrorString() { screenCaptureErrorString(): ?string {
// it won't work at all if you're not on HTTPS so whine whine whine // it won't work at all if you're not on HTTPS so whine whine whine
if (!global.window || global.window.location.protocol !== "https:") { if (!global.window || global.window.location.protocol !== "https:") {
return "You need to be using HTTPS to place a screen-sharing call."; return "You need to be using HTTPS to place a screen-sharing call.";