summaryrefslogtreecommitdiffstats
path: root/services/sync/tps/extensions/tps/resource/quit.sys.mjs
blob: e2cb8d8c227a4a0142fd4a73e96b8816fe5be89d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* -*- indent-tabs-mode: nil -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*
  From mozilla/toolkit/content
  These files did not have a license
*/
function canQuitApplication() {
  try {
    var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
      Ci.nsISupportsPRBool
    );
    Services.obs.notifyObservers(cancelQuit, "quit-application-requested");

    // Something aborted the quit process.
    if (cancelQuit.data) {
      return false;
    }
  } catch (ex) {}

  return true;
}

export function goQuitApplication() {
  if (!canQuitApplication()) {
    return false;
  }

  try {
    Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
  } catch (ex) {
    throw new Error(`goQuitApplication: ${ex.message}`);
  }

  return true;
}