mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-06 14:04:12 +01:00
Ditch the bloody chrome registry.
This commit is contained in:
@@ -52,15 +52,21 @@ if (!JSMLoader || JSMLoader.bump != 1)
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader)
|
||||
.loadSubScript(url, global.global || global);
|
||||
}
|
||||
let global = Components.utils.import(url, target);
|
||||
try {
|
||||
let global = Components.utils.import(url, target);
|
||||
|
||||
if (name == "base.jsm") {
|
||||
global.JSMLoader = this;
|
||||
Components.utils.import(url, this.global);
|
||||
this.global.EXPORTED_SYMBOLS = global.EXPORTED_SYMBOLS;
|
||||
if (name == "base.jsm") {
|
||||
global.JSMLoader = this;
|
||||
Components.utils.import(url, this.global);
|
||||
this.global.EXPORTED_SYMBOLS = global.EXPORTED_SYMBOLS;
|
||||
}
|
||||
|
||||
return this.globals[url] = global;
|
||||
}
|
||||
catch (e) {
|
||||
dump("Importing " + url + ": " + e + "\n" + (e.stack || Error().stack));
|
||||
throw e;
|
||||
}
|
||||
|
||||
return this.globals[url] = global;
|
||||
},
|
||||
cleanup: function unregister() {
|
||||
for each (let factory in this.factories.splice(0))
|
||||
|
||||
@@ -55,7 +55,50 @@ var ConfigBase = Class("ConfigBase", {
|
||||
return addon;
|
||||
}),
|
||||
|
||||
language: Class.memoize(function () services.chromeRegistry.getSelectedLocale("dactyl")),
|
||||
/**
|
||||
* The current application locale.
|
||||
*/
|
||||
appLocale: Class.memoize(function () services.chromeRegistry.getSelectedLocale("global")),
|
||||
|
||||
/**
|
||||
* The current dactyl locale.
|
||||
*/
|
||||
locale: Class.memoize(function () this.bestLocale(this.locales)),
|
||||
|
||||
/**
|
||||
* The current application locale.
|
||||
*/
|
||||
locales: Class.memoize(function () {
|
||||
// TODO: Merge with completion.file code.
|
||||
function getDir(str) str.match(/^(?:.*[\/\\])?/)[0];
|
||||
|
||||
let uri = "resource://dactyl-locale/";
|
||||
let jar = io.isJarURL(uri);
|
||||
if (jar) {
|
||||
let prefix = getDir(jar.JAREntry);
|
||||
return iter(s.slice(prefix.length).replace(/\/.*/, "") for (s in io.listJar(jar.JARFile, prefix)))
|
||||
.uniq().toArray();
|
||||
}
|
||||
else {
|
||||
return array(f.leafName
|
||||
for (f in util.getFile(uri).iterDirectory())
|
||||
if (f.isDirectory())).array;
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Returns the best locale match to the current locale from a list
|
||||
* of available locales.
|
||||
*
|
||||
* @param {[string]} list A list of available locales
|
||||
* @returns {string}
|
||||
*/
|
||||
bestLocale: function (list) {
|
||||
let langs = set(list);
|
||||
return values([this.appLocale, this.appLocale.replace(/-.*/, ""),
|
||||
"en", "en-US", iter(langs).next()])
|
||||
.nth(function (l) set.has(langs, l), 0);
|
||||
},
|
||||
|
||||
/** @property {string} The Dactyl version string. */
|
||||
version: Class.memoize(function () {
|
||||
@@ -593,14 +636,14 @@ var ConfigBase = Class("ConfigBase", {
|
||||
]]></>)
|
||||
});
|
||||
|
||||
services.subscriptLoader.loadSubScript("chrome://dactyl/content/config.js", this);
|
||||
services.subscriptLoader.loadSubScript("resource://dactyl-local-content/config.js", this);
|
||||
|
||||
config.INIT = update(Object.create(config.INIT), config.INIT, {
|
||||
init: function init(dactyl, modules, window) {
|
||||
init.superapply(this, arguments);
|
||||
|
||||
let img = window.Image();
|
||||
img.src = this.logo || "chrome://" + this.name + "/content/logo.png";
|
||||
img.src = this.logo || "chrome://dactyl-local-content/logo.png";
|
||||
img.onload = function () {
|
||||
highlight.loadCSS(<>{"!Logo {"}
|
||||
display: inline-block;
|
||||
|
||||
@@ -43,7 +43,7 @@ Highlight.defaultValue("selector", function () highlight.selector(this.class));
|
||||
|
||||
Highlight.defaultValue("sites", function ()
|
||||
this.base ? this.base.sites
|
||||
: ["chrome://dactyl/*", "dactyl:*", "file://*"].concat(
|
||||
: ["resource://dactyl*", "dactyl:*", "file://*"].concat(
|
||||
highlight.styleableChrome));
|
||||
|
||||
Highlight.defaultValue("style", function ()
|
||||
|
||||
@@ -296,7 +296,7 @@ var IO = Module("io", {
|
||||
return File(file);
|
||||
},
|
||||
|
||||
isJarURL: function (url) {
|
||||
isJarURL: function isJarURL(url) {
|
||||
try {
|
||||
let uri = util.newURI(url);
|
||||
let channel = services.io.newChannelFromURI(uri);
|
||||
@@ -308,6 +308,22 @@ var IO = Module("io", {
|
||||
return false;
|
||||
},
|
||||
|
||||
listJar: function listJar(file, path) {
|
||||
file = util.getFile(file);
|
||||
if (file) {
|
||||
// let jar = services.zipReader.getZip(file); Crashes.
|
||||
let jar = services.ZipReader(file);
|
||||
try {
|
||||
for (let entry in jar.findEntries("*"))
|
||||
if (filter.test(s))
|
||||
yield entry;
|
||||
}
|
||||
finally {
|
||||
jar.close();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
readHeredoc: function (end) {
|
||||
return "";
|
||||
},
|
||||
@@ -869,25 +885,12 @@ unlet s:cpo_save
|
||||
let uri = io.isJarURL(dir);
|
||||
if (uri)
|
||||
context.generate = function generate_jar() {
|
||||
let file = util.getFile(uri.JARFile);
|
||||
if (file) {
|
||||
// let jar = services.zipReader.getZip(file); Crashes.
|
||||
let jar = services.ZipReader(file);
|
||||
try {
|
||||
let filter = RegExp("^" + util.regexp.escape(decodeURI(getDir(uri.JAREntry)))
|
||||
+ "[^/]*/?$");
|
||||
return [
|
||||
{
|
||||
isDirectory: function () s.substr(-1) == "/",
|
||||
leafName: /([^\/]*)\/?$/.exec(s)[1]
|
||||
}
|
||||
for (s in iter(jar.findEntries("*"))) if (filter.test(s))
|
||||
]
|
||||
return [
|
||||
{
|
||||
isDirectory: function () s.substr(-1) == "/",
|
||||
leafName: /([^\/]*)\/?$/.exec(s)[1]
|
||||
}
|
||||
finally {
|
||||
jar.close();
|
||||
}
|
||||
}
|
||||
for (s in io.listJar(getDir(uri.JARFile, uri.JAREntry)))]
|
||||
};
|
||||
else
|
||||
context.generate = function generate_file() {
|
||||
|
||||
@@ -84,7 +84,7 @@ var Overlay = Module("Overlay", {
|
||||
Module.list = [];
|
||||
Module.constructors = {};
|
||||
|
||||
const BASE = "chrome://dactyl/content/";
|
||||
const BASE = "resource://dactyl-content/";
|
||||
|
||||
const create = window.Object.create || (function () {
|
||||
window.__dactyl_eval_string = "(function (proto) ({ __proto__: proto }))";
|
||||
@@ -143,7 +143,7 @@ var Overlay = Module("Overlay", {
|
||||
modules.modules = modules;
|
||||
window.dactyl = { modules: modules };
|
||||
|
||||
let prefix = [BASE];
|
||||
let prefix = [BASE, "resource://dactyl-local-content/"];
|
||||
|
||||
defineModule.time("load", null, function _load() {
|
||||
["base",
|
||||
@@ -156,7 +156,6 @@ var Overlay = Module("Overlay", {
|
||||
"storage",
|
||||
"util"
|
||||
].forEach(function (name) require(jsmodules, name));
|
||||
prefix.unshift("chrome://" + config.name + "/content/");
|
||||
|
||||
["dactyl",
|
||||
"modes",
|
||||
|
||||
Reference in New Issue
Block a user