Skip to content

Commit

Permalink
Add UpdateService to manage versions updates
Browse files Browse the repository at this point in the history
  • Loading branch information
leeroybrun committed Dec 11, 2014
1 parent d65973d commit 7a50bf3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
1 change: 1 addition & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function(grunt) {
'src/background/SpotifyService.js',
'src/background/ShazamService.js',
'src/background/TagsService.js',
'src/background/UpdateService.js',
]
}
}
Expand Down
59 changes: 59 additions & 0 deletions src/background/UpdateService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(function(Logger){
var UpdateService = {
update: function(initVersionTxt, finalVersionTxt) {
var rePoint = new RegExp('\\.', 'g');

var initVersion = parseInt(initVersionTxt.replace(rePoint, ''));
var finalVersion = parseInt(finalVersionTxt.replace(rePoint, ''));

var startIndex = null;
var endIndex = null;

console.log(UpdateService._updates);

for(var i = 0; i < UpdateService._updates.length && (startIndex === null || endIndex === null); i++) {
console.log(i, UpdateService._updates[i].version, initVersion, finalVersion, startIndex, endIndex);

if(startIndex === null && UpdateService._updates[i].version > initVersion) {
startIndex = i;
}

console.log(i, UpdateService._updates[i].version, initVersion, finalVersion, startIndex, endIndex);

if(startIndex !== null && UpdateService._updates[i].version <= finalVersion) {
endIndex = i;
}

console.log(i, UpdateService._updates[i].version, initVersion, finalVersion, startIndex, endIndex);
}

if(startIndex !== null && endIndex !== null) {
Logger.info('[Updater] '+ (endIndex-startIndex+1) +' update scripts to call to go from v'+ initVersionTxt +' to v'+ finalVersionTxt +'.');
} else {
Logger.info('[Updater] No update script defined to go from v'+ initVersionTxt +' to v'+ finalVersionTxt +'.');
}
},

openUpdatePage: function(version) {
var supportedLocales = ['en', 'fr'];
var locale = chrome.i18n.getMessage('@@ui_locale');
locale = (supportedLocales.indexOf(locale) != -1) ? locale : supportedLocales[0];

chrome.tabs.create({'url': chrome.extension.getURL('static/update-'+ version +'-'+ locale +'.html'), 'selected': true});
},

_updates: [
{'version': 10, 'update': function(callback) {

}},
{'version': 20, 'update': function(callback) {

}},
{'version': 30, 'update': function(callback) {

}}
]
};

window.s2s.UpdateService = UpdateService;
})(window.s2s.Logger);
10 changes: 1 addition & 9 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,7 @@ $(document).ready(function() {
var thisVersion = chrome.runtime.getManifest().version;
s2s.Logger.info('[core] Extension updated from '+ details.previousVersion +' to '+ thisVersion +'.');

// Only open update page for major versions
var majorUpdates = ['0.2.0'];
if(majorUpdates.indexOf(thisVersion) != -1) {
var supportedLocales = ['en', 'fr'];
var locale = chrome.i18n.getMessage('@@ui_locale');
locale = (supportedLocales.indexOf(locale) != -1) ? locale : supportedLocales[0];

chrome.tabs.create({'url': chrome.extension.getURL('static/update-'+ thisVersion +'-'+ locale +'.html'), 'selected': true});
}
s2s.UpdateService.update(details.previousVersion, thisVersion);
}
});
});

0 comments on commit 7a50bf3

Please sign in to comment.