mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-20 09:36:55 -04:00
Merge pull request #689 from jellemdekker/feature/296-status-indicator-in-system-tray
[Help needed] Different system tray icon is shown when one or more vaults are unlocked fixes #296
This commit is contained in:
@@ -53,6 +53,7 @@ public class ExitUtil {
|
||||
private final Localization localization;
|
||||
private final Settings settings;
|
||||
private final Optional<MacFunctions> macFunctions;
|
||||
private TrayIcon trayIcon;
|
||||
|
||||
@Inject
|
||||
public ExitUtil(@Named("mainWindow") Stage mainWindow, Localization localization, Settings settings, Optional<MacFunctions> macFunctions) {
|
||||
@@ -82,7 +83,7 @@ public class ExitUtil {
|
||||
}
|
||||
|
||||
private void initTrayIconExitHandler(Runnable exitCommand) {
|
||||
final TrayIcon trayIcon = createTrayIcon(exitCommand);
|
||||
trayIcon = createTrayIcon(exitCommand);
|
||||
try {
|
||||
// double clicking tray icon should open Cryptomator
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
@@ -118,14 +119,7 @@ public class ExitUtil {
|
||||
exitItem.addActionListener(e -> exitCommand.run());
|
||||
popup.add(exitItem);
|
||||
|
||||
final Image image;
|
||||
if (SystemUtils.IS_OS_MAC_OSX && isMacMenuBarDarkMode()) {
|
||||
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_white.png"));
|
||||
} else if (SystemUtils.IS_OS_MAC_OSX) {
|
||||
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon_mac_black.png"));
|
||||
} else {
|
||||
image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tray_icon.png"));
|
||||
}
|
||||
final Image image = getAppropriateTrayIconImage(true);
|
||||
|
||||
return new TrayIcon(image, localization.getString("app.name"), popup);
|
||||
}
|
||||
@@ -202,4 +196,23 @@ public class ExitUtil {
|
||||
});
|
||||
}
|
||||
|
||||
public void updateTrayIcon(boolean areAllVaultsLocked) {
|
||||
if (trayIcon != null) {
|
||||
Image image = getAppropriateTrayIconImage(areAllVaultsLocked);
|
||||
trayIcon.setImage(image);
|
||||
}
|
||||
}
|
||||
|
||||
private Image getAppropriateTrayIconImage(boolean areAllVaultsLocked) {
|
||||
String resourceName;
|
||||
if (SystemUtils.IS_OS_MAC_OSX && isMacMenuBarDarkMode()) {
|
||||
resourceName = areAllVaultsLocked ? "/tray_icon_mac_white.png" : "/tray_icon_unlocked_mac_white.png";
|
||||
} else if (SystemUtils.IS_OS_MAC_OSX) {
|
||||
resourceName = areAllVaultsLocked ? "/tray_icon_mac_black.png" : "/tray_icon_unlocked_mac_black.png";
|
||||
} else {
|
||||
resourceName = areAllVaultsLocked ? "/tray_icon.png" : "/tray_icon_unlocked.png";
|
||||
}
|
||||
return Toolkit.getDefaultToolkit().getImage(getClass().getResource(resourceName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ public class MainController implements ViewController {
|
||||
this.upgradeStrategyForSelectedVault = EasyBind.monadic(selectedVault).map(upgradeStrategies::getUpgradeStrategy);
|
||||
this.areAllVaultsLocked = Bindings.isEmpty(FXCollections.observableList(vaults, Vault::observables).filtered(Vault.NOT_LOCKED));
|
||||
|
||||
EasyBind.subscribe(areAllVaultsLocked, exitUtil::updateTrayIcon);
|
||||
EasyBind.subscribe(areAllVaultsLocked, Platform::setImplicitExit);
|
||||
autoUnlocker.unlockAllSilently();
|
||||
|
||||
|
||||
BIN
main/ui/src/main/resources/tray_icon_unlocked.png
Normal file
BIN
main/ui/src/main/resources/tray_icon_unlocked.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 699 B |
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_black.png
Normal file
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_black.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 353 B |
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_black@2x.png
Normal file
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_black@2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 705 B |
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_white.png
Normal file
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 378 B |
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_white@2x.png
Normal file
BIN
main/ui/src/main/resources/tray_icon_unlocked_mac_white@2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 760 B |
Reference in New Issue
Block a user