Created
January 29, 2021 18:16
-
-
Save ncalexan/d0bb5f3512950b99ca1fdff3503c7735 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- | |
* 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/. */ | |
// ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this); | |
// XPCOMUtils.defineLazyModuleGetters(this, { | |
// SessionStore: "resource:///modules/sessionstore/SessionStore.jsm", | |
// }); | |
var EXPORTED_SYMBOLS = ["runBackgroundTask"]; | |
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); | |
const { XPCOMUtils } = ChromeUtils.import( | |
"resource://gre/modules/XPCOMUtils.jsm" | |
); | |
XPCOMUtils.defineLazyModuleGetters(this, { | |
setTimeout: "resource://gre/modules/Timer.jsm", | |
}); | |
// Notes to self: | |
// | |
// It's BrowserContentHandler.jsm that sends the update success ping. | |
// That won't happen when launching a background service. Best to | |
// check that we witness the update at the next run, and think about | |
// sending some other ping from background services. | |
// | |
// The update ready ping is sent based on the `update-downloaded` and | |
// `update-staged` observer notifactions. I think that | |
// `UpdatePing.earlyInit()` will be called in background services, but | |
// it seems those notifications may race shutdown. | |
function runBackgroundTask() { | |
// TODO: do better here. | |
Services.prefs.setBoolPref("app.update.langpack.enabled", false); | |
console.error("runBackgroundTask... 3"); | |
const { AppUpdater } = ChromeUtils.import( | |
"resource:///modules/AppUpdater.jsm" | |
); | |
let p = new Promise(resolve => { | |
try { | |
let appUpdater = new AppUpdater(); | |
let _appUpdaterListener = status => { | |
console.log(`_appUpdaterListener: ${status}`); | |
if (AppUpdater.STATUS.isTerminalStatus(status)) { | |
appUpdater.removeListener(_appUpdaterListener); | |
resolve(0); | |
} | |
}; | |
appUpdater.addListener(_appUpdaterListener); | |
appUpdater.check(); | |
} catch (e) { | |
console.log(`e: ${e}`, e, e.stack); | |
throw e; | |
} | |
}); | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment