Bug 1735458 - Do not show mail notification on Windows if running fullscreen app. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D128427

--HG--
extra : amend_source : 3a9d3b7a844a384008d1239aaee8d96c430c8fc6
This commit is contained in:
Ping Chen 2021-10-19 22:59:51 +03:00
Родитель 95e44433c6
Коммит cbdacd1a75
4 изменённых файлов: 68 добавлений и 15 удалений

Просмотреть файл

@ -104,16 +104,41 @@ var gMockAlertsServiceFactory = {
},
};
let gMockWindowsIntegration = {
QueryInterface: ChromeUtils.generateQI([
"nsIMessengerOSIntegration",
"nsIMessengerWindowsIntegration",
]),
// Do not suppress notification, so that the tests can pass on Treeherder.
suppressNotification: false,
updateUnreadCount() {},
};
let gMockWindowsIntegrationFactory = {
createInstance() {
return gMockWindowsIntegration;
},
};
add_task(function setupModule(module) {
// Register the mock alerts service
Components.manager
.QueryInterface(Ci.nsIComponentRegistrar)
.registerFactory(
Components.ID("{1bda6c33-b089-43df-a8fd-111907d6385a}"),
"Mock Alerts Service",
"@mozilla.org/system-alerts-service;1",
gMockAlertsServiceFactory
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(
Components.ID("{1bda6c33-b089-43df-a8fd-111907d6385a}"),
"Mock Alerts Service",
"@mozilla.org/system-alerts-service;1",
gMockAlertsServiceFactory
);
if (Services.appinfo.OS == "WINNT") {
registrar.registerFactory(
Components.ID("{a1e1bf40-4275-46b5-897f-71c20b6931cd}"),
"",
"@mozilla.org/messenger/osintegration;1",
gMockWindowsIntegrationFactory
);
}
// Ensure we have enabled new mail notifications
remember_and_set_bool_pref("mail.biff.show_alert", true);

Просмотреть файл

@ -13,4 +13,7 @@ interface nsIMessengerWindowsIntegration : nsIMessengerOSIntegration {
void hideWindow(in nsIBaseWindow aWindow);
void showWindow(in mozIDOMWindowProxy aWindow);
/** Do not show notifications in some states, e.g. when running a fullscreen app. */
readonly attribute boolean suppressNotification;
};

Просмотреть файл

@ -50,13 +50,6 @@ class MailNotificationManager {
this._bundle = Services.strings.createBundle(
"chrome://messenger/locale/messenger.properties"
);
try {
this._osIntegration = Cc[
"@mozilla.org/messenger/osintegration;1"
].getService(Ci.nsIMessengerOSIntegration);
} catch (e) {
// We don't have OS integration on all platforms.
}
MailServices.mailSession.AddFolderListener(
this,
Ci.nsIFolderListener.intPropertyChanged
@ -78,6 +71,21 @@ class MailNotificationManager {
Services.obs.addObserver(this, "windows-refresh-badge-tray");
Services.prefs.addObserver("mail.biff.show_badge", this);
}
XPCOMUtils.defineLazyGetter(this, "_osIntegration", () => {
try {
let osIntegration = Cc[
"@mozilla.org/messenger/osintegration;1"
].getService(Ci.nsIMessengerOSIntegration);
if (AppConstants.platform == "win") {
osIntegration.QueryInterface(Ci.nsIMessengerWindowsIntegration);
}
return osIntegration;
} catch (e) {
// We don't have OS integration on all platforms.
return null;
}
});
}
observe(subject, topic, data) {
@ -133,6 +141,12 @@ class MailNotificationManager {
if (!Services.prefs.getBoolPref("mail.biff.show_alert")) {
return;
}
if (
AppConstants.platform == "win" &&
this._osIntegration.suppressNotification
) {
return;
}
this._logger.debug(
`onFolderIntPropertyChanged; property=${property}: ${oldValue} => ${newValue}, folder.URI=${folder.URI}`
@ -166,7 +180,7 @@ class MailNotificationManager {
}
/**
* Show an alert according the changed folder.
* Show an alert according to the changed folder.
* @param {nsIMsgFolder} changedFolder - The folder that emitted the change
* event, can be a root folder or a real folder.
*/

Просмотреть файл

@ -226,6 +226,17 @@ nsMessengerWinIntegration::ShowWindow(mozIDOMWindowProxy* aWindow) {
return NS_OK;
}
NS_IMETHODIMP
nsMessengerWinIntegration::GetSuppressNotification(bool* suppressNotification) {
*suppressNotification = false;
QUERY_USER_NOTIFICATION_STATE qstate;
if (SUCCEEDED(SHQueryUserNotificationState(&qstate)) &&
qstate != QUNS_ACCEPTS_NOTIFICATIONS) {
*suppressNotification = true;
}
return NS_OK;
}
NS_IMETHODIMP
nsMessengerWinIntegration::UpdateUnreadCount(uint32_t unreadCount,
const nsAString& unreadTooltip) {