diff --git a/weasis-distributions/script/resources/macosx/run.sh b/weasis-distributions/script/resources/macosx/run.sh
deleted file mode 100644
index 21d289eb8..000000000
--- a/weasis-distributions/script/resources/macosx/run.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-# Get the path to the directory containing this script
-SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
-"$SCRIPT_DIR/Weasis" "$@"
\ No newline at end of file
diff --git a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Info.plist b/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Info.plist
deleted file mode 100755
index d5d58a66e..000000000
--- a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Info.plist
+++ /dev/null
@@ -1,93 +0,0 @@
-
-
-
-
- NSUIElement
-
- CFBundleAllowMixedLocalizations
-
- CFBundleDevelopmentRegion
- en
- CFBundleExecutable
- applet
- CFBundleIconFile
- applet
- CFBundleIdentifier
- com.apple.ScriptEditor.id.weasis-url-handler
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleName
- weasis-url-handler
- CFBundlePackageType
- APPL
- CFBundleShortVersionString
- 1.0
- CFBundleSignature
- aplt
- LSMinimumSystemVersionByArchitecture
-
- x86_64
- 10.13
-
- LSRequiresCarbon
-
- NSAppleEventsUsageDescription
- This script needs to control other applications to run.
- NSAppleMusicUsageDescription
- This script needs access to your music to run.
- NSCalendarsUsageDescription
- This script needs access to your calendars to run.
- NSCameraUsageDescription
- This script needs access to your camera to run.
- NSContactsUsageDescription
- This script needs access to your contacts to run.
- NSHomeKitUsageDescription
- This script needs access to your HomeKit Home to run.
- NSMicrophoneUsageDescription
- This script needs access to your microphone to run.
- NSPhotoLibraryUsageDescription
- This script needs access to your photos to run.
- NSRemindersUsageDescription
- This script needs access to your reminders to run.
- NSSiriUsageDescription
- This script needs access to Siri to run.
- NSSystemAdministrationUsageDescription
- This script needs access to administer this system to run.
- WindowState
-
- bundleDividerCollapsed
-
- bundlePositionOfDivider
- 0.0
- dividerCollapsed
-
- eventLogLevel
- 2
- name
- ScriptWindowState
- positionOfDivider
- 355
- savedFrame
- 1345 248 700 672 0 0 2560 1417
- selectedTab
- result
-
- CFBundleURLTypes
-
-
- CFBundleTypeRole
- Editor
- CFBundleURLName
- Weasis URI Handler
- LSIsAppleDefaultForType
- Yes
- CFBundleURLSchemes
-
- weasis
-
-
-
-
-
\ No newline at end of file
diff --git a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/MacOS/applet b/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/MacOS/applet
deleted file mode 100755
index 5f4e5e5eb..000000000
Binary files a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/MacOS/applet and /dev/null differ
diff --git a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/PkgInfo b/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/PkgInfo
deleted file mode 100755
index 3253614c4..000000000
--- a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/PkgInfo
+++ /dev/null
@@ -1 +0,0 @@
-APPLaplt
\ No newline at end of file
diff --git a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/Scripts/main.scpt b/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/Scripts/main.scpt
deleted file mode 100755
index 776a514ee..000000000
Binary files a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/Scripts/main.scpt and /dev/null differ
diff --git a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/applet.icns b/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/applet.icns
deleted file mode 100755
index 0cdd17086..000000000
Binary files a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/applet.icns and /dev/null differ
diff --git a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/applet.rsrc b/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/applet.rsrc
deleted file mode 100755
index a2067c213..000000000
Binary files a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/applet.rsrc and /dev/null differ
diff --git a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/description.rtfd/TXT.rtf b/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/description.rtfd/TXT.rtf
deleted file mode 100755
index 962bd7bb7..000000000
--- a/weasis-distributions/script/resources/macosx/weasis-url-handler.app/Contents/Resources/description.rtfd/TXT.rtf
+++ /dev/null
@@ -1,5 +0,0 @@
-{\rtf1\ansi\ansicpg1252\cocoartf2513
-\cocoatextscaling0\cocoaplatform0{\fonttbl}
-{\colortbl;\red255\green255\blue255;}
-{\*\expandedcolortbl;;}
-}
\ No newline at end of file
diff --git a/weasis-launcher/src/main/java/org/weasis/launcher/AppLauncher.java b/weasis-launcher/src/main/java/org/weasis/launcher/AppLauncher.java
index 2c3261ad9..d3cceca4d 100755
--- a/weasis-launcher/src/main/java/org/weasis/launcher/AppLauncher.java
+++ b/weasis-launcher/src/main/java/org/weasis/launcher/AppLauncher.java
@@ -18,6 +18,9 @@
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy;
import ch.qos.logback.core.util.FileSize;
+import com.formdev.flatlaf.util.SystemInfo;
+import java.awt.Desktop;
+import java.awt.Desktop.Action;
import java.io.File;
import java.util.List;
import java.util.Properties;
@@ -75,17 +78,74 @@ public class AppLauncher extends WeasisLauncher implements Singleton.SingletonAp
logger.addAppender(rollingFileAppender);
}
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AppLauncher.class);
+
public AppLauncher(ConfigData configData) {
super(configData);
}
public static void main(String[] argv) throws Exception {
final Type launchType = Type.NATIVE;
- System.setProperty("weasis.launch.type", launchType.name());
ConfigData configData = new ConfigData(argv);
if (!Singleton.invoke(configData)) {
AppLauncher instance = new AppLauncher(configData);
+
+ // Init handler for open URI and open file events
+ Desktop app = Desktop.getDesktop();
+ if (app.isSupported(Action.APP_OPEN_URI)) {
+ long time = System.currentTimeMillis();
+ boolean noArgs = argv.length == 0;
+ app.setOpenURIHandler(
+ e -> {
+ String uri = e.getURI().toString();
+ LOGGER.info("Get URI event from OS. URI: {}", uri);
+ int index = Utils.getWeasisProtocolIndex(uri);
+ if (index < 0) {
+ uri = "dicom:get -r \"" + uri + "\""; // NON-NLS
+ instance.executeCommands(List.of(uri), null);
+ } else {
+ boolean sameInstance = System.currentTimeMillis() - time < 3000;
+ String[] args;
+ if (SystemInfo.isMacOS) {
+ args = new String[] {"open", "-n", "-b", "org.weasis.launcher", "--args", uri};
+ } else if (SystemInfo.isWindows) {
+ args = new String[] {"cmd", "/c", "start", uri};
+ } else {
+ args = new String[] {"xdg-open", uri};
+ }
+ Thread launcherThread =
+ Thread.ofVirtual()
+ .start(
+ () -> {
+ try {
+ ProcessBuilder pb = new ProcessBuilder(args);
+ pb.start().waitFor(15, TimeUnit.SECONDS);
+ if (sameInstance && noArgs) {
+ LOGGER.info(
+ "Configuration with URI is different, restart Weasis with new configuration");
+ instance.shutdownHook();
+ }
+ } catch (Exception ex) {
+ LOGGER.error("Cannot start Weasis from URI", ex);
+ }
+ });
+ launcherThread.start();
+ }
+ });
+ }
+ if (app.isSupported(Desktop.Action.APP_OPEN_FILE)) {
+ app.setOpenFileHandler(
+ e -> {
+ List files =
+ e.getFiles().stream()
+ .map(f -> "dicom:get -l \"" + f.getPath() + "\"") // NON-NLS
+ .toList();
+ LOGGER.info("Get oOpen file event from OS. Files: {}", files);
+ instance.executeCommands(files, null);
+ });
+ }
+
Singleton.start(instance, configData.getSourceID());
instance.launch(launchType);
}
diff --git a/weasis-launcher/src/main/java/org/weasis/launcher/Singleton.java b/weasis-launcher/src/main/java/org/weasis/launcher/Singleton.java
index 96f52a486..7676d3bf6 100755
--- a/weasis-launcher/src/main/java/org/weasis/launcher/Singleton.java
+++ b/weasis-launcher/src/main/java/org/weasis/launcher/Singleton.java
@@ -422,7 +422,7 @@ private void handleMagicWord(BufferedReader in, Socket s, InputStreamReader isr)
if (siApp.canStartNewActivation(props)) {
siApp.newActivation(args);
- LOGGER.debug("Sending ACK");
+ LOGGER.debug("Sending ACK for loading args");
sendResponse(s, isr, SI_ACK);
} else {
LOGGER.debug("Sending EXIT");
diff --git a/weasis-launcher/src/main/java/org/weasis/launcher/WeasisLauncher.java b/weasis-launcher/src/main/java/org/weasis/launcher/WeasisLauncher.java
index c395e57ae..8b228230f 100755
--- a/weasis-launcher/src/main/java/org/weasis/launcher/WeasisLauncher.java
+++ b/weasis-launcher/src/main/java/org/weasis/launcher/WeasisLauncher.java
@@ -24,8 +24,6 @@
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.util.SystemInfo;
-import java.awt.Desktop;
-import java.awt.Desktop.Action;
import java.awt.EventQueue;
import java.io.File;
import java.io.FileDescriptor;
@@ -123,6 +121,7 @@ public static String valueOf(int state) {
protected String look = null;
protected RemotePrefService remotePrefs;
protected String localPrefsDir;
+ protected volatile boolean closing = false;
protected final Properties modulesi18n;
protected final ConfigData configData;
@@ -179,6 +178,9 @@ public final void launch(Type type) throws Exception {
try {
String goshArgs = getGoshArgs(serverProp);
+ if (closing) {
+ return;
+ }
// Now create an instance of the framework with our configuration properties.
mFelix = new Felix(serverProp);
// Initialize the framework, but don't start it yet.
@@ -195,7 +197,9 @@ public final void launch(Type type) throws Exception {
new ServiceTracker(
mFelix.getBundleContext(), "org.apache.felix.service.command.CommandProcessor", null);
mTracker.open();
-
+ if (closing) {
+ return;
+ }
// Start the framework.
mFelix.start();
@@ -208,37 +212,6 @@ public final void launch(Type type) throws Exception {
LOGGER.info(
"Logs has been delegated to the OSGI service and can be read in {}", logActivation);
}
-
- // Init after default properties for UI
- Desktop app = Desktop.getDesktop();
- if (app.isSupported(Action.APP_OPEN_URI)) {
- app.setOpenURIHandler(
- e -> {
- String uri = e.getURI().toString();
- LOGGER.info("Get URI event from OS. URI: {}", uri);
- int index = Utils.getWeasisProtocolIndex(uri);
- if (index < 0) {
- uri = "dicom:get -r \"" + uri + "\""; // NON-NLS
- executeCommands(List.of(uri), null);
- } else {
- configData.extractArgFromUri(uri);
- executeCommands(configData.getArguments(), null);
- }
- });
- }
- if (app.isSupported(Desktop.Action.APP_OPEN_FILE)) {
-
- app.setOpenFileHandler(
- e -> {
- List files =
- e.getFiles().stream()
- .map(f -> "dicom:get -l \"" + f.getPath() + "\"") // NON-NLS
- .toList();
- LOGGER.info("Get oOpen file event from OS. Files: {}", files);
- executeCommands(files, null);
- });
- }
-
executeCommands(configData.getArguments(), goshArgs);
checkBundleUI(serverProp);
@@ -246,6 +219,9 @@ public final void launch(Type type) throws Exception {
showMessage(mainFrame, serverProp);
+ if (closing) {
+ return;
+ }
// Wait for framework to stop to exit the VM.
mFelix.waitForStop(0);
System.exit(0);
@@ -1130,7 +1106,8 @@ public static Locale textToLocale(String value) {
return Locale.getDefault();
}
- private void shutdownHook() {
+ protected void shutdownHook() {
+ closing = true;
if (mFelix == null || (mFelix.getState() & 6) != 0) {
return;
}