Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ tasks.register('devClient', JavaExec) {
'--add-opens=java.base/sun.security.pkcs=ALL-UNNAMED',
'--add-opens=java.base/sun.security.rsa=ALL-UNNAMED',
'--add-opens=java.base/sun.security.x509=ALL-UNNAMED',
'--add-opens=java.desktop/com.apple.eawt=ALL-UNNAMED',
'--add-opens=java.desktop/com.apple.eio=ALL-UNNAMED',
'--add-opens=java.desktop/java.awt=ALL-UNNAMED',
'--add-opens=java.desktop/java.awt.color=ALL-UNNAMED',
'--add-opens=java.desktop/java.awt.font=ALL-UNNAMED',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package com.mirth.connect.client.ui;

import java.awt.Desktop;
import java.net.URI;
import java.util.Arrays;

/**
Expand Down Expand Up @@ -40,31 +42,17 @@ public class BareBonesBrowserLaunch {
* <code>"https://dna-engine.org/"</code>)
*/
public static void openURL(String url) {
try { // attempt to use Desktop library from JDK 1.6+
Class<?> d = Class.forName("java.awt.Desktop");
d.getDeclaredMethod("browse",
new Class<?>[] { java.net.URI.class }).invoke(
d.getDeclaredMethod("getDesktop").invoke(null),
new Object[] { java.net.URI.create(url) });
} catch (Exception ignore) { // library not available or failed
String osName = System.getProperty("os.name");
try {
Desktop.getDesktop().browse(URI.create(url));
} catch (Exception ignore) { // Desktop not supported or failed, assume Unix or Linux
try {
if (osName.startsWith("Mac OS")) {
Class.forName("com.apple.eio.FileManager").getDeclaredMethod(
"openURL", new Class<?>[] { String.class }).invoke(null,
new Object[] { url });
} else if (osName.startsWith("Windows"))
Runtime.getRuntime().exec(new String[] {
"rundll32", "url.dll,FileProtocolHandler", url });
else { // assume Unix or Linux
String browser = null;
for (String b : browsers)
if (browser == null
&& Runtime.getRuntime().exec(new String[] { "which", b }).getInputStream().read() != -1)
Runtime.getRuntime().exec(new String[] { browser = b, url });
if (browser == null)
throw new Exception(Arrays.toString(browsers));
}
String browser = null;
for (String b : browsers)
if (browser == null
&& Runtime.getRuntime().exec(new String[] { "which", b }).getInputStream().read() != -1)
Runtime.getRuntime().exec(new String[] { browser = b, url });
if (browser == null)
throw new Exception(Arrays.toString(browsers));
Comment on lines +49 to +55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just go for the exec? This seems like it is a TOCTOU. Presumably the exec of the browser will fail sufficiently to avoid which - which is not required to be present as a binary in the first place - it's normally a shell built-in.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was preexisting code that came from the upsteam launcher. It's only showing up here because of a whitespace change.

It's iterating through an array of options, so we'd need to wrap it in a new try/catch to ignore all of the exceptions until it exhausts the list. I'm not sure what we would gain since this works in all Linux environments I've tested it in.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you review only commit 2 and hide whitespace changes, this change is just a delete and directly importing Desktop instead of finding it by reflection.

} catch (Exception e) {
PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, e);
}
Expand Down
17 changes: 14 additions & 3 deletions client/src/main/java/com/mirth/connect/client/ui/Mirth.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,20 @@ public static void initUIManager() {
createAlternateKeyBindings();
}

if (SystemUtils.IS_OS_MAC) {
OSXAdapter.setAboutHandler(Mirth.class, Mirth.class.getDeclaredMethod("aboutMac", (Class[]) null));
OSXAdapter.setQuitHandler(Mirth.class, Mirth.class.getDeclaredMethod("quitMac", (Class[]) null));
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.APP_ABOUT)) {
desktop.setAboutHandler(e -> aboutMac());
}
if (desktop.isSupported(Desktop.Action.APP_QUIT_HANDLER)) {
desktop.setQuitHandler((e, response) -> {
if (quitMac()) {
response.performQuit();
} else {
response.cancelQuit();
}
});
}
}
} catch (Exception e) {
LogManager.getLogger(Mirth.class).error("Error initializing look and feel", e);
Expand Down
302 changes: 0 additions & 302 deletions client/src/main/java/com/mirth/connect/client/ui/OSXAdapter.java

This file was deleted.

Loading
Loading