diff --git a/Makefile b/Makefile index 0bb797c6c..b2152c72e 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ crx_contents := script.js eventPage.js icon16.png icon48.png icon128.png manifes release := \ $(foreach f, \ - $(foreach c,. -beta.,$(name)$(c)crx updates$(c)xml $(name)$(c)user.js $(name)$(c)meta.js) \ + $(foreach c,. -beta.,$(name)$(c)crx updates$(c)xml updates$(c)json $(name)$(c)user.js $(name)$(c)meta.js) \ $(name)-noupdate.crx \ $(name)-noupdate.user.js \ $(name).zip \ @@ -184,6 +184,9 @@ testbuilds/crx$1/manifest.json : src/meta/manifest.json version.json $(template_ testbuilds/updates$1.xml : src/meta/updates.xml version.json $(template_deps) | testbuilds/crx$1 $(template) $$< $$@ type=crx channel=$1 +testbuilds/updates$1.json : src/meta/updates.json version.json $(template_deps) | testbuilds/crx$1 + $(template) $$< $$@ type=crx channel=$1 + testbuilds/$(name)$1.crx.zip : \ $(foreach f,$(crx_contents),testbuilds/crx$1/$(f)) \ package.json version.json tools/zip-crx.js node_modules/jszip/package.json @@ -342,7 +345,7 @@ stable : distready git push . HEAD:bstable git tag -af stable -m "$(meta_name) v$(version)." cd dist && git merge --no-commit -s ours stable - cd dist && git checkout stable "builds/$(name).*" builds/updates.xml + cd dist && git checkout stable "builds/$(name).*" builds/updates.xml builds/updates.json cd dist && git commit -am "Move $(meta_name) v$(version) to stable channel." web : index.html distready diff --git a/package.json b/package.json index 1e4469f75..19efb222e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "newIssue": "https://gitreports.com/issue/ccd0/4chan-x?issue_title=%title&details=%details", "newIssueMaxLength": 8181, "appid": "lacclbnghgdicfifcamcmcnilckjamag", + "appidGecko": "4chan-x@4chan-x.net", "chromeStoreID": "ohnjgmpcibpbafdlkimncjhflgedgpam", "recaptchaKey": "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc", "youtubeAPIKey": "AIzaSyB5_zaen_-46Uhz1xGR-lz1YoUMHqCD6CE", diff --git a/src/meta/jshint.json b/src/meta/jshint.json index 45f62a3eb..1b58dc59c 100644 --- a/src/meta/jshint.json +++ b/src/meta/jshint.json @@ -20,6 +20,7 @@ "BroadcastChannel": false, "GM_info": false, "cloneInto": false, + "XPCNativeWrapper": false, "unsafeWindow": false, "chrome": false, "GM": false<%= diff --git a/src/meta/manifest.json b/src/meta/manifest.json index af5b31144..8438753bb 100644 --- a/src/meta/manifest.json +++ b/src/meta/manifest.json @@ -23,10 +23,14 @@ <% if (channel !== '-noupdate') { %> "update_url": "<%= meta.downloads %>updates<%= channel %>.xml", "key": "<%= meta.appid %>", <% } %> "minimum_chrome_version": "<%= meta.min.chrome %>", - "permissions": [ - "storage" - ], + "permissions": <%= JSON.stringify(meta.matches_only.concat(["storage"])) %>, "optional_permissions": [ "*://*/" - ] + ], + "applications": { + "gecko": { + "id": "<%= meta.appidGecko %>"<% if (channel !== '-noupdate') { %>, + "update_url": "<%= meta.downloads %>updates<%= channel %>.json" +<% } %> } + } } diff --git a/src/meta/updates.json b/src/meta/updates.json new file mode 100644 index 000000000..dc9d876f6 --- /dev/null +++ b/src/meta/updates.json @@ -0,0 +1,12 @@ +{ + "addons": { + "<%= meta.appidGecko %>": { + "updates": [ + { + "version": "<%= readJSON('/version.json').version %>", + "update_link": "<%= meta.downloads %><%= name %><%= channel %>.crx" + } + ] + } + } +} diff --git a/src/platform/$.coffee b/src/platform/$.coffee index 44c39168c..9eeaebf6d 100644 --- a/src/platform/$.coffee +++ b/src/platform/$.coffee @@ -45,6 +45,10 @@ $.ajax = do -> # With the `If-Modified-Since` header we only receive the HTTP headers and no body for 304 responses. # This saves a lot of bandwidth and CPU time for both the users and the servers. lastModified = {} + <% if (type === 'crx') { %> + if XPCNativeWrapper? + pageXHR = XPCNativeWrapper window.wrappedJSObject.XMLHttpRequest + <% } %> (url, options={}, extra={}) -> {type, whenModified, upCallbacks, form} = extra @@ -53,7 +57,11 @@ $.ajax = do -> url = url.replace /^((?:https?:)?\/\/(?:\w+\.)?4c(?:ha|d)n\.org)\/adv\//, '$1//adv/' # XXX https://bugs.chromium.org/p/chromium/issues/detail?id=643659 url += "?s=#{whenModified}" if $.engine is 'blink' and whenModified - r = new XMLHttpRequest() + xhr = XMLHttpRequest + <% if (type === 'crx') { %> + xhr = pageXHR or xhr + <% } %> + r = new xhr() type or= form and 'post' or 'get' try r.open type, url, true @@ -415,9 +423,17 @@ $.get = $.oneItemSugar (data, cb) -> return unless $.crxWorking() results = {} get = (area) -> - chrome.storage[area].get Object.keys(data), (result) -> + keys = Object.keys data + # XXX slow performance in Firefox + if $.engine is 'gecko' and area is 'sync' and keys.length > 3 + keys = null + chrome.storage[area].get keys, (result) -> if chrome.runtime.lastError c.error chrome.runtime.lastError.message + if keys is null + result2 = {} + result2[key] = val for key, val of result when key of data + result = result2 for key of data $.oldValue[area][key] = result[key] results[area] = result