Bug 1805514 - Part 1: Support launch_action in Windows native toast notifications. r=barret

`launch_action` is both top-level (when the toast is clicked) and
per-action (when a button is clicked).

Differential Revision: https://phabricator.services.mozilla.com/D182312
This commit is contained in:
Nick Alexander
2023-07-15 02:34:05 +00:00
parent 37c5e5fc4f
commit bd3b0949b0
6 changed files with 149 additions and 3 deletions

View File

@@ -59,6 +59,22 @@
"type": "string",
"format": "moz-url-format"
},
"launch_action": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "The launch action to be performed when Firefox is launched."
},
"data": {
"type": "object"
}
},
"required": [
"type"
],
"additionalProperties": true
},
"requireInteraction": {
"type": "boolean",
"description": "Whether the toast notification should remain active until the user clicks or dismisses it, rather than closing automatically."
@@ -92,6 +108,22 @@
"windowsSystemActivationType": {
"type": "boolean",
"description": "Whether to have Windows process the given `action`."
},
"launch_action": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "The launch action to be performed when Firefox is launched."
},
"data": {
"type": "object"
}
},
"required": [
"type"
],
"additionalProperties": true
}
},
"required": [

View File

@@ -993,6 +993,22 @@
"type": "string",
"format": "moz-url-format"
},
"launch_action": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "The launch action to be performed when Firefox is launched."
},
"data": {
"type": "object"
}
},
"required": [
"type"
],
"additionalProperties": true
},
"requireInteraction": {
"type": "boolean",
"description": "Whether the toast notification should remain active until the user clicks or dismisses it, rather than closing automatically."
@@ -1026,6 +1042,22 @@
"windowsSystemActivationType": {
"type": "boolean",
"description": "Whether to have Windows process the given `action`."
},
"launch_action": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "The launch action to be performed when Firefox is launched."
},
"data": {
"type": "object"
}
},
"required": [
"type"
],
"additionalProperties": true
}
},
"required": [

View File

@@ -32,6 +32,20 @@
"type": "string",
"format": "moz-url-format"
},
"launch_action": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "The launch action to be performed when Firefox is launched."
},
"data": {
"type": "object"
}
},
"required": ["type"],
"additionalProperties": true
},
"requireInteraction": {
"type": "boolean",
"description": "Whether the toast notification should remain active until the user clicks or dismisses it, rather than closing automatically."
@@ -65,6 +79,20 @@
"windowsSystemActivationType": {
"type": "boolean",
"description": "Whether to have Windows process the given `action`."
},
"launch_action": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "The launch action to be performed when Firefox is launched."
},
"data": {
"type": "object"
}
},
"required": ["type"],
"additionalProperties": true
}
},
"required": ["action", "title"],

View File

@@ -576,6 +576,44 @@ const MESSAGES = () => [
trigger: { id: "backgroundTaskMessage" },
frequency: { lifetime: 3 },
},
{
id: "TEST_TOAST_NOTIFICATION2",
weight: 100,
template: "toast_notification",
content: {
title: "Launch action on toast click and on action button click",
body: "Body",
image_url:
"https://firefox-settings-attachments.cdn.mozilla.net/main-workspace/ms-images/a3c640c8-7594-4bb2-bc18-8b4744f3aaf2.gif",
launch_action: {
type: "OPEN_URL",
data: { args: "https://mozilla.org", where: "window" },
},
requireInteraction: true,
actions: [
{
action: "dismiss",
title: "Dismiss",
windowsSystemActivationType: true,
},
{
action: "snooze",
title: "Snooze",
windowsSystemActivationType: true,
},
{
action: "private",
title: "Private Window",
launch_action: { type: "OPEN_PRIVATE_BROWSER_WINDOW" },
},
],
tag: "test_toast_notification",
},
groups: ["panel-test-provider"],
targeting: "!hasActiveEnterprisePolicies",
trigger: { id: "backgroundTaskMessage" },
frequency: { lifetime: 3 },
},
{
id: "MR2022_BACKGROUND_UPDATE_TOAST_NOTIFICATION",
weight: 100,

View File

@@ -102,12 +102,28 @@ const ToastNotification = {
action.title
);
}
if (action.launch_action) {
action.opaqueRelaunchData = JSON.stringify(action.launch_action);
delete action.launch_action;
}
}
alert.actions = actions;
}
if (content.launch_url) {
alert.launchURL = Services.urlFormatter.formatURL(content.launch_url);
// Populate `opaqueRelaunchData`, prefering `launch_action` if given,
// falling back to `launch_url` if given.
let relaunchAction = content.launch_action;
if (!relaunchAction && content.launch_url) {
relaunchAction = {
type: "OPEN_URL",
data: {
args: content.launch_url,
where: "tab",
},
};
}
if (relaunchAction) {
alert.opaqueRelaunchData = JSON.stringify(relaunchAction);
}
let shownPromise = lazy.PromiseUtils.defer();

View File

@@ -25,7 +25,7 @@ add_task(async function test_PanelTestProvider() {
whatsnew_panel_message: 7,
spotlight: 3,
pb_newtab: 2,
toast_notification: 2,
toast_notification: 3,
};
const EXPECTED_TOTAL_MESSAGE_COUNT = Object.values(