From: Jason Boyer Date: Wed, 9 May 2018 00:55:51 +0000 (-0400) Subject: LP1731922: Add Firefox support to Hatch X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4a92f09ca0a79df558fd93dcb11dc71c7652e2cd;p=working%2FHatch.git LP1731922: Add Firefox support to Hatch 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 --- diff --git a/INSTALL.adoc b/INSTALL.adoc index 7982b3a16e..3ccfa14eb1 100644 --- a/INSTALL.adoc +++ b/INSTALL.adoc @@ -1,8 +1,8 @@ = Hatch Install Documentation = This documentation assumes Windows users will use the Hatch Windows -installer. The xref:linux[Linux]-only steps can also be done on Windows, but -are not documented here. +installer. The xref:linux[Linux]-only steps can also be done on Windows +from a source checkout but are not documented here. == Windows == @@ -18,20 +18,25 @@ Execute the 'Hatch-Installer-(version).exe' executable. NOTE: See installer/windows/README.adoc for building the Windows installer from Linux or Windows. When building the Windows installer -on Windows, the full JDK will be required (for compiling Java). +on Windows a full JDK is required for compiling. ==== Optional: Test Hatch ==== [source,sh] ------------------------------------------------------------------------- C:\>cd %ProgramFiles(x86)%\Hatch -C:\Program Files (x86)\Hatch>hatch.sh test +C:\Program Files (x86)\Hatch>hatch.bat test ------------------------------------------------------------------------- === Install Chrome Extension === If the extension was not installed automatically when installing Hatch you can get it directly in the browser from the -https://chrome.google.com/webstore/detail/hatch-native-messenger/ppooibdipmklfichpmkcgplfgdplgahl[Chrome App Store] +https://chrome.google.com/webstore/detail/hatch-native-messenger/ppooibdipmklfichpmkcgplfgdplgahl[Chrome App Store]. + +=== Install Firefox Extension === + +The Firefox extension can not be installed automatically by the native application installer; +https://addons.mozilla.org/en-US/firefox/addon/hatch-native-messenger/[it is available on the Firefox Addons site]. === Continue with xref:using-hatch[Using Hatch] === @@ -58,18 +63,18 @@ $ ./hatch.sh compile === Configure Native Messaging === -Edit extension/host/org.evergreen_ils.hatch.json and change the "path" +Edit extension/host/org.evergreen_ils.hatch.(chrome|firefox).json and change the "path" value to match the location of your copy of "hatch.sh", found in the root directory of the Hatch repository. -Copy the host file into Chrome's configuration directory. +Copy the correct host file, changing the filename to org.evergreen_ils.hatch.json, into the browser's configuration directory. For Chrome: [source,sh] ------------------------------------------------------------------------- $ mkdir -p ~/.config/google-chrome/NativeMessagingHosts/ -$ cp extension/host/org.evergreen_ils.hatch.json ~/.config/google-chrome/NativeMessagingHosts/ +$ cp extension/host/org.evergreen_ils.hatch.chrome.json ~/.config/google-chrome/NativeMessagingHosts/org.evergreen_ils.hatch.json ------------------------------------------------------------------------- For Chromium: @@ -77,19 +82,32 @@ For Chromium: [source,sh] ------------------------------------------------------------------------- $ mkdir -p ~/.config/chromium/NativeMessagingHosts/ -$ cp extension/host/org.evergreen_ils.hatch.json ~/.config/chromium/NativeMessagingHosts/ +$ cp extension/host/org.evergreen_ils.hatch.chrome.json ~/.config/chromium/NativeMessagingHosts/org.evergreen_ils.hatch.json +------------------------------------------------------------------------- + +For Firefox: + +[source,sh] +------------------------------------------------------------------------- +$ mkdir -p ~/.mozilla/native-messaging-hosts/ +$ cp extension/host/org.evergreen_ils.hatch.firefox.json ~/.mozilla/native-messaging-hosts/org.evergreen_ils.hatch.json ------------------------------------------------------------------------- === Install Chrome Extension === -Install the exenstion directly in the browser from the -https://chrome.google.com/webstore/detail/hatch-native-messenger/ppooibdipmklfichpmkcgplfgdplgahl[Chrome App Store] +Install the Chrome exenstion directly from the +https://chrome.google.com/webstore/detail/hatch-native-messenger/ppooibdipmklfichpmkcgplfgdplgahl[Chrome App Store]. + +=== Install Firefox Extension === + +Install the Firefox extension from the +https://addons.mozilla.org/en-US/firefox/addon/hatch-native-messenger/[Firefox Addons site]. ==== Optional: Test Hatch ==== NOTE: print commands are disabled by default in the tests to avoid -unexpected printing, but they can be added by un-commenting +unexpected printing but they can be added by un-commenting them in src/org/evergreen_ils/hatch/TestHatch.java and recompiling. [source,sh] @@ -132,7 +150,7 @@ Hatch responded to message ID 1 "Connecting to native messaging host: org.evergreen_ils.hatch" in the Background Page console with no errors. * Use the "Reload" link to apply local changes made to the - extension (e.g. main.js). (This might only work when installing + extension (e.g. extension.js). (This might only work when installing the exention manually via developer mode tools). * See also https://developer.chrome.com/extensions/getstarted diff --git a/extension/app/extension.js b/extension/app/extension.js index fddd095b19..a46a2d3299 100644 --- a/extension/app/extension.js +++ b/extension/app/extension.js @@ -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 diff --git a/extension/app/hatch_icon_128.png b/extension/app/hatch_icon_128.png deleted file mode 100644 index 86228e7be2..0000000000 Binary files a/extension/app/hatch_icon_128.png and /dev/null differ diff --git a/extension/app/hatch_icon_16.png b/extension/app/hatch_icon_16.png deleted file mode 100644 index 4981a0929a..0000000000 Binary files a/extension/app/hatch_icon_16.png and /dev/null differ diff --git a/extension/app/hatch_icon_48.png b/extension/app/hatch_icon_48.png deleted file mode 100644 index 1f1974a4e9..0000000000 Binary files a/extension/app/hatch_icon_48.png and /dev/null differ diff --git a/extension/app/icon_128.png b/extension/app/icon_128.png new file mode 100644 index 0000000000..f4133025c1 Binary files /dev/null and b/extension/app/icon_128.png differ diff --git a/extension/app/icon_48.png b/extension/app/icon_48.png new file mode 100644 index 0000000000..e9d713a10b Binary files /dev/null and b/extension/app/icon_48.png differ diff --git a/extension/app/icon_96.png b/extension/app/icon_96.png new file mode 100644 index 0000000000..5ba2cc4177 Binary files /dev/null and b/extension/app/icon_96.png differ diff --git a/extension/app/manifest.json b/extension/app/manifest.json index e953e356a6..4d3fd7c20e 100644 --- a/extension/app/manifest.json +++ b/extension/app/manifest.json @@ -1,12 +1,12 @@ { "name": "Hatch Native Messenger", - "version": "0.1.5", + "version": "0.2.0", "manifest_version": 2, - "description": "Relays messages to/from Hatch.", + "description": "Relays messages to/from the Hatch native printing service for the Evergreen ILS web client.", "icons": { - "16": "hatch_icon_16.png", - "48": "hatch_icon_48.png", - "128": "hatch_icon_128.png" + "48": "icon_48.png", + "96": "icon_96.png", + "128": "icon_128.png" }, "background" : { "scripts" : ["extension.js"] @@ -19,10 +19,21 @@ } ], "browser_action": { - "default_title": "Hatch" + "default_title": "Hatch", + "default_icon": { + "48": "icon_48.png", + "96": "icon_96.png", + "128": "icon_128.png" + } }, "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 index 0000000000..8cf84211f2 --- /dev/null +++ b/extension/host/org.evergreen_ils.hatch.chrome.json @@ -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 index 0000000000..85dea656b3 --- /dev/null +++ b/extension/host/org.evergreen_ils.hatch.firefox.json @@ -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 index 8cf84211f2..0000000000 --- a/extension/host/org.evergreen_ils.hatch.json +++ /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/" - ] -} diff --git a/hatch.bat b/hatch.bat index 1b208f873c..dd76b2e151 100755 --- 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^ diff --git a/installer/windows/hatch.nsi b/installer/windows/hatch.nsi index 68fed3e904..06731f321c 100644 --- a/installer/windows/hatch.nsi +++ b/installer/windows/hatch.nsi @@ -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