From ca497170d319fee33ee23f74cebe8a65ec18970b Mon Sep 17 00:00:00 2001 From: Chris Hastie Date: Wed, 21 Dec 2011 08:40:42 +0000 Subject: [PATCH] Show release notes at first run after upgrade --- content/overlay.js | 37 +++++++++++++++++++++++++++++++ content/utils.js | 17 +++++++++----- defaults/preferences/tbdialout.js | 2 ++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/content/overlay.js b/content/overlay.js index cb55ecb..0cc9b0f 100644 --- a/content/overlay.js +++ b/content/overlay.js @@ -56,6 +56,43 @@ var tbdialout = { if (!passmigrated) { tbdialoututils.migratePass(); } + + // If TBDialOut has been upgraded since the last time we showed upgrade notes, + // show the notes for the current version. + var updateshown = this.prefs.getCharPref("updateshown"); + var showupdatenotes = this.prefs.getBoolPref("showupdatenotes"); + // a false default should override user prefs, as there probably + // are no notes to display + if (showupdatenotes && this.prefs.prefHasUserValue("showupdatenotes")) { + showupdatenotes = false; + } + + try { + Components.utils.import("resource://gre/modules/AddonManager.jsm"); + AddonManager.getAddonByID("tbdialout@oak-wood.co.uk", function(addon) { + // This is an asynchronous callback function that might not be called immediately + if (showupdatenotes && addon.version != updateshown) { + window.setTimeout(function() { + tbdialoututils.openInTab("http://www.oak-wood.co.uk/oss/tbdialout/updates/" + addon.version.replace(/\./g,'-'), "^http://www.oak-wood.co.uk", false);}, + 500); + var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.tbdialout."); + prefs.setCharPref("updateshown", addon.version); + } + }); + } + catch (ex) { + // pre Thunderbird 3.3 + var em = Components.classes["@mozilla.org/extensions/manager;1"] + .getService(Components.interfaces.nsIExtensionManager); + var addon = em.getItemForID("tbdialout@oak-wood.co.uk"); + if (showupdatenotes && addon.version != updateshown) { + window.setTimeout(function() { + tbdialoututils.openInTab("http://www.oak-wood.co.uk/oss/tbdialout/updates/" + addon.version.replace(/\./g,'-'), "^http://www.oak-wood.co.uk", false);}, + 500); + this.prefs.setCharPref("updateshown", addon.version); + } + } + }, // Check whether or not there are phone numbers for the selected diff --git a/content/utils.js b/content/utils.js index 5589da0..1f14aed 100644 --- a/content/utils.js +++ b/content/utils.js @@ -85,7 +85,9 @@ var tbdialoututils = { // clickmask is a string representation of a regular expression defining URLs which // may be clicked through to within the tab. - openInTab: function (url, clickmask) { + openInTab: function (url, clickmask, setfocus) { + setfocus = typeof(setfocus) != 'undefined' ? setfocus : true; + // try to open the page in a new tab with Thunderbird var tabmail = document.getElementById("tabmail"); if (!tabmail) { @@ -95,7 +97,9 @@ var tbdialoututils = { .getMostRecentWindow("mail:3pane"); if (mail3PaneWindow) { tabmail = mail3PaneWindow.document.getElementById("tabmail"); - mail3PaneWindow.focus(); + if (setfocus) { + mail3PaneWindow.focus(); + } } } // allow user to click within the sites defined by the regexp mask @@ -116,16 +120,17 @@ var tbdialoututils = { var passtypes = ["custompass", "ami.secret"]; var idx; var pass; - try { - for (idx in passtypes) { + for (idx in passtypes) { + try { pass = this.prefs.getCharPref( passtypes[idx] ); if (pass.length > 0) { this.setPass(passtypes[idx], pass); } this.prefs.clearUserPref(passtypes[idx]); } - } catch (err) { - tbdialoututils.logger(1, "Error migrating passwords: " + err.message); + catch (err) { + tbdialoututils.logger(1, "Error migrating password " + passtypes[idx] + ": " + err.message); + } } this.prefs.setBoolPref("passmigrated", true); }, diff --git a/defaults/preferences/tbdialout.js b/defaults/preferences/tbdialout.js index 6d01331..af5c78f 100644 --- a/defaults/preferences/tbdialout.js +++ b/defaults/preferences/tbdialout.js @@ -7,6 +7,8 @@ pref( "extensions.tbdialout.customuser", "" ); pref( "extensions.tbdialout.custominbackground", true ); pref( "extensions.tbdialout.loglevel", 2); pref( "extensions.tbdialout.passmigrated", false ); +pref( "extensions.tbdialout.updateshown", "" ); +pref( "extensions.tbdialout.showupdatenotes", true); pref( "extensions.tbdialout.ami.channel", "" ); pref( "extensions.tbdialout.ami.context", "default" ); pref( "extensions.tbdialout.ami.host", "" );