tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

BackgroundTask_uninstall.sys.mjs (1723B)


      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/. */
      5 
      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 */
     12 
     13 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
     14 
     15 export async function runBackgroundTask() {
     16  console.log("Running BackgroundTask_uninstall.");
     17 
     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  }
     27 
     28  console.log("Cleaning up update files.");
     29  try {
     30    await Cc["@mozilla.org/updates/update-manager;1"]
     31      .getService(Ci.nsIUpdateManager)
     32      .doUninstallCleanup();
     33  } catch (ex) {
     34    console.error(ex);
     35  }
     36 }
     37 
     38 function removeNotifications() {
     39  console.log("Removing Windows toast notifications.");
     40 
     41  if (!("nsIWindowsAlertsService" in Ci)) {
     42    console.log("nsIWindowsAlertsService not present.");
     43    return;
     44  }
     45 
     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  }
     55 
     56  alertsService.removeAllNotificationsForInstall();
     57  console.log("Finished removing Windows toast notifications.");
     58 }