Commits

Matthew Schinckel committed b80b5b7

Better handling when plugin is not installed.
Could still be better than this, though?

Comments (0)

Files changed (2)

contrib/knockout.garmin.js

   var selectedDevice = ko.observable(null);
   var busy = ko.observable(false);
   
-  // Kick off a findDevices, store the found devices in devices.
-  plugin.findDevices(devices);
+  this.pluginNotInstalled = !plugin.installed;
+  
+  if (plugin.installed) {
+    plugin.findDevices(devices);
+  }
   
   // Observable properties
   this.busy = ko.computed(function(){
     if (window.Garmin.Communicator) {
       return;
     }
-    throw new Error("Garmin namespace appears to exist, and it's not our. Bailing out.");
+    throw new Error("Garmin namespace appears to exist, and it's not us. Bailing out.");
   }
   
   var Garmin = window.Garmin = {};
     // We need to have a flag so we can't try to have two things happening at once.
     var inUse = false;
     var currentDevice = null;
-    var plugin = this.plugin = new Garmin.Plugin();
+    var plugin = Garmin.Plugin();
     var $plugin = $(plugin);
     var unlockCodes = [
       "file:///","cb1492ae040612408d87cc53e3f7ff3c",
         
     // See if the plugin is actually installed.
     if (!plugin.Unlock) {
-      throw new Error("Could not find Communicator Plugin");
+      this.installed = false;
+      this.installationInstructions = {
+        heading: "Plugin not installed",
+        message: [
+          "The Garmin Communicator plugin could not be loaded.",
+          "<a href='http://www.garmin.com/products/communicator'>Install the plugin</a>."
+        ]
+      };
+      // throw new Error("Could not find Communicator Plugin");
       // We could have a default way of dealing with this...
       return;
     }
     
+    this.installed = true;
+    
     // Unlock the plugin (or die trying)
     unlock(_.union(unlockCodes, options.unlockCodes || []));
     
     // wait for other initialisation to finish, then search for devices.
     setTimeout(this.findDevices, 0);
   };
-})(jQuery);
+})(jQuery);