Permalink
Browse files

store the data about firstRun and runcount in prefs, hopefully avoidi…

…ng cookie badness.
  • Loading branch information...
funkatron committed Apr 29, 2011
1 parent d6a08a4 commit 5f2ce4d958d0cf9808ce28f5e038f7617832c0a3
Showing with 48 additions and 60 deletions.
  1. +1 −1 app/assistants/app-assistant.js
  2. +40 −58 app/models/versioncookie.js
  3. +7 −1 default_preferences.js
@@ -185,7 +185,7 @@ AppAssistant.prototype.initialize = function() {
}
- this.App.versionCookie = new VersionCookie();
+ this.App.versionCookie = new VersionCookie(this.App.prefs);
this.App.versionCookie.init();
};
@@ -354,71 +354,53 @@
*
*/
-function VersionCookie()
-{
- this.cookie = false;
- this.isFirst = false;
- this.isNew = false;
- this.runs = 0;
- //this.init();
+function VersionCookie(prefsObj) {
+ if (!prefsObj) {
+ Mojo.Log.error('VersionCookie constructor must be passed a SpazPrefs object');
+ }
+
+ this.prefsObj = prefsObj;
};
+
VersionCookie.prototype.init = function()
{
- try
- {
- // reset these
- this.cookie = false;
- this.isFirst = false;
- this.isNew = false;
- this.runs = 0;
-
- this.cookie = new Mojo.Model.Cookie('version');
- // uncomment to delete cookie for testing
- // this.cookie.remove();
+ // load it
+ this.get();
+
+ Mojo.Log.error('Runs %s', this.runs);
+
+ if (this.lastVersion == Mojo.appInfo.version) {
+ Mojo.Log.info('Same Version %s', this.lastVersion, Mojo.appInfo.version);
+ } else {
+ Mojo.Log.info('New Version %s %s', this.lastVersion, Mojo.appInfo.version);
+ this.isNew = true;
+ }
+
+ // save it
+ this.put();
- var data = this.cookie.get();
- if (data)
- {
-
- this.runs = data.runs||0;
- Mojo.Log.error('Runs %s', this.runs);
-
- if (data.version == Mojo.appInfo.version)
- {
- Mojo.Log.error('Same Version %s', data.version, Mojo.appInfo.version);
- }
- else
- {
- Mojo.Log.error('New Version %s %s', data.version, Mojo.appInfo.version);
- this.isNew = true;
- }
- this.put();
- }
- else
- {
- Mojo.Log.error('First Launch (no cookie data)');
- this.isFirst = true;
- this.isNew = true;
- this.runs = 0;
- this.put();
- }
- // uncomment to delete cookie for testing
- // this.cookie.remove();
- }
- catch (e)
- {
- Mojo.Log.logException(e, 'VersionCookie#init');
- }
};
-VersionCookie.prototype.put = function()
-{
- this.cookie.put({version: Mojo.appInfo.version, runs: (this.runs+1)});
- // uncomment to set lower version for testing
- // this.cookie.put({version: '0.0.1', runs:9});
+
+VersionCookie.prototype.get = function() {
+ this.lastVersion = this.prefsObj.get('run-lastVersion');
+ this.isFirst = this.prefsObj.get('run-isFirst');
+ this.runs = this.prefsObj.get('run-count');
+ Mojo.Log.info('VersionCookie.get: %s %s %s', this.lastVersion, this.isFirst, this.runs);
};
-VersionCookie.prototype.showStartupScene = function()
-{
+
+VersionCookie.prototype.put = function() {
+ this.prefsObj.set('run-lastVersion', Mojo.appInfo.version);
+ this.prefsObj.set('run-isFirst', false);
+ this.prefsObj.set('run-count', (this.runs+1));
+ Mojo.Log.info('VersionCookie.put: %s %s %s',
+ this.prefsObj.get('run-lastVersion'),
+ this.prefsObj.get('run-isFirst'),
+ this.prefsObj.get('run-count')
+ );
+};
+
+VersionCookie.prototype.showStartupScene = function() {
if (this.isNew || this.isFirst) return true;
else return false;
};
View
@@ -63,5 +63,11 @@ var default_preferences = {
'timeline-text-size': 'tall', // also grande, venti
'post-rt-cursor-position': 'beginning', // 'beginning' or 'end'
- 'post-send-on-enter': true
+ 'post-send-on-enter': true,
+
+ // track run data that was once in VersionCookie
+ 'run-lastVersion':'0.0.1',
+ 'run-isFirst':true,
+ 'run-isNew':true,
+ 'run-count':0
};

0 comments on commit 5f2ce4d

Please sign in to comment.