Search in sources :

Example 1 with MacApplicationUiState

use of org.cryptomator.jni.MacApplicationUiState in project cryptomator by cryptomator.

the class ExitUtil method initTrayIconExitHandler.

private void initTrayIconExitHandler(Runnable exitCommand) {
    final TrayIcon trayIcon = createTrayIcon(exitCommand);
    try {
        // double clicking tray icon should open Cryptomator
        if (SystemUtils.IS_OS_WINDOWS) {
            trayIcon.addMouseListener(new TrayIconMouseListener());
        }
        SystemTray.getSystemTray().add(trayIcon);
        mainWindow.setOnCloseRequest((e) -> {
            if (Platform.isImplicitExit()) {
                exitCommand.run();
            } else {
                macFunctions.map(MacFunctions::uiState).ifPresent(JniException.ignore(MacApplicationUiState::transformToAgentApplication));
                mainWindow.close();
                this.showTrayNotification(trayIcon);
            }
        });
    } catch (SecurityException | AWTException ex) {
        // not working? then just go ahead and close the app
        mainWindow.setOnCloseRequest((ev) -> {
            exitCommand.run();
        });
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) Settings(org.cryptomator.ui.settings.Settings) PopupMenu(java.awt.PopupMenu) Inject(javax.inject.Inject) SwingUtilities(javax.swing.SwingUtilities) TrayIcon(java.awt.TrayIcon) MacFunctions(org.cryptomator.jni.MacFunctions) MouseAdapter(java.awt.event.MouseAdapter) MessageType(java.awt.TrayIcon.MessageType) Named(javax.inject.Named) SystemTray(java.awt.SystemTray) Localization(org.cryptomator.ui.settings.Localization) ScriptException(javax.script.ScriptException) Logger(org.slf4j.Logger) Image(java.awt.Image) SystemUtils(org.apache.commons.lang3.SystemUtils) ScriptEngineManager(javax.script.ScriptEngineManager) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) TimeUnit(java.util.concurrent.TimeUnit) Platform(javafx.application.Platform) MenuItem(java.awt.MenuItem) Stage(javafx.stage.Stage) AWTException(java.awt.AWTException) ScriptEngine(javax.script.ScriptEngine) Optional(java.util.Optional) JniException(org.cryptomator.jni.JniException) MacApplicationUiState(org.cryptomator.jni.MacApplicationUiState) Toolkit(java.awt.Toolkit) TrayIcon(java.awt.TrayIcon) AWTException(java.awt.AWTException)

Aggregations

AWTException (java.awt.AWTException)1 Image (java.awt.Image)1 MenuItem (java.awt.MenuItem)1 PopupMenu (java.awt.PopupMenu)1 SystemTray (java.awt.SystemTray)1 Toolkit (java.awt.Toolkit)1 TrayIcon (java.awt.TrayIcon)1 MessageType (java.awt.TrayIcon.MessageType)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 TimeUnit (java.util.concurrent.TimeUnit)1 Platform (javafx.application.Platform)1 Stage (javafx.stage.Stage)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 Singleton (javax.inject.Singleton)1 ScriptEngine (javax.script.ScriptEngine)1