mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-19 13:46:04 +00:00
adjust to latest API
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
<!-- cryptomator dependencies -->
|
<!-- cryptomator dependencies -->
|
||||||
<cryptomator.cryptofs.version>2.4.0</cryptomator.cryptofs.version>
|
<cryptomator.cryptofs.version>2.4.0</cryptomator.cryptofs.version>
|
||||||
<cryptomator.integrations.version>1.1.0-beta2</cryptomator.integrations.version>
|
<cryptomator.integrations.version>1.1.0-beta3</cryptomator.integrations.version>
|
||||||
<cryptomator.integrations.win.version>1.1.0-beta1</cryptomator.integrations.win.version>
|
<cryptomator.integrations.win.version>1.1.0-beta1</cryptomator.integrations.win.version>
|
||||||
<cryptomator.integrations.mac.version>1.1.0-beta1</cryptomator.integrations.mac.version>
|
<cryptomator.integrations.mac.version>1.1.0-beta1</cryptomator.integrations.mac.version>
|
||||||
<cryptomator.integrations.linux.version>1.1.0-beta1</cryptomator.integrations.linux.version>
|
<cryptomator.integrations.linux.version>1.1.0-beta1</cryptomator.integrations.linux.version>
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ module org.cryptomator.desktop {
|
|||||||
requires logback.classic;
|
requires logback.classic;
|
||||||
requires logback.core;
|
requires logback.core;
|
||||||
|
|
||||||
|
exports org.cryptomator.ui.traymenu to org.cryptomator.integrations.api;
|
||||||
provides TrayMenuController with AwtTrayMenuController;
|
provides TrayMenuController with AwtTrayMenuController;
|
||||||
|
|
||||||
opens org.cryptomator.common.settings to com.google.gson;
|
opens org.cryptomator.common.settings to com.google.gson;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class FxApplication {
|
|||||||
|
|
||||||
// init system tray
|
// init system tray
|
||||||
final boolean hasTrayIcon;
|
final boolean hasTrayIcon;
|
||||||
if (SystemTray.isSupported() && settings.showTrayIcon().get()) {
|
if (settings.showTrayIcon().get() && trayMenu.get().isSupported()) {
|
||||||
trayMenu.get().initializeTrayIcon();
|
trayMenu.get().initializeTrayIcon();
|
||||||
Platform.setImplicitExit(false); // don't quit when closing all windows
|
Platform.setImplicitExit(false); // don't quit when closing all windows
|
||||||
hasTrayIcon = true;
|
hasTrayIcon = true;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package org.cryptomator.ui.traymenu;
|
package org.cryptomator.ui.traymenu;
|
||||||
|
|
||||||
import org.apache.commons.lang3.SystemUtils;
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
import org.cryptomator.integrations.common.CheckAvailability;
|
||||||
import org.cryptomator.integrations.common.Priority;
|
import org.cryptomator.integrations.common.Priority;
|
||||||
import org.cryptomator.integrations.tray.ActionItem;
|
import org.cryptomator.integrations.tray.ActionItem;
|
||||||
import org.cryptomator.integrations.tray.SeparatorItem;
|
import org.cryptomator.integrations.tray.SeparatorItem;
|
||||||
import org.cryptomator.integrations.tray.SubMenuItem;
|
import org.cryptomator.integrations.tray.SubMenuItem;
|
||||||
import org.cryptomator.integrations.tray.TrayMenuController;
|
import org.cryptomator.integrations.tray.TrayMenuController;
|
||||||
|
import org.cryptomator.integrations.tray.TrayMenuException;
|
||||||
import org.cryptomator.integrations.tray.TrayMenuItem;
|
import org.cryptomator.integrations.tray.TrayMenuItem;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -21,18 +23,23 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@CheckAvailability
|
||||||
@Priority(Priority.FALLBACK)
|
@Priority(Priority.FALLBACK)
|
||||||
public class AwtTrayMenuController implements TrayMenuController {
|
public class AwtTrayMenuController implements TrayMenuController {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AwtTrayMenuController.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AwtTrayMenuController.class);
|
||||||
|
|
||||||
private TrayIcon trayIcon;
|
private final PopupMenu menu = new PopupMenu();
|
||||||
private PopupMenu menu = new PopupMenu();
|
|
||||||
|
@CheckAvailability
|
||||||
|
public static boolean isAvailable() {
|
||||||
|
return SystemTray.isSupported();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showTrayIcon(InputStream rawImageData, Runnable defaultAction, String tooltip) throws IOException {
|
public void showTrayIcon(byte[] rawImageData, Runnable defaultAction, String tooltip) {
|
||||||
var image = Toolkit.getDefaultToolkit().createImage(rawImageData.readAllBytes());
|
var image = Toolkit.getDefaultToolkit().createImage(rawImageData);
|
||||||
trayIcon = new TrayIcon(image, tooltip, menu);
|
var trayIcon = new TrayIcon(image, tooltip, menu);
|
||||||
|
|
||||||
trayIcon.setImageAutoSize(true);
|
trayIcon.setImageAutoSize(true);
|
||||||
if (SystemUtils.IS_OS_WINDOWS) {
|
if (SystemUtils.IS_OS_WINDOWS) {
|
||||||
@@ -59,7 +66,7 @@ public class AwtTrayMenuController implements TrayMenuController {
|
|||||||
if (item instanceof ActionItem a) {
|
if (item instanceof ActionItem a) {
|
||||||
var menuItem = new MenuItem(a.title());
|
var menuItem = new MenuItem(a.title());
|
||||||
menuItem.addActionListener(evt -> a.action().run());
|
menuItem.addActionListener(evt -> a.action().run());
|
||||||
// TODO menuItem.setEnabled(a.enabled());
|
menuItem.setEnabled(a.enabled());
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
} else if (item instanceof SeparatorItem) {
|
} else if (item instanceof SeparatorItem) {
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ import org.cryptomator.integrations.tray.ActionItem;
|
|||||||
import org.cryptomator.integrations.tray.SeparatorItem;
|
import org.cryptomator.integrations.tray.SeparatorItem;
|
||||||
import org.cryptomator.integrations.tray.SubMenuItem;
|
import org.cryptomator.integrations.tray.SubMenuItem;
|
||||||
import org.cryptomator.integrations.tray.TrayMenuController;
|
import org.cryptomator.integrations.tray.TrayMenuController;
|
||||||
|
import org.cryptomator.integrations.tray.TrayMenuException;
|
||||||
import org.cryptomator.integrations.tray.TrayMenuItem;
|
import org.cryptomator.integrations.tray.TrayMenuItem;
|
||||||
import org.cryptomator.ui.common.VaultService;
|
import org.cryptomator.ui.common.VaultService;
|
||||||
import org.cryptomator.ui.fxapp.FxApplicationTerminator;
|
import org.cryptomator.ui.fxapp.FxApplicationTerminator;
|
||||||
import org.cryptomator.ui.fxapp.FxApplicationWindows;
|
import org.cryptomator.ui.fxapp.FxApplicationWindows;
|
||||||
import org.cryptomator.ui.preferences.SelectedPreferencesTab;
|
import org.cryptomator.ui.preferences.SelectedPreferencesTab;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@@ -27,6 +30,7 @@ import java.util.ResourceBundle;
|
|||||||
@TrayMenuScoped
|
@TrayMenuScoped
|
||||||
public class TrayMenuBuilder {
|
public class TrayMenuBuilder {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(TrayMenuBuilder.class);
|
||||||
private static final String TRAY_ICON_MAC = "/img/tray_icon_mac.png";
|
private static final String TRAY_ICON_MAC = "/img/tray_icon_mac.png";
|
||||||
private static final String TRAY_ICON = "/img/tray_icon.png";
|
private static final String TRAY_ICON = "/img/tray_icon.png";
|
||||||
|
|
||||||
@@ -56,15 +60,16 @@ public class TrayMenuBuilder {
|
|||||||
vaults.forEach(v -> {
|
vaults.forEach(v -> {
|
||||||
v.displayNameProperty().addListener(this::vaultListChanged);
|
v.displayNameProperty().addListener(this::vaultListChanged);
|
||||||
});
|
});
|
||||||
rebuildMenu();
|
|
||||||
|
|
||||||
try (var image = getClass().getResourceAsStream(SystemUtils.IS_OS_MAC_OSX ? TRAY_ICON_MAC : TRAY_ICON)) {
|
try (var image = getClass().getResourceAsStream(SystemUtils.IS_OS_MAC_OSX ? TRAY_ICON_MAC : TRAY_ICON)) {
|
||||||
trayMenu.showTrayIcon(image, this::showMainWindow, "Cryptomator");
|
trayMenu.showTrayIcon(image.readAllBytes(), this::showMainWindow, "Cryptomator");
|
||||||
|
rebuildMenu();
|
||||||
|
initialized = true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException("Failed to load embedded resource", e);
|
throw new UncheckedIOException("Failed to load embedded resource", e);
|
||||||
|
} catch (TrayMenuException e) {
|
||||||
|
LOG.error("Adding tray icon failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
@@ -88,11 +93,14 @@ public class TrayMenuBuilder {
|
|||||||
menu.add(new SubMenuItem(label, submenu));
|
menu.add(new SubMenuItem(label, submenu));
|
||||||
}
|
}
|
||||||
menu.add(new SeparatorItem());
|
menu.add(new SeparatorItem());
|
||||||
menu.add(new ActionItem(resourceBundle.getString("traymenu.lockAllVaults"), this::lockAllVaults));
|
menu.add(new ActionItem(resourceBundle.getString("traymenu.lockAllVaults"), this::lockAllVaults, vaults.stream().anyMatch(Vault::isUnlocked)));
|
||||||
menu.add(new ActionItem(resourceBundle.getString("traymenu.quitApplication"), this::quitApplication));
|
menu.add(new ActionItem(resourceBundle.getString("traymenu.quitApplication"), this::quitApplication));
|
||||||
// lockAllItem.setEnabled(!vaults.filtered(Vault::isUnlocked).isEmpty());
|
|
||||||
|
|
||||||
trayMenu.updateTrayMenu(menu);
|
try {
|
||||||
|
trayMenu.updateTrayMenu(menu);
|
||||||
|
} catch (TrayMenuException e) {
|
||||||
|
LOG.error("Updating tray menu failed", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TrayMenuItem> buildSubmenu(Vault vault) {
|
private List<TrayMenuItem> buildSubmenu(Vault vault) {
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ public interface TrayMenuComponent {
|
|||||||
* @return <code>true</code> if a tray icon can be installed
|
* @return <code>true</code> if a tray icon can be installed
|
||||||
*/
|
*/
|
||||||
default boolean isSupported() {
|
default boolean isSupported() {
|
||||||
// TODO add isSupported to API and move SystemTray.isSupported() to impl
|
return trayMenuController().isPresent();
|
||||||
return trayMenuController().isPresent() && SystemTray.isSupported();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,11 +37,13 @@ public interface TrayMenuComponent {
|
|||||||
/**
|
/**
|
||||||
* Installs a tray icon to the system tray.
|
* Installs a tray icon to the system tray.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException If already added
|
* @throws IllegalStateException If not {@link #isSupported() supported}
|
||||||
*/
|
*/
|
||||||
default void initializeTrayIcon() throws IllegalStateException {
|
default void initializeTrayIcon() throws IllegalStateException {
|
||||||
Preconditions.checkState(isSupported(), "system tray not supported");
|
Preconditions.checkState(isSupported(), "system tray not supported");
|
||||||
trayMenuBuilder().initTrayMenu();
|
if (!trayMenuBuilder().isInitialized()) {
|
||||||
|
trayMenuBuilder().initTrayMenu();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subcomponent.Builder
|
@Subcomponent.Builder
|
||||||
|
|||||||
Reference in New Issue
Block a user