Use a dedicated file for storing extension info

Chrome has getManifest(), Safari doesn't have anything, Firefox has an
asynchronous API...
So, instead of using extension APIs, store the common informations
(extension name, version, homepage url) in a file (vapi-appinfo.js), which
can be included when it's needed (its data will be available at vAPI.app.____).
The file's content is updated each time the extension is being built, so
it shouldn't be modified manually.
This commit is contained in:
Deathamns 2014-10-20 22:10:59 +02:00
parent fbffc5b07e
commit 749b6f186d
12 changed files with 68 additions and 45 deletions

View File

@ -15,7 +15,7 @@
<key>CFBundleShortVersionString</key>
<string>0.7.0.7</string>
<key>CFBundleVersion</key>
<string>1452564</string>
<string>1452580</string>
<key>Chrome</key>
<dict>
<key>Database Quota</key>

View File

@ -10,7 +10,7 @@
<body>
<h2>µBlock <span id="aboutVersion"></span></h2>
<h2 id="aboutNameVer"></h2>
<ul>
<li><a href="https://github.com/gorhill/uBlock/releases" data-i18n="aboutChangelog"></a>
<li><a href="https://github.com/gorhill/uBlock" data-i18n="aboutCode"></a>
@ -28,12 +28,13 @@
<button type="button" id="import" data-i18n="aboutRestoreDataButton"></button>
<input id="restoreFilePicker" type="file" accept="text/plain" style="display:none;">
<p>
<p><button type="button" id="reset" data-i18n="aboutResetDataButton">Start from scratch...</button>
<p><button type="button" id="reset" data-i18n="aboutResetDataButton"></button>
</div>
<script src="js/js-loader.js" data-jsList="
js/vapi-common.js
js/vapi-client.js
js/vapi-appinfo.js
js/udom.js
js/i18n.js
js/dashboard-common.js

View File

@ -10,6 +10,7 @@
<script src="lib/yamd5.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-background.js"></script>
<script src="js/vapi-appinfo.js"></script>
<script src="js/background.js"></script>
<script src="js/xal.js"></script>
<script src="js/async.js"></script>

View File

@ -108,7 +108,7 @@ uDom('#export').on('click', exportToFile);
uDom('#import').on('click', startImportFilePicker);
uDom('#reset').on('click', resetUserData);
uDom('#restoreFilePicker').on('change', handleImportFilePicker);
uDom('#aboutVersion').html(µBlock.version);
uDom('#aboutNameVer').html(vAPI.app.name + ' v' + vAPI.app.version);
/******************************************************************************/

View File

@ -97,7 +97,7 @@ var cachedAssetsManager = (function() {
// Flush cached non-user assets if these are from a prior version.
// https://github.com/gorhill/httpswitchboard/issues/212
var onLastVersionRead = function(store) {
var currentVersion = µBlock.version;
var currentVersion = vAPI.app.version;
var lastVersion = store.extensionLastVersion || '0.0.0.0';
if ( currentVersion !== lastVersion ) {
vAPI.storage.set({ 'extensionLastVersion': currentVersion });

View File

@ -51,9 +51,6 @@ var defaultExternalLists = [
/******************************************************************************/
return {
name: "µBlock",
version: "0.7.0",
userSettings: {
autoUpdate: true,
collapseBlocked: true,

View File

@ -677,7 +677,7 @@ var getUserData = function(callback) {
var onUserFiltersReady = function(details) {
callback({
'timeStamp': Date.now(),
'version': µb.version,
'version': vAPI.app.version,
'userSettings': µb.userSettings,
'filterLists': µb.remoteBlacklists,
'netWhitelist': µb.stringFromWhitelist(µb.netWhitelist),

View File

@ -181,7 +181,8 @@ var toggleNetFilteringSwitch = function(ev) {
var renderHeader = function() {
var hdr = uDom('#version');
hdr.html(hdr.html() + 'v'); // + chrome.runtime.getManifest().version);
hdr.nodes[0].previousSibling.textContent = vAPI.app.name;
hdr.html(hdr.html() + 'v' + vAPI.app.version);
};
/******************************************************************************/

View File

@ -592,6 +592,7 @@
// - Initialize internal state with maybe already existing tabs.
// - Schedule next update operation.
var onAllDone = function() {
if (vAPI.chrome) {
// http://code.google.com/p/chromium/issues/detail?id=410868#c11
// Need to be sure to access `chrome.runtime.lastError` to prevent
// spurious warnings in the console.
@ -625,7 +626,6 @@
}
};
if (vAPI.chrome) {
chrome.tabs.query({ url: 'http://*/*' }, bindToTabs);
chrome.tabs.query({ url: 'https://*/*' }, bindToTabs);
}

10
src/js/vapi-appinfo.js Normal file
View File

@ -0,0 +1,10 @@
// can be included anywhere if it's needed
'use strict';
window.vAPI = window.vAPI || {};
vAPI.app = {
/**/name: 'µBlock',
/**/version: '0.7.0.7',
/**/url: 'https://github.com/gorhill/uBlock',
};

View File

@ -9,7 +9,7 @@
</head>
<body>
<h4 title="popupTipDashboard">µBlock<span id="version"></span></h4>
<h4 title="popupTipDashboard">v<span id="version"></span></h4>
<div>
<p id="switch" data-i18n-tip="popupPowerSwitchInfo"><span class="fa">&#xf011;</span></p>
<p id="switch-hint"></p>
@ -55,6 +55,7 @@
<script src="js/js-loader.js" data-jsList="
js/vapi-common.js
js/vapi-client.js
js/vapi-appinfo.js
js/udom.js
js/i18n.js
js/popup.js

View File

@ -46,6 +46,18 @@ config['build_number'] = strftime('%y' + str(int(tmp.total_seconds() * 65535 / 3
rmtree(target_locale_dir)
with open(pj(src_dir, 'js', 'vapi-appinfo.js'), 'r+t', encoding='utf-8', newline='\n') as f:
tmp = f.read()
f.seek(0)
f.write(re.sub(
r'/\*\*/([^:]+:).+',
lambda m: '/**/' + m.group(1) + " '" + config[m.group(1)[:-1]] + "',",
tmp
))
for alpha2 in os.listdir(source_locale_dir):
with open(pj(source_locale_dir, alpha2, 'messages.json'), encoding='utf-8') as f:
string_data = json.load(f, object_pairs_hook=OrderedDict)