always try obtain application lock on startup

This commit is contained in:
Craig Raw 2021-05-12 08:46:24 +02:00
parent 6f35d86890
commit 6155306acc

View file

@ -173,16 +173,15 @@ public class MainApp extends Application {
} }
List<String> fileUriArguments = jCommander.getUnknownOptions(); List<String> fileUriArguments = jCommander.getUnknownOptions();
if(!fileUriArguments.isEmpty()) {
if(args.network == null && args.dir == null) {
try { try {
sparrowUnique = new SparrowUnique(APP_ID, fileUriArguments); sparrowUnique = new SparrowUnique(fileUriArguments);
sparrowUnique.acquireLock(); //Will exit app after sending fileUriArguments if lock cannot be acquired sparrowUnique.acquireLock(); //If fileUriArguments is not empty, will exit app after sending fileUriArguments if lock cannot be acquired
} catch(Unique4jException e) { } catch(Unique4jException e) {
getLogger().error("Could not obtain unique lock", e); getLogger().error("Could not access application lock", e);
}
} }
if(!fileUriArguments.isEmpty()) {
AppServices.parseFileUriArguments(fileUriArguments); AppServices.parseFileUriArguments(fileUriArguments);
} }
@ -198,16 +197,18 @@ public class MainApp extends Application {
private static class SparrowUnique extends Unique4jList { private static class SparrowUnique extends Unique4jList {
private final List<String> fileUriArguments; private final List<String> fileUriArguments;
public SparrowUnique(String APP_ID, List<String> fileUriArguments) { public SparrowUnique(List<String> fileUriArguments) {
super(APP_ID + "." + Network.get()); super(MainApp.APP_ID + "." + Network.get(), !fileUriArguments.isEmpty());
this.fileUriArguments = fileUriArguments; this.fileUriArguments = fileUriArguments;
} }
@Override @Override
protected void receiveMessageList(List<String> messageList) { protected void receiveMessageList(List<String> messageList) {
if(messageList != null && !messageList.isEmpty()) {
AppServices.parseFileUriArguments(messageList); AppServices.parseFileUriArguments(messageList);
AppServices.openFileUriArguments(null); AppServices.openFileUriArguments(null);
} }
}
@Override @Override
protected List<String> sendMessageList() { protected List<String> sendMessageList() {