Merge remote-tracking branch 'origin/develop' into dbkr/electron_3
This commit is contained in:
commit
275a55266b
|
@ -174,14 +174,27 @@ function getConfig() {
|
||||||
let deferred = q.defer();
|
let deferred = q.defer();
|
||||||
|
|
||||||
request(
|
request(
|
||||||
{ method: "GET", url: "config.json", json: true },
|
{ method: "GET", url: "config.json" },
|
||||||
(err, response, body) => {
|
(err, response, body) => {
|
||||||
if (err || response.status < 200 || response.status >= 300) {
|
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});
|
deferred.reject({err: err, response: response});
|
||||||
return;
|
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 {
|
try {
|
||||||
configJson = await getConfig();
|
configJson = await getConfig();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// On 404 errors, carry on without a config,
|
configError = e;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Vector starting at "+window.location);
|
console.log("Vector starting at "+window.location);
|
||||||
|
|
|
@ -65,6 +65,40 @@ export default class WebPlatform extends VectorBasePlatform {
|
||||||
this._updateFavicon();
|
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) {
|
displayNotification(title: string, msg: string, avatarUrl: string) {
|
||||||
const notification = new global.Notification(
|
const notification = new global.Notification(
|
||||||
title,
|
title,
|
||||||
|
|
Loading…
Reference in New Issue