Bug 1794475 - Part 1: Add a default dismiss button when there's no action r=nrishel,fluent-reviewers,bolsson

Differential Revision: https://phabricator.services.mozilla.com/D183516
This commit is contained in:
Kagami Sascha Rosylight 2023-07-19 20:31:13 +00:00
Родитель 9172df82a5
Коммит 7cc8d2e95a
3 изменённых файлов: 36 добавлений и 2 удалений

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

@ -6,3 +6,7 @@ alert-close =
.tooltiptext = Close this notification
alert-settings-title =
.tooltiptext = Settings
## Reminder Notifications
notification-default-dismiss = Dismiss

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

@ -22,6 +22,7 @@
#include "mozilla/Tokenizer.h"
#include "mozilla/Unused.h"
#include "mozilla/WindowsVersion.h"
#include "mozilla/intl/Localization.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsAppRunner.h"
#include "nsDirectoryServiceDefs.h"
@ -631,6 +632,25 @@ ComPtr<IXmlDocument> ToastNotificationHandler::CreateToastXmlDocument() {
NS_ENSURE_TRUE(success, nullptr);
}
// Windows ignores scenario=reminder added by mRequiredInteraction if
// there's no non-contextmenu activationType=background action.
if (mRequireInteraction && !mActions.Length()) {
nsTArray<nsCString> resIds = {
"toolkit/global/alert.ftl"_ns,
};
RefPtr<intl::Localization> l10n = intl::Localization::Create(resIds, true);
IgnoredErrorResult rv;
nsAutoCString closeTitle;
l10n->FormatValueSync("notification-default-dismiss"_ns, {}, closeTitle,
rv);
NS_ENSURE_TRUE(!rv.Failed(), nullptr);
NS_ENSURE_TRUE(
AddActionNode(toastXml, actionsNode, NS_ConvertUTF8toUTF16(closeTitle),
launchArg, u""_ns, u""_ns, u"background"_ns),
nullptr);
}
ComPtr<IXmlNode> appendedChild;
hr = toastNodeRoot->AppendChild(actionsNode.Get(), &appendedChild);
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);

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

@ -287,14 +287,24 @@ function testAlert(when, { serverEnabled, profD, isBackgroundTaskMode } = {}) {
);
alert = makeAlert({ name, title, text, imageURL, requireInteraction: true });
expected = `<toast scenario="reminder" launch="launch"><visual><binding template="ToastImageAndText03"><image id="1" src="file:///image.png"/><text id="1">title</text><text id="2">text</text></binding></visual><actions>${settingsAction}</actions></toast>`;
expected = `<toast scenario="reminder" launch="launch"><visual><binding template="ToastImageAndText03"><image id="1" src="file:///image.png"/><text id="1">title</text><text id="2">text</text></binding></visual><actions>${settingsAction}<action content="Dismiss"/></actions></toast>`;
Assert.deepEqual(
[
expected.replace("<actions></actions>", "<actions/>"),
{
launch: parsedArgumentString({ action: "" }),
actions: Object.fromEntries(
[parsedSettingsAction()].filter(x => x.length)
[
parsedSettingsAction(),
[
"Dismiss",
{
content: "Dismiss",
arguments: { "": undefined },
activationType: "background",
},
],
].filter(x => x.length)
),
},
],