-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UpdateService to manage versions updates
- Loading branch information
1 parent
d65973d
commit 7a50bf3
Showing
3 changed files
with
61 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters