mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 07:48:38 +09:00
Bug 1216271 - Display a notification upon upgrade for users who currently allow notifications for at least one site
This commit is contained in:
parent
99d6131d72
commit
4f42ce57c9
2 changed files with 47 additions and 13 deletions
|
|
@ -39,6 +39,9 @@ Cu.import("resource://gre/modules/Services.jsm");
|
|||
["DateTimePickerHelper", "resource://gre/modules/DateTimePickerHelper.jsm"],
|
||||
].forEach(([name, resource]) => XPCOMUtils.defineLazyModuleGetter(this, name, resource));
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "AlertsService",
|
||||
"@mozilla.org/alerts-service;1", "nsIAlertsService");
|
||||
|
||||
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
||||
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
||||
|
||||
|
|
@ -825,16 +828,6 @@ BrowserGlue.prototype = {
|
|||
if (actions.indexOf("showAlert") == -1)
|
||||
return;
|
||||
|
||||
let notifier;
|
||||
try {
|
||||
notifier = Cc["@mozilla.org/alerts-service;1"].
|
||||
getService(Ci.nsIAlertsService);
|
||||
}
|
||||
catch (e) {
|
||||
// nsIAlertsService is not available for this platform
|
||||
return;
|
||||
}
|
||||
|
||||
let title = getNotifyString({propName: "alertTitle",
|
||||
stringName: "puAlertTitle",
|
||||
stringParams: [appName]});
|
||||
|
|
@ -856,10 +849,10 @@ BrowserGlue.prototype = {
|
|||
try {
|
||||
// This will throw NS_ERROR_NOT_AVAILABLE if the notification cannot
|
||||
// be displayed per the idl.
|
||||
notifier.showAlertNotification(null, title, text,
|
||||
true, url, clickCallback);
|
||||
AlertsService.showAlertNotification(null, title, text,
|
||||
}
|
||||
catch (e) {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -1191,7 +1184,7 @@ BrowserGlue.prototype = {
|
|||
},
|
||||
|
||||
_migrateUI: function BG__migrateUI() {
|
||||
const UI_VERSION = 15;
|
||||
const UI_VERSION = 17;
|
||||
const BROWSER_DOCURL = "chrome://browser/content/browser.xul#";
|
||||
let currentUIVersion = 0;
|
||||
try {
|
||||
|
|
@ -1386,6 +1379,10 @@ BrowserGlue.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
if (currentUIVersion < 17) {
|
||||
this._notifyNotificationsUpgrade();
|
||||
}
|
||||
|
||||
if (this._dirty)
|
||||
this._dataSource.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush();
|
||||
|
||||
|
|
@ -1396,6 +1393,41 @@ BrowserGlue.prototype = {
|
|||
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
|
||||
},
|
||||
|
||||
_hasExistingNotificationPermission: function BG__hasExistingNotificationPermission() {
|
||||
let enumerator = Services.perms.enumerator;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
|
||||
if (permission.type == "desktop-notification") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_notifyNotificationsUpgrade: function BG__notifyNotificationsUpgrade() {
|
||||
if (!this._hasExistingNotificationPermission()) {
|
||||
return;
|
||||
}
|
||||
function clickCallback(subject, topic, data) {
|
||||
if (topic != "alertclickcallback")
|
||||
return;
|
||||
let win = RecentWindow.getMostRecentBrowserWindow();
|
||||
win.openUILinkIn(data, "tab");
|
||||
}
|
||||
let imageURL = "chrome://browser/skin/web-notifications-icon.svg";
|
||||
let title = gBrowserBundle.GetStringFromName("webNotifications.upgradeTitle");
|
||||
let text = gBrowserBundle.GetStringFromName("webNotifications.upgradeInfo");
|
||||
let url = Services.urlFormatter.formatURLPref("browser.push.warning.infoURL");
|
||||
|
||||
try {
|
||||
AlertsService.showAlertNotification(imageURL, title, text,
|
||||
true, url, clickCallback);
|
||||
}
|
||||
catch (e) {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
},
|
||||
|
||||
_getPersist: function BG__getPersist(aSource, aProperty) {
|
||||
var target = this._dataSource.GetTarget(aSource, aProperty, true);
|
||||
if (target instanceof Ci.nsIRDFLiteral)
|
||||
|
|
|
|||
|
|
@ -304,6 +304,8 @@ webNotifications.alwaysShow.accesskey=A
|
|||
webNotifications.neverShow=Always Block Notifications
|
||||
webNotifications.neverShow.accesskey=N
|
||||
webNotifications.showFromSite=Would you like to show notifications from %S?
|
||||
webNotifications.upgradeTitle=Upgraded notifications
|
||||
webNotifications.upgradeInfo=You will receive notifications from sites, even those not open in a tab. Click to learn more.
|
||||
|
||||
# Pointer lock UI
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue