Skip to content
Browse files

better first-run logic

  • Loading branch information...
1 parent 8ba0db8 commit 06fbc92f329256b8e7d152f19302b8564471768a @clipperhouse committed Feb 21, 2012
Showing with 25 additions and 3 deletions.
  1. +2 −0 .gitignore
  2. +23 −3 src/background.html
View
2 .gitignore
@@ -1,2 +1,4 @@
src.pem
+
+screen1.png
View
26 src/background.html
@@ -6,17 +6,37 @@
chrome.tabs.query({ url : "*://twitter.com/*" }, callback);
};
-var firstRun = function() {
+function onInstall() {
findTab(function(tabs) {
if (tabs.length) {
chrome.tabs.update(tabs[0].id, { url: "http://twitter.com", active: true });
} else {
chrome.tabs.create({ url: "http://twitter.com" });
}
});
-};
+}
+
+function onUpdate() {
+ onInstall();
+}
+
+function getVersion() {
+ var details = chrome.app.getDetails();
+ return details.version;
+}
+
+// Check if the version has changed.
+var currVersion = getVersion();
+var prevVersion = localStorage['version']
+if (currVersion != prevVersion) {
+ if (typeof prevVersion == 'undefined') {
+ onInstall();
+ } else {
+ onUpdate();
+ }
+ localStorage['version'] = currVersion;
+}
-firstRun();
chrome.browserAction.onClicked.addListener(function() {
findTab(function(tabs) {
if (tabs.length) {

0 comments on commit 06fbc92

Please sign in to comment.
Something went wrong with that request. Please try again.