Skip to content

Commit

Permalink
fixes #858
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Mar 19, 2019
1 parent a4ef082 commit 44fc676
Showing 1 changed file with 24 additions and 36 deletions.
Expand Up @@ -6,7 +6,6 @@
package org.cryptomator.launcher;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.logging.DebugMode;
Expand All @@ -20,7 +19,6 @@
import javax.inject.Singleton;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;

@Singleton
public class Cryptomator {
Expand Down Expand Up @@ -56,51 +54,41 @@ public static void main(String[] args) {
private int run(String[] args) {
logConfig.init();
LOG.info("Starting Cryptomator {} on {} {} ({})", applicationVersion.orElse("SNAPSHOT"), SystemUtils.OS_NAME, SystemUtils.OS_VERSION, SystemUtils.OS_ARCH);
debugMode.initialize();

if (sendArgsToRunningInstance(args)) {
LOG.info("Found running application instance. Shutting down...");
return 0;
}

try {
runGuiApplication();
LOG.info("Shutting down...");
return 0;
} catch (Throwable e) {
LOG.error("Terminating due to error", e);
return 1;
}
}

/**
* Attempts to create an IPC connection to a running Cryptomator instance and sends it the given args.
* If no external process could be reached, the args will be handled by the loopback IPC endpoint.
*
* @param args Arguments to send to the instance (if possible)
* @return <code>true</code> if a different process could be reached, <code>false</code> otherwise.
*/
private boolean sendArgsToRunningInstance(String[] args) {
/*
* Attempts to create an IPC connection to a running Cryptomator instance and sends it the given args.
* If no external process could be reached, the args will be handled by the loopback IPC endpoint.
*/
try (IpcFactory.IpcEndpoint endpoint = ipcFactory.create()) {
endpoint.getRemote().handleLaunchArgs(args); // if we are the server, getRemote() returns self.
return endpoint.isConnectedToRemote();
if (endpoint.isConnectedToRemote()) {
LOG.info("Found running application instance. Shutting down...");
return 2;
} else {
LOG.debug("Did not find running application instance. Launching GUI...");
return runGuiApplication();
}
} catch (IOException e) {
LOG.error("Failed to initiate inter-process communication.", e);
return false;
return runGuiApplication();
}
}

/**
* Launches the JavaFX application and waits until shutdown is requested.
* @return Nonzero exit code in case of an error.
*/
private void runGuiApplication() {
debugMode.initialize();
CleanShutdownPerformer.registerShutdownHook();
Application.launch(MainApp.class);
// Platform.startup(() -> {
// assert Platform.isFxApplicationThread();
// FxApplication app = CRYPTOMATOR_COMPONENT.fxApplicationComponent().application();
// app.start();
// });
private int runGuiApplication() {
try {
CleanShutdownPerformer.registerShutdownHook();
Application.launch(MainApp.class);
LOG.info("Shutting down...");
return 0;
} catch (Throwable e) {
LOG.error("Terminating due to error", e);
return 1;
}
}


Expand Down

0 comments on commit 44fc676

Please sign in to comment.