Merge remote-tracking branch 'origin/develop' into dbkr/electron_3

pull/2535/head
David Baker 2016-11-02 19:46:02 +00:00
commit 275a55266b
2 changed files with 50 additions and 9 deletions

View File

@ -174,14 +174,27 @@ function getConfig() {
let deferred = q.defer();
request(
{ method: "GET", url: "config.json", json: true },
{ method: "GET", url: "config.json" },
(err, response, body) => {
if (err || response.status < 200 || response.status >= 300) {
// Lack of a config isn't an error, we should
// just use the defaults.
// Also treat a blank config as no config because
// we don't get 404s from file: URIs so this is the
// only way we can not fail if the file doesn't exist
// when loading from a file:// URI.
if (( err && err.response.status == 404) || body == '') {
deferred.resolve({});
}
deferred.reject({err: err, response: response});
return;
}
deferred.resolve(body);
// We parse the JSON ourselves rather than use the JSON
// parameter, since this throws a parse error on empty
// which breaks if there's no config.json and we're
// loading from the filesystem (see above).
deferred.resolve(JSON.parse(body));
}
);
@ -234,13 +247,7 @@ async function loadApp() {
try {
configJson = await getConfig();
} catch (e) {
// On 404 errors, carry on without a config,
// but on other errors, fail, otherwise it will
// lead to subtle errors where the app runs with
// the default config if it fails to fetch config.json.
if (e.response.status != 404) {
configError = e;
}
configError = e;
}
console.log("Vector starting at "+window.location);

View File

@ -65,6 +65,40 @@ export default class WebPlatform extends VectorBasePlatform {
this._updateFavicon();
}
/**
* Returns true if the platform supports displaying
* notifications, otherwise false.
*/
supportsNotifications() : boolean {
return Boolean(global.Notification);
}
/**
* Returns true if the application currently has permission
* to display notifications. Otherwise false.
*/
maySendNotifications() : boolean {
return global.Notification.permission == 'granted';
}
/**
* Requests permission to send notifications. Returns
* a promise that is resolved when the user has responded
* to the request. The promise has a single string argument
* that is 'granted' if the user allowed the request or
* 'denied' otherwise.
*/
requestNotificationPermission() : Promise {
// annoyingly, the latest spec says this returns a
// promise, but this is only supported in Chrome 46
// and Firefox 47, so adapt the callback API.
const defer = q.defer();
global.Notification.requestPermission((result) => {
defer.resolve(result);
});
return defer.promise;
}
displayNotification(title: string, msg: string, avatarUrl: string) {
const notification = new global.Notification(
title,