Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lockfile to prevent duplicate instances #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions src/main/java/net/marvk/fs/vatsim/map/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import net.harawata.appdirs.AppDirsFactory;
import net.marvk.fs.vatsim.map.data.VersionProvider;

import java.io.File;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

/**
* TODO Hacky way to start a JavaFX application without messing with modules
Expand All @@ -18,6 +22,16 @@ private Application() {
}

public static void main(final String[] args) throws IOException {
// Establish and check lockfile to prevent multiple instances
String userHome = System.getProperty("user.home");
File file = new File(userHome, "vatprism.lock");
FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
FileLock lock = fc.tryLock();
if (lock == null) {
System.out.println("Another instance of VATprism is running");
System.exit(1);
}

reconfigureLogger();
SystemInformationLogger.logGeneralInformation();
App.main(args);
Expand Down