Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to WebExtensions #48

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ADDON_DATA = \
addon/bootstrap.css addon/options.html addon/options.css addon/options.js \
addon/pref-setup.js

default: build/betterponymotes.xpi build/chrome.zip build/BPM.safariextension build/export.json.bz2
default: build/betterponymotes.xpi build/chrome.zip build/firefox.zip build/BPM.safariextension build/export.json.bz2
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that my target filenames are in any way sensible most of the time, but can we rename this to something less authoritative sounding like webext.zip? Or is there some particular utility to this name?


clean:
rm -fr build
Expand Down Expand Up @@ -136,6 +136,32 @@ build/chrome.zip: $(ADDON_DATA) addon/cr-background.html addon/cr-background.js
# Uncompressed due to prior difficulties with the webstore
cd build/chrome && zip -0 ../chrome.zip *

build/firefox.zip: $(ADDON_DATA) addon/cr-background.html addon/cr-background.js
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are unifying Chrome and WebExt, would like to rename these to we- or similar. Ideally also s/Chrome/WebExt/ where appropriate (possibly also in random "browser type" constant strings). Though exactly which bit of text to use in which places may not always be perfectly clear.

mkdir -p build/firefox_webextension
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar complaint: long name, just call it build/webext.


sed "s/\/\*{{version}}\*\//$(VERSION)/" < addon/fx-manifest.json > build/firefox_webextension/manifest.json

cp addon/cr-background.html build/firefox_webextension/background.html
cp addon/cr-background.js build/firefox_webextension/background.js

cp build/betterponymotes.js build/firefox_webextension
cp build/bpm-resources.js build/firefox_webextension
cp build/emote-classes.css build/firefox_webextension

cp addon/bootstrap.css build/firefox_webextension
cp addon/bpmotes.css build/firefox_webextension
cp addon/combiners-nsfw.css build/firefox_webextension
cp addon/extracss-pure.css build/firefox_webextension
cp addon/extracss-webkit.css build/firefox_webextension
cp addon/options.css build/firefox_webextension
cp addon/options.html build/firefox_webextension
cp addon/options.js build/firefox_webextension
cp addon/pref-setup.js build/firefox_webextension

cp betterponymotes.pem build/firefox_webextension/key.pem
# Uncompressed due to prior difficulties with the webstore
cd build/firefox_webextension && zip -0 ../firefox_webextension.xpi *
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be writing out firefox.zip (or webext.zip if we rename). Or else change the Makefile rule target to match.


build/BPM.safariextension: $(ADDON_DATA) addon/sf-Settings.plist addon/sf-background.html addon/sf-background.js
mkdir -p build/BPM.safariextension

Expand Down
4 changes: 2 additions & 2 deletions addon/bpm-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ case "chrome-ext":
}
data.method = method;
log_debug("_send_message:", data);
chrome.extension.sendMessage(data, _message_handler);
chrome.runtime.sendMessage(data, _message_handler);
};

var _message_handler = catch_errors(function(message) {
Expand All @@ -175,7 +175,7 @@ case "chrome-ext":
};

linkify_options = function(element) {
element.href = chrome.extension.getURL("/options.html");
element.href = chrome.runtime.getURL("/options.html");
element.target = "_blank";
};
break;
Expand Down
2 changes: 1 addition & 1 deletion addon/cr-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var pref_manager = manage_prefs(sr_name2id, {
});

// Content script requests
chrome.extension.onMessage.addListener(function(message, sender, sendResponse) {
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
switch(message.method) {
case "get_initdata":
var reply = {"method": "initdata"};
Expand Down
49 changes: 49 additions & 0 deletions addon/fx-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"background": {
"page": "background.html"
},
"content_scripts": [
{
"all_frames": true,
"js": [
"bpm-resources.js",
"betterponymotes.js"
],
"matches": [
"*://*/*"
],
"run_at": "document_start"
}
],
"applications": {
"gecko": {
"id": "jid1-tHrhDJXsKvsiCw@jetpack"
}
},
"description": "View Reddit ponymotes across the site",
"homepage_url": "https://ponymotes.net/bpm/",
"manifest_version": 2,
"minimum_chrome_version": "20",
"name": "BetterPonymotes",
"options_ui": {
"page": "options.html",
"browser_style": true
},
"permissions": [
"http://*.reddit.com/",
"https://*.reddit.com/",
"http://*.redditstatic.com/",
"https://*.redditstatic.com/",
"http://*.redditmedia.com/",
"https://*.redditmedia.com/"
],
"version": "/*{{version}}*/.mozsucks",
"web_accessible_resources": [
"bpmotes.css",
"emote-classes.css",
"combiners-nsfw.css",
"extracss-pure.css",
"extracss-webkit.css",
"options.html"
]
}
4 changes: 2 additions & 2 deletions addon/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var bpm_utils = {
platform: (function() {
if(self.on !== undefined) {
return "firefox-ext";
} else if(_bpm_global("chrome") !== undefined && chrome.extension !== undefined) {
} else if(_bpm_global("chrome") !== undefined && chrome.runtime !== undefined) {
return "chrome-ext";
} else if(_bpm_global("safari")) {
return "safari-ext";
Expand Down Expand Up @@ -130,7 +130,7 @@ case "chrome-ext":
data = {};
}
data["method"] = method;
chrome.extension.sendMessage(data, this._message_handler.bind(this));
chrome.runtime.sendMessage(data, this._message_handler.bind(this));
},

_message_handler: function(message) {
Expand Down