mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +01:00
1bb2978a89
Summary: Fixes T4139. Adds a "Desktop Notifications" panel to settings. For now, we start with "Send Desktop Notifications Too" functionality. We can try to be fancy later and only send desktop notifications if the web app doesn't have focus, etc. Test Plan: Made some comments as a test user on a task and got purdy desktop notifications using Chrome. Then did it again with Firefox. Played around with permissions form with Chrome and got helpful information about what was up. Played around with Firefox and got similar results, except canceling the dialogue didn't invoke my handler code somehow. Oh Firefox! Reviewers: epriestley Reviewed By: epriestley Subscribers: rbalik, tycho.tatitscheff, joshuaspence, epriestley, Korvin Maniphest Tasks: T4139 Differential Revision: https://secure.phabricator.com/D13219
120 lines
3.6 KiB
JavaScript
120 lines
3.6 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-desktop-notifications-control
|
|
* @requires javelin-behavior
|
|
* javelin-stratcom
|
|
* javelin-dom
|
|
* javelin-uri
|
|
* phabricator-notification
|
|
*/
|
|
|
|
JX.behavior('desktop-notifications-control', function(config, statics) {
|
|
|
|
function findEl(id) {
|
|
var el = null;
|
|
try {
|
|
el = JX.$(id);
|
|
} catch (e) {
|
|
// not found
|
|
}
|
|
return el;
|
|
}
|
|
function updateFormStatus(permission) {
|
|
var statusEl = findEl(config.statusID);
|
|
if (!statusEl) {
|
|
return;
|
|
}
|
|
switch (permission) {
|
|
case 'default':
|
|
JX.DOM.setContent(statusEl.firstChild, config.cancelAsk);
|
|
break;
|
|
case 'granted':
|
|
JX.DOM.setContent(statusEl.firstChild, config.grantedAsk);
|
|
break;
|
|
case 'denied':
|
|
JX.DOM.setContent(statusEl.firstChild, config.deniedAsk);
|
|
break;
|
|
}
|
|
JX.DOM.show(statusEl);
|
|
}
|
|
|
|
function updateBrowserStatus(permission) {
|
|
var browserStatusEl = findEl(config.browserStatusID);
|
|
if (!browserStatusEl) {
|
|
return;
|
|
}
|
|
switch (permission) {
|
|
case 'default':
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-notice', true);
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-success', false);
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-error', false);
|
|
JX.DOM.setContent(browserStatusEl, JX.$H(config.defaultStatus));
|
|
break;
|
|
case 'granted':
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-success', true);
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-notice', false);
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-error', false);
|
|
JX.DOM.setContent(browserStatusEl, JX.$H(config.grantedStatus));
|
|
break;
|
|
case 'denied':
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-error', true);
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-notice', false);
|
|
JX.DOM.alterClass(browserStatusEl, 'phui-info-severity-success', false);
|
|
JX.DOM.setContent(browserStatusEl, JX.$H(config.deniedStatus));
|
|
break;
|
|
}
|
|
JX.DOM.show(browserStatusEl);
|
|
}
|
|
|
|
function installSelectListener() {
|
|
var controlEl = findEl(config.controlID);
|
|
if (!controlEl) {
|
|
return;
|
|
}
|
|
var select = JX.DOM.find(controlEl, 'select');
|
|
JX.DOM.listen(
|
|
select,
|
|
'change',
|
|
null,
|
|
function (e) {
|
|
if (!JX.Notification.supportsDesktopNotifications()) {
|
|
return;
|
|
}
|
|
var value = e.getTarget().value;
|
|
if (value == config.desktopMode) {
|
|
window.Notification.requestPermission(
|
|
function (permission) {
|
|
updateFormStatus(permission);
|
|
updateBrowserStatus(permission);
|
|
});
|
|
} else {
|
|
var statusEl = JX.$(config.statusID);
|
|
JX.DOM.hide(statusEl);
|
|
}
|
|
});
|
|
}
|
|
|
|
function install() {
|
|
JX.Stratcom.listen(
|
|
'click',
|
|
'desktop-notifications-permission-button',
|
|
function () {
|
|
window.Notification.requestPermission(
|
|
function (permission) {
|
|
updateFormStatus(permission);
|
|
updateBrowserStatus(permission);
|
|
});
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
statics.installed = statics.installed || install();
|
|
if (!JX.Notification.supportsDesktopNotifications()) {
|
|
var statusEl = JX.$(config.statusID);
|
|
JX.DOM.setContent(statusEl.firstChild, config.noSupport);
|
|
JX.DOM.show(statusEl);
|
|
} else {
|
|
updateBrowserStatus(window.Notification.permission);
|
|
}
|
|
installSelectListener();
|
|
});
|