mirror of https://github.com/gorhill/uBlock.git
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:
parent
fbffc5b07e
commit
749b6f186d
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -51,9 +51,6 @@ var defaultExternalLists = [
|
|||
/******************************************************************************/
|
||||
|
||||
return {
|
||||
name: "µBlock",
|
||||
version: "0.7.0",
|
||||
|
||||
userSettings: {
|
||||
autoUpdate: true,
|
||||
collapseBlocked: true,
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -592,47 +592,47 @@
|
|||
// - Initialize internal state with maybe already existing tabs.
|
||||
// - Schedule next update operation.
|
||||
var onAllDone = function() {
|
||||
// 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.
|
||||
var scriptDone = function() {
|
||||
chrome.runtime.lastError;
|
||||
};
|
||||
var scriptEnd = function(tabId) {
|
||||
if ( chrome.runtime.lastError ) {
|
||||
return;
|
||||
}
|
||||
vAPI.tabs.injectScript(tabId, {
|
||||
file: 'js/contentscript-end.js',
|
||||
allFrames: true,
|
||||
runAt: 'document_idle'
|
||||
}, scriptDone);
|
||||
};
|
||||
var scriptStart = function(tabId) {
|
||||
vAPI.tabs.injectScript(tabId, {
|
||||
file: 'js/contentscript-start.js',
|
||||
allFrames: true,
|
||||
runAt: 'document_idle'
|
||||
}, function(){ scriptEnd(tabId); });
|
||||
};
|
||||
var bindToTabs = function(tabs) {
|
||||
var i = tabs.length, tab;
|
||||
while ( i-- ) {
|
||||
tab = tabs[i];
|
||||
µb.bindTabToPageStats(tab.id, tab.url);
|
||||
// https://github.com/gorhill/uBlock/issues/129
|
||||
scriptStart(tab.id);
|
||||
}
|
||||
};
|
||||
|
||||
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.
|
||||
var scriptDone = function() {
|
||||
chrome.runtime.lastError;
|
||||
};
|
||||
var scriptEnd = function(tabId) {
|
||||
if ( chrome.runtime.lastError ) {
|
||||
return;
|
||||
}
|
||||
vAPI.tabs.injectScript(tabId, {
|
||||
file: 'js/contentscript-end.js',
|
||||
allFrames: true,
|
||||
runAt: 'document_idle'
|
||||
}, scriptDone);
|
||||
};
|
||||
var scriptStart = function(tabId) {
|
||||
vAPI.tabs.injectScript(tabId, {
|
||||
file: 'js/contentscript-start.js',
|
||||
allFrames: true,
|
||||
runAt: 'document_idle'
|
||||
}, function(){ scriptEnd(tabId); });
|
||||
};
|
||||
var bindToTabs = function(tabs) {
|
||||
var i = tabs.length, tab;
|
||||
while ( i-- ) {
|
||||
tab = tabs[i];
|
||||
µb.bindTabToPageStats(tab.id, tab.url);
|
||||
// https://github.com/gorhill/uBlock/issues/129
|
||||
scriptStart(tab.id);
|
||||
}
|
||||
};
|
||||
|
||||
chrome.tabs.query({ url: 'http://*/*' }, bindToTabs);
|
||||
chrome.tabs.query({ url: 'https://*/*' }, bindToTabs);
|
||||
}
|
||||
|
||||
// https://github.com/gorhill/uBlock/issues/184
|
||||
// If we restored a selfie, check for updates not too far
|
||||
// in the future.
|
||||
// in the future.
|
||||
var nextUpdate = fromSelfie === false && µb.userSettings.autoUpdate ?
|
||||
µb.nextUpdateAfter :
|
||||
µb.firstUpdateAfter;
|
||||
|
|
|
@ -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',
|
||||
};
|
|
@ -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"></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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue