diff options
author | Deathamns <deathamns@gmail.com> | 2014-10-20 22:10:59 +0200 |
---|---|---|
committer | Deathamns <deathamns@gmail.com> | 2014-11-09 17:39:38 +0100 |
commit | 749b6f186d59c65655d49d5859900746b502cb84 (patch) | |
tree | ce0459ce0d8701bd4d29be675fcd7d69ed56f1da /src | |
parent | fbffc5b07e1e9069e0a5427f1df1ae67f4e2a2e9 (diff) | |
download | uBlock-749b6f186d59c65655d49d5859900746b502cb84.zip uBlock-749b6f186d59c65655d49d5859900746b502cb84.tar.gz uBlock-749b6f186d59c65655d49d5859900746b502cb84.tar.bz2 |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/Info.plist | 2 | ||||
-rw-r--r-- | src/about.html | 5 | ||||
-rw-r--r-- | src/background.html | 1 | ||||
-rw-r--r-- | src/js/about.js | 2 | ||||
-rw-r--r-- | src/js/assets.js | 2 | ||||
-rw-r--r-- | src/js/background.js | 3 | ||||
-rw-r--r-- | src/js/messaging.js | 2 | ||||
-rw-r--r-- | src/js/popup.js | 3 | ||||
-rw-r--r-- | src/js/storage.js | 68 | ||||
-rw-r--r-- | src/js/vapi-appinfo.js | 10 | ||||
-rw-r--r-- | src/popup.html | 3 |
11 files changed, 56 insertions, 45 deletions
diff --git a/src/Info.plist b/src/Info.plist index cb50fc3..2f5bbe5 100644 --- a/src/Info.plist +++ b/src/Info.plist @@ -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> diff --git a/src/about.html b/src/about.html index f6589be..081b981 100644 --- a/src/about.html +++ b/src/about.html @@ -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 diff --git a/src/background.html b/src/background.html index 438d2b4..7f43555 100644 --- a/src/background.html +++ b/src/background.html @@ -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> diff --git a/src/js/about.js b/src/js/about.js index d7407c6..4b5ebd3 100644 --- a/src/js/about.js +++ b/src/js/about.js @@ -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); /******************************************************************************/ diff --git a/src/js/assets.js b/src/js/assets.js index 80dc0fe..6d8164b 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -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 }); diff --git a/src/js/background.js b/src/js/background.js index 54a465b..0f33405 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -51,9 +51,6 @@ var defaultExternalLists = [ /******************************************************************************/ return { - name: "µBlock", - version: "0.7.0", - userSettings: { autoUpdate: true, collapseBlocked: true, diff --git a/src/js/messaging.js b/src/js/messaging.js index 8086b65..878f029 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -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), diff --git a/src/js/popup.js b/src/js/popup.js index 8596d5d..0583511 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -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); }; /******************************************************************************/ diff --git a/src/js/storage.js b/src/js/storage.js index bdd51b7..fb7b610 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -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; diff --git a/src/js/vapi-appinfo.js b/src/js/vapi-appinfo.js new file mode 100644 index 0000000..dc4684d --- /dev/null +++ b/src/js/vapi-appinfo.js @@ -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', +};
\ No newline at end of file diff --git a/src/popup.html b/src/popup.html index 0c2ea30..c86b512 100644 --- a/src/popup.html +++ b/src/popup.html @@ -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 |