package id.co.gtc.erhacam; import Config.SomeCodes; import Database.PhotoCleaner; import SecureDongle.SecureDongle; import SecureDongle.SecureDongleEvent; import javafx.application.Application; import javafx.application.Platform; import javafx.fxml.FXMLLoader; import javafx.geometry.Rectangle2D; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.stage.Screen; import javafx.stage.Stage; import org.tinylog.Logger; import java.io.IOException; import static Config.SomeCodes.ShowAlert; import static Config.SomeCodes.config; public class MainApplication extends Application { final String version = "01072025-PRODUCTION-1.0.1"; PhotoCleaner photoCleaner; @Override public void start(Stage stage) throws IOException { Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (photoCleaner!=null) photoCleaner.Stop(); System.out.println("ShutdownHook Checking running threads..."); // Map allThreads = Thread.getAllStackTraces(); // for(Thread thread : allThreads.keySet()){ // System.out.println("Thread: " + thread.getName()+", State: " + thread.getState()+", Daemon: " + thread.isDaemon()); // thread.interrupt(); // } })); SecureDongle sd = new SecureDongle((short)0x4B30, (short)0xA66C, (short)0x3109, (short)0x37B1); if (sd.Find()){ if (sd.Open()){ String UserID = Integer.toHexString(sd.ReadUserID()) ; sd.Close(); if (UserID.equals("14022025")){ Logger.info("Secure Dongle UserID valid"); FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("main-view.fxml")); Screen screen = Screen.getPrimary(); Rectangle2D screenbound = screen.getBounds(); Scene scene = new Scene(fxmlLoader.load(), screenbound.getWidth(), screenbound.getHeight()); stage.setTitle("MultiCam Capture App for ERHA "+version); stage.setScene(scene); stage.setResizable(true); stage.setMaximized(true); stage.setOnCloseRequest(e->{ sd.StopMonitor(); config.Save(); MainView mainView = fxmlLoader.getController(); mainView.Unload(); Logger.info("Application closed"); }); SomeCodes.LoadQRReader(); Detectors.LoadAllDetectors(); stage.show(); AutoCloseAlert.init(); Logger.info("Application started"); System.out.println("Application version : " + version+" started"); sd.setEvent(new SecureDongleEvent() { @Override public void onDongleMissing() { Logger.error("Secure Dongle Missing"); Platform.runLater(()->{ ShowAlert(Alert.AlertType.ERROR, "Secure Dongle Missing", "Secure Dongle Missing", "Secure Dongle Missing"); Platform.exit(); }); } @Override public void onDongleError(String function, int errorCode) { } }); sd.StartMonitor(); photoCleaner = new PhotoCleaner(90); photoCleaner.Start(); } else { ShowAlert(Alert.AlertType.ERROR, "Secure Dongle UserID not valid", "Secure Dongle UserID not valid", "Secure Dongle UserID not valid"); Logger.error("Secure Dongle UserID not valid"); Platform.exit(); } } else { ShowAlert(Alert.AlertType.ERROR, "Secure Dongle cannot be opened", "Secure Dongle cannot be opened", "Secure Dongle cannot be opened"); Logger.error("Secure Dongle cannot be opened"); Platform.exit(); } } else { ShowAlert(Alert.AlertType.ERROR, "Secure Dongle not found", "Secure Dongle not found", "Secure Dongle not found"); Logger.error("Secure Dongle not found"); Platform.exit(); } } public static void main(String[] args) { SomeCodes.ExtractResource("/tinylog.properties"); launch(); } }