Last active
January 15, 2016 19:34
-
-
Save jaredhirsch/8fa2be280f48ef96c1b0 to your computer and use it in GitHub Desktop.
loading code in one addon from another addon
This file contains 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
// skipping the imports of Cu and AddonManager here: | |
// get an addon pointer | |
var addon; | |
AddonManager.getAddonByID('@idea-town-addon', function(x) { addon = x; }); | |
// get the local machine's file path of the addon | |
var addonURI = addon.getResourceURI().asciiSpec; | |
// ugh, wrap the `file:///` URI in a `jar:///` URI, | |
// to get access to the metrics.jsm file inside the zipped idea town xpi. | |
// figured this out after a long search in dxr: | |
var xpiURI = 'jar:' + addonURI + '!/' + 'modules/metrics.jsm'; | |
// finally, load the file, importing a Metrics object into the context | |
Cu.import(xpiURI); | |
// :grimacing: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess somebody will probably google for this at some point in the future, so I'll also record here that I figured out, after a lot of looking, how you can get access to SDK's loader from non-SDK addons:
You can wrap that in an
if (typeof require === 'undefined')
check to build up libraries that can be shared between SDK and non-SDK addons.