Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / browser / modules / BackgroundTask_uninstall.sys.mjs
blob9e51248438e1a1ec9e7c904498437d6e8a3a4df6
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /**
7  * This task ought to have an ephemeral profile and should not apply updates.
8  * These settings are controlled externally, by
9  * `BackgroundTasks::IsUpdatingTaskName` and
10  * `BackgroundTasks::IsEphemeralProfileTaskName`.
11  */
13 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
15 export async function runBackgroundTask(commandLine) {
16   console.log("Running BackgroundTask_uninstall.");
18   if (AppConstants.platform === "win") {
19     try {
20       removeNotifications();
21     } catch (ex) {
22       console.error(ex);
23     }
24   } else {
25     console.log("Not a Windows install. Skipping notification removal.");
26   }
28   console.log("Cleaning up update files.");
29   try {
30     Cc["@mozilla.org/updates/update-manager;1"]
31       .getService(Ci.nsIUpdateManager)
32       .doUninstallCleanup();
33   } catch (ex) {
34     console.error(ex);
35   }
38 function removeNotifications() {
39   console.log("Removing Windows toast notifications.");
41   if (!("nsIWindowsAlertsService" in Ci)) {
42     console.log("nsIWindowsAlertsService not present.");
43     return;
44   }
46   let alertsService;
47   try {
48     alertsService = Cc["@mozilla.org/system-alerts-service;1"]
49       .getService(Ci.nsIAlertsService)
50       .QueryInterface(Ci.nsIWindowsAlertsService);
51   } catch (e) {
52     console.error("Error retrieving nsIWindowsAlertsService: " + e.message);
53     return;
54   }
56   alertsService.removeAllNotificationsForInstall();
57   console.log("Finished removing Windows toast notifications.");