Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created November 22, 2012 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebaldry/4133076 to your computer and use it in GitHub Desktop.
Save mikebaldry/4133076 to your computer and use it in GitHub Desktop.
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