LP1731922: Add Firefox support to Hatch user/csharp/lp1731922_ff_support_signoff
authorJason Boyer <JBoyer@library.in.gov>
Wed, 9 May 2018 00:55:51 +0000 (20:55 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Tue, 6 Nov 2018 19:53:15 +0000 (14:53 -0500)
Firefox has an unnecessarily picky manifest parser
so it requires a separate manifest, and there was
also an issue with the batch file and quoting
command line parameters that was causing silent
failures.

The installer has also been updated to put the
necessary NativeMessagingHosts key in place but
FF doesn't offer the same kind of auto-install
abilities that Chrome does.

Signed-off-by: Jason Boyer <JBoyer@library.in.gov>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
extension/app/extension.js
extension/app/manifest.json
extension/host/org.evergreen_ils.hatch.chrome.json [new file with mode: 0644]
extension/host/org.evergreen_ils.hatch.firefox.json [new file with mode: 0644]
extension/host/org.evergreen_ils.hatch.json [deleted file]
hatch.bat
installer/windows/hatch.nsi

index fddd095..a46a2d3 100644 (file)
@@ -39,10 +39,19 @@ function connectToHatch() {
 /**
  * Called when the connection to Hatch goes away.
  */
-function onDisconnected() {
-  console.warn("Hatch disconnected: " + chrome.runtime.lastError.message);
+function onDisconnected(port) {
+  var reason = "unspecified reason";
+
+  if (port && port.error) {
+    reason = port.error.message;
+  } else if (chrome.runtime.lastError) {
+    reason = chrome.runtime.lastError.message;
+  }
+
+  console.warn("Hatch disconnected: " + reason);
   hatchPort = null;
 
+  // Firefox gives some indication a NativeMessaging app doesn't exist, does Chrome? (port.error.message starts with No such...)
   if (hatchHostUnavailable) return;
 
   // If we can reasonablly assume a connection to the Hatch host 
index e953e35..2c48b4e 100644 (file)
   "permissions": [
     "nativeMessaging"
   ],
+  "applications": {
+    "gecko": {
+      "id": "hatch-native-messenger@evergreen-ils.org",
+      "strict_min_version": "50.0"
+    }
+  },
   "minimum_chrome_version": "38"
 }
diff --git a/extension/host/org.evergreen_ils.hatch.chrome.json b/extension/host/org.evergreen_ils.hatch.chrome.json
new file mode 100644 (file)
index 0000000..8cf8421
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "name": "org.evergreen_ils.hatch",
+  "description": "Hatch Native Messaging Host",
+  "path": "/path/to/hatch.sh",
+  "type": "stdio",
+  "allowed_origins": [
+    "chrome-extension://ppooibdipmklfichpmkcgplfgdplgahl/"
+  ]
+}
diff --git a/extension/host/org.evergreen_ils.hatch.firefox.json b/extension/host/org.evergreen_ils.hatch.firefox.json
new file mode 100644 (file)
index 0000000..85dea65
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "name": "org.evergreen_ils.hatch",
+  "description": "Hatch Native Messaging Host",
+  "path": "/path/to/hatch.sh",
+  "type": "stdio",
+  "allowed_extensions": [
+    "hatch-native-messenger@evergreen-ils.org"
+  ]
+}
diff --git a/extension/host/org.evergreen_ils.hatch.json b/extension/host/org.evergreen_ils.hatch.json
deleted file mode 100644 (file)
index 8cf8421..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-  "name": "org.evergreen_ils.hatch",
-  "description": "Hatch Native Messaging Host",
-  "path": "/path/to/hatch.sh",
-  "type": "stdio",
-  "allowed_origins": [
-    "chrome-extension://ppooibdipmklfichpmkcgplfgdplgahl/"
-  ]
-}
index 1b208f8..dd76b2e 100755 (executable)
--- a/hatch.bat
+++ b/hatch.bat
@@ -30,12 +30,17 @@ SET JAVA=%PROGRAMDATA%\Oracle\Java\javapath\java
 IF %ERRORLEVEL% EQU 0 GOTO Huzzah
 
 REM I don't blame you
-EXIT %ERRORLEVEL%
+EXIT /B %ERRORLEVEL%
 
 REM There you are.
 :Huzzah
 
-IF "%1" == "compile" (
+REM %~1 means to strip %1 of any surrounding quotes.
+REM This is necessary if you're going to use a construction like "%1" == "etc" because a quoted %1 will
+REM cause silent failures when the batch file is run and dies because the IF command has a syntax error.
+REM Specifically, "Files was unexpected at this time."
+
+IF "%~1" == "compile" (
 
     %JAVAC% -cp "lib\*" -Xdiags:verbose^
         -d lib src\org\evergreen_ils\hatch\*.java
@@ -45,7 +50,7 @@ IF "%1" == "compile" (
 
 ) ELSE (
 
-    IF "%1" == "test" (
+    IF "%~1" == "test" (
 
         %JAVA% -cp "lib\*"^
             -Djava.util.logging.config.file=logging.properties^
index 68fed3e..06731f3 100644 (file)
@@ -62,6 +62,10 @@ ${EndIf}
 
 ; Find any installed JRE/JDK and return the version or -1
 Function DetectJava
+    ; FYI: Because it appears there won't ever be a 64 bit version of makensis for linux
+    ; this script assumes that it will always be run as part of a 32 bit installer.
+    ; If that should ever change this script will require some significant adjustment.
+
     ; 32 bit JRE >= 9
     ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\JRE" "CurrentVersion"
     StrCmp $0 "" +1 Found
@@ -173,14 +177,13 @@ section "install"
     File ..\..\hatch.bat
     File ..\..\hatch.properties
     File ..\..\logging.properties
-    
-    ; Set path variable in org.ils_evergreen.hatch.json to $INSTDIR\hatch.bat
-    ${StrRep} '$0' '$INSTDIR' '\' '\\'
-    !insertmacro _ReplaceInFile  "$INSTDIR\extension\host\org.evergreen_ils.hatch.json" "/path/to/hatch.sh" "$0\\hatch.bat"
-    AccessControl::EnableFileInheritance "$INSTDIR\extension\host\org.evergreen_ils.hatch.json"
 
-    ; Uninstaller
-    writeUninstaller "$INSTDIR\Uninstall ${APPNAME}.exe"
+    ; Set path variable in org.ils_evergreen.hatch.*.json to $INSTDIR\hatch.bat
+    ${StrRep} '$0' '$INSTDIR' '\' '\\'
+    !insertmacro _ReplaceInFile  "$INSTDIR\extension\host\org.evergreen_ils.hatch.chrome.json" "/path/to/hatch.sh" "$0\\hatch.bat"
+    !insertmacro _ReplaceInFile  "$INSTDIR\extension\host\org.evergreen_ils.hatch.firefox.json" "/path/to/hatch.sh" "$0\\hatch.bat"
+    AccessControl::EnableFileInheritance "$INSTDIR\extension\host\org.evergreen_ils.hatch.chrome.json"
+    AccessControl::EnableFileInheritance "$INSTDIR\extension\host\org.evergreen_ils.hatch.firefox.json"
 
     ; Registry info for Add/Remove Programs
     WriteRegStr HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}" "Install Path" $INSTDIR
@@ -207,8 +210,25 @@ section "install"
     WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
 
     ; Connect Hatch to Chrome and install the Hatch extension from the Chrome Web Store
-    WriteRegStr HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.json"
+    WriteRegStr HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.chrome.json"
     WriteRegStr HKLM "Software\Google\Chrome\Extensions\${EXTENSIONID}" "update_url" "${EXTENSION_UPDATEURL}"
+
+    ; Firefox won't check both the 32 and 64 bit views, so it's on us to put the key in the right place.
+    ; Firefox doesn't allow automatic installation of remote extensions either, so there's no (good) auto-install option here. :-/
+    ; A link should be added to the web client to simplify locating the FF extension. (Links to both would likely be a good practice.)
+    ${If} ${RunningX64}
+        SetRegView 64
+    ${EndIf}
+
+    WriteRegStr HKLM "SOFTWARE\Mozilla\NativeMessagingHosts\org.evergreen_ils.hatch" "" "$INSTDIR\extension\host\org.evergreen_ils.hatch.firefox.json"
+
+    ${If} ${RunningX64}
+        SetRegView 32
+    ${EndIf}
+
+    ; Uninstaller
+    writeUninstaller "$INSTDIR\Uninstall ${APPNAME}.exe"
+
 SectionEnd
 
 
@@ -217,7 +237,7 @@ SectionEnd
 
 function un.onInit
     SetShellVarContext all
-    
+
     # Verify uninstaller
     MessageBox MB_OKCANCEL "Permanently remove ${APPNAME}?" /SD IDOK IDOK next
         Abort
@@ -225,7 +245,7 @@ function un.onInit
     !insertmacro VerifyUserIsAdmin
 functionEnd
 
-section "uninstall"    
+section "uninstall"
     # Remove the actual files
     Delete /REBOOTOK "$INSTDIR\hatch.bat"
     Delete /REBOOTOK "$INSTDIR\hatch.properties"
@@ -235,18 +255,25 @@ section "uninstall"
     RmDir /r /REBOOTOK "$INSTDIR\lib"
     # Delete uninstaller last
     Delete /REBOOTOK "$INSTDIR\Uninstall ${APPNAME}.exe"
-    
+
     # Remove installation directory
     RmDir /REBOOTOK "$INSTDIR"
-    
+
     # Remove uninstaller info from registry
     DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}\${APPNAME}"
     DeleteRegKey HKLM "SOFTWARE\${COMPANYNAME}"
     DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"
     DeleteRegKey HKLM "SOFTWARE\Google\Chrome\NativeMessagingHosts\org.evergreen_ils.hatch"
     DeleteRegKey HKLM "SOFTWARE\Google\Chrome\Extensions\${EXTENSIONID}"
+
     ${If} ${RunningX64}
-        DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Google\Chrome\Extensions\${EXTENSIONID}"
+        SetRegView 64
+    ${EndIf}
+
+    DeleteRegKey HKLM "SOFTWARE\Mozilla\NativeMessagingHosts\org.evergreen_ils.hatch"
+
+    ${If} ${RunningX64}
+        SetRegView 32
     ${EndIf}
 
     IfRebootFlag 0 Done
@@ -254,5 +281,5 @@ section "uninstall"
     Reboot
 
     Done:
-    
+
 sectionEnd