Skip to content

Commit

Permalink
add dialog to Launcher (#11800)
Browse files Browse the repository at this point in the history
* add dialog to Launcher

when user open two instances of JabRef, second one will open dialog saying Localization.lang("Another JabRef instance is already running. Please switch to that instance.")

* change it in JavaFX implement

change it in JavaFX implement

* fix base on comment

1. Refactor the message when user starts JabRef a second time. now it is"Another JabRef instance is already running. Please switch to that instance." not "Passing arguments passed on to running JabRef..."
2. send a message from second instance to first instance to open a dialog in exist instance

* push the test code don't merge

I know I should not close the first instance, I'm testing. I push this code since @calixtus ask me to push it.

* update based on DevCall decision

- a little difference between DevCall decision, since before `initialize()` the UiTaskExecutor and dialogService is null, I arrange the dialog code after `initialize()`

* only change debug log without dialog

1. only change debug log without dialog
2. add a null check before closing taskExecutor

* fix a logger level to warn

fix comment position

* fix revert missing empty line

fix revert missing empty line

* fix the comment

"We do not launch a new instance in presence of an error" to "We do not launch a new instance in presence if there is another instance running"
  • Loading branch information
leaf-soba authored Sep 29, 2024
1 parent c93a47c commit e395853
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,29 @@ private static void initLogging(String[] args) {
/**
* @return true if JabRef should continue starting up, false if it should quit.
*/
private static boolean handleMultipleAppInstances(String[] args, RemotePreferences remotePreferences) {
private static boolean handleMultipleAppInstances(String[] args, RemotePreferences remotePreferences) throws InterruptedException {
LOGGER.trace("Checking for remote handling...");
if (remotePreferences.useRemoteServer()) {
// Try to contact already running JabRef
RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort());
if (remoteClient.ping()) {
LOGGER.debug("Pinging other instance succeeded.");
// We are not alone, there is already a server out there, send command line
// arguments to other instance
LOGGER.debug("Passing arguments passed on to running JabRef...");
if (remoteClient.sendCommandLineArguments(args)) {
// So we assume it's all taken care of, and quit.
// Output to both to the log and the screen. Therefore, we do not have an additional System.out.println.
LOGGER.info("Arguments passed on to running JabRef instance. Shutting down.");
return false;
if (args.length == 0) {
// There is already a server out there, avoid showing log "Passing arguments" while no arguments are provided.
LOGGER.warn("This JabRef instance is already running. Please switch to that instance.");
} else {
LOGGER.warn("Could not communicate with other running JabRef instance.");
// We do not launch a new instance in presence of an error
return false;
// We are not alone, there is already a server out there, send command line arguments to other instance
LOGGER.debug("Passing arguments passed on to running JabRef...");
if (remoteClient.sendCommandLineArguments(args)) {
// So we assume it's all taken care of, and quit.
// Output to both to the log and the screen. Therefore, we do not have an additional System.out.println.
LOGGER.info("Arguments passed on to running JabRef instance. Shutting down.");
} else {
LOGGER.warn("Could not communicate with other running JabRef instance.");
}
}
// We do not launch a new instance in presence if there is another instance running
return false;
} else {
LOGGER.debug("Could not ping JabRef instance.");
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ public void stopBackgroundTasks() {

public static void shutdownThreadPools() {
LOGGER.trace("Shutting down taskExecutor");
taskExecutor.shutdown();
if (taskExecutor != null) {
taskExecutor.shutdown();
}
LOGGER.trace("Shutting down fileUpdateMonitor");
fileUpdateMonitor.shutdown();
LOGGER.trace("Shutting down directoryMonitor");
Expand Down

0 comments on commit e395853

Please sign in to comment.