Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 95ddd44

Browse files
committed
fix #75: check CFBundleIconFile before AppleScript dialogs are displayed
check for undefined icons or icon names without .icns extension and prepare an osascript statement for those cases when the icon can be shown in the dialog
1 parent 6aae09f commit 95ddd44

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/universalJavaApplicationStub

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# #
1212
# @author Tobias Fischer #
1313
# @url https://github.com/tofi86/universalJavaApplicationStub #
14-
# @date 2019-12-08 #
14+
# @date 2019-12-09 #
1515
# @version 3.0.4 #
1616
# #
1717
##################################################################################
@@ -292,6 +292,18 @@ else
292292
fi
293293

294294

295+
# (#75) check for undefined icons or icon names without .icns extension and prepare
296+
# an osascript statement for those cases when the icon can be shown in the dialog
297+
DialogWithIcon=""
298+
if [ ! -z ${CFBundleIconFile} ]; then
299+
if [[ ${CFBundleIconFile} == *.icns ]] && [[ -f "${ResourcesFolder}/${CFBundleIconFile}" ]] ; then
300+
DialogWithIcon=" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
301+
elif [[ ${CFBundleIconFile} != *.icns ]] && [[ -f "${ResourcesFolder}/${CFBundleIconFile}.icns" ]] ; then
302+
CFBundleIconFile+=".icns"
303+
DialogWithIcon=" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
304+
fi
305+
fi
306+
295307

296308
# JVMVersion: post processing and optional splitting
297309
if [[ ${JVMVersion} == *";"* ]]; then
@@ -518,7 +530,7 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
518530
# log exit cause
519531
stub_logger "[EXIT 4] ${MSG_JVMVERSION_REQ_INVALID_EXPANDED}"
520532
# display error message with AppleScript
521-
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_JVMVERSION_REQ_INVALID_EXPANDED}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
533+
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_JVMVERSION_REQ_INVALID_EXPANDED}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1${DialogWithIcon}"
522534
# exit with error
523535
exit 4
524536
fi
@@ -528,7 +540,7 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
528540
# log exit cause
529541
stub_logger "[EXIT 5] ${MSG_JVMVERSION_REQ_INVALID_EXPANDED}"
530542
# display error message with AppleScript
531-
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_JVMVERSION_REQ_INVALID_EXPANDED}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
543+
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_JVMVERSION_REQ_INVALID_EXPANDED}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1${DialogWithIcon}"
532544
# exit with error
533545
exit 5
534546
fi
@@ -705,7 +717,7 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
705717
stub_logger "[EXIT 3] ${MSG_NO_SUITABLE_JAVA_EXPANDED}"
706718

707719
# display error message with AppleScript
708-
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_NO_SUITABLE_JAVA_EXPANDED}\n${MSG_NO_SUITABLE_JAVA_CHECK}\" with title \"${CFBundleName}\" buttons {\" OK \", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" \
720+
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_NO_SUITABLE_JAVA_EXPANDED}\n${MSG_NO_SUITABLE_JAVA_CHECK}\" with title \"${CFBundleName}\" buttons {\" OK \", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\"${DialogWithIcon}" \
709721
-e "set response to button returned of the result" \
710722
-e "if response is \"${MSG_VISIT_JAVA_DOT_COM}\" then open location \"http://java.com\""
711723
# exit with error
@@ -715,7 +727,7 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
715727
# log exit cause
716728
stub_logger "[EXIT 1] ${MSG_ERROR_LAUNCHING}"
717729
# display error message with AppleScript
718-
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_INSTALL_JAVA}\" with title \"${CFBundleName}\" buttons {\"${MSG_LATER}\", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\" with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)" \
730+
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_INSTALL_JAVA}\" with title \"${CFBundleName}\" buttons {\"${MSG_LATER}\", \"${MSG_VISIT_JAVA_DOT_COM}\"} default button \"${MSG_VISIT_JAVA_DOT_COM}\"${DialogWithIcon}" \
719731
-e "set response to button returned of the result" \
720732
-e "if response is \"${MSG_VISIT_JAVA_DOT_COM}\" then open location \"http://java.com\""
721733
# exit with error
@@ -732,7 +744,7 @@ if [ -z "${JVMMainClass}" ]; then
732744
# log exit cause
733745
stub_logger "[EXIT 2] ${MSG_MISSING_MAINCLASS}"
734746
# display error message with AppleScript
735-
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_MISSING_MAINCLASS}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1 with icon path to resource \"${CFBundleIconFile}\" in bundle (path to me)"
747+
osascript -e "tell application \"System Events\" to display dialog \"${MSG_ERROR_LAUNCHING}\n\n${MSG_MISSING_MAINCLASS}\" with title \"${CFBundleName}\" buttons {\" OK \"} default button 1${DialogWithIcon}"
736748
# exit with error
737749
exit 2
738750
fi

0 commit comments

Comments
 (0)