Browse Source

Building extension files

Adds possibility to build extension files (Chrome and Safari) from
command line.

To run from the project directory:
python tools/build.py [meta]

If the optional `meta` argument is set, then only the manifest and
language files are uptated.
Without that everything is being built (extension files too) into the
`dist/build/version_number` folder.

For Chrome there will be two files, a crx, and a .zip file which
includes the key.pem private key (so this must not be shared,
it's just a bit help for publishing it to the Chrome Web Store).

Beside the extension files, update-files are generated too (for self
hosting - Safari needs it).
pull/2/head
Deathamns 10 years ago
committed by gorhill
parent
commit
aebfb15aa2
  1. 19
      src/js/vapi-client.js

19
src/js/vapi-client.js

@ -1,3 +1,4 @@
// » header
/* global addMessageListener, removeMessageListener, sendAsyncMessage */ /* global addMessageListener, removeMessageListener, sendAsyncMessage */
// for non background pages // for non background pages
@ -51,8 +52,10 @@ var messagingConnector = function(response) {
var uniqueId = function() { var uniqueId = function() {
return parseInt(Math.random() * 1e10, 10).toString(36); return parseInt(Math.random() * 1e10, 10).toString(36);
}; };
// «
if (self.chrome) { if (self.chrome) {
// » crx
vAPI.chrome = true; vAPI.chrome = true;
vAPI.messaging = { vAPI.messaging = {
port: null, port: null,
@ -60,15 +63,14 @@ if (self.chrome) {
listeners: {}, listeners: {},
requestId: 0, requestId: 0,
connectorId: uniqueId(), connectorId: uniqueId(),
connector: messagingConnector,
setup: function() { setup: function() {
this.port = chrome.runtime.connect({name: this.connectorId}); this.port = chrome.runtime.connect({name: this.connectorId});
this.port.onMessage.addListener(this.connector);
this.port.onMessage.addListener(messagingConnector);
}, },
close: function() { close: function() {
if (this.port) { if (this.port) {
this.port.disconnect(); this.port.disconnect();
this.port.onMessage.removeListener(this.connector);
this.port.onMessage.removeListener(messagingConnector);
this.port = this.channels = this.listeners = this.connectorId = null; this.port = this.channels = this.listeners = this.connectorId = null;
} }
}, },
@ -105,7 +107,9 @@ if (self.chrome) {
return this.channels[channelName]; return this.channels[channelName];
} }
}; };
// «
} else if (self.safari) { } else if (self.safari) {
// » safariextz
vAPI.safari = true; vAPI.safari = true;
// relevant? // relevant?
@ -115,7 +119,6 @@ if (self.chrome) {
listeners: {}, listeners: {},
requestId: 0, requestId: 0,
connectorId: uniqueId(), connectorId: uniqueId(),
connector: messagingConnector,
setup: function() { setup: function() {
this._connector = function(msg) { this._connector = function(msg) {
// messages from the background script are sent to every frame, // messages from the background script are sent to every frame,
@ -123,7 +126,7 @@ if (self.chrome) {
// what is meant for the current context // what is meant for the current context
if (msg.name === vAPI.messaging.connectorId if (msg.name === vAPI.messaging.connectorId
|| msg.name === 'broadcast') { || msg.name === 'broadcast') {
vAPI.messaging.connector(msg.message);
messagingConnector(msg.message);
} }
}; };
safari.self.addEventListener('message', this._connector, false); safari.self.addEventListener('message', this._connector, false);
@ -174,7 +177,7 @@ if (self.chrome) {
target: { target: {
page: { page: {
dispatchMessage: function(name, msg) { dispatchMessage: function(name, msg) {
vAPI.messaging.connector(msg);
messagingConnector(msg);
} }
} }
} }
@ -371,6 +374,8 @@ if (self.chrome) {
url: window.location.href, url: window.location.href,
type: 'main_frame' type: 'main_frame'
}); });
// «
} }
// » footer
})(); })();
// «
Loading…
Cancel
Save