Created
November 22, 2012 21:58
-
-
Save mikebaldry/4133076 to your computer and use it in GitHub Desktop.
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
class VersionDetection | |
constructor: (@persistentStorage, @callbacks) -> | |
execute: -> | |
installedVersion = this._parseVersion @persistentStorage["installedVersion"] | |
version = this._parseVersion this._getVersion() | |
return this._onInstalled(version) unless installedVersion | |
return if installedVersion.string == version.string | |
if installedVersion.major == version.major && installedVersion.minor == version.minor | |
this._onUpdatedPatch installedVersion, version | |
else | |
this._onUpdated installedVersion, version | |
_getVersion: -> | |
chrome.app.getDetails().version | |
_parseVersion: (version) -> | |
return null unless version | |
parts = version.split(".") | |
string: version | |
major: parts[0] | |
minor: if parts.length > 1 then parts[1] else 0 | |
patch: if parts.length > 2 then parts[2] else 0 | |
_onInstalled: (version) -> | |
@callbacks["installed"].call(this, version) | |
this._recordVersion version.string | |
_onUpdated: (oldVersion, newVersion) -> | |
@callbacks["updated"].call(this, oldVersion, newVersion) | |
this._recordVersion newVersion.string | |
_onUpdatedPatch: (oldVersion, newVersion) -> | |
@callbacks["updatedPatch"].call(this, oldVersion, newVersion) | |
this._recordVersion newVersion.string | |
_recordVersion: (version) -> | |
@persistentStorage["installedVersion"] = version | |
exports = VersionDetection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment