mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-30 19:56:00 +00:00
added mac native function for listening to system interface theme changes and changing the tray icon accordingly [ci skip]
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package org.cryptomator.ui.traymenu;
|
||||
|
||||
import javafx.beans.Observable;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.jni.MacFunctions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -10,30 +9,28 @@ import javax.inject.Inject;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.SystemTray;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Optional;
|
||||
|
||||
@TrayMenuScoped
|
||||
public class TrayIconController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TrayIconController.class);
|
||||
|
||||
private final Settings settings;
|
||||
private final TrayImageFactory imageFactory;
|
||||
private final TrayMenuController trayMenuController;
|
||||
private final TrayIcon trayIcon;
|
||||
private final Optional<MacFunctions> macFunctions;
|
||||
|
||||
@Inject
|
||||
TrayIconController(Settings settings, TrayImageFactory imageFactory, TrayMenuController trayMenuController) {
|
||||
this.settings = settings;
|
||||
TrayIconController(TrayImageFactory imageFactory, TrayMenuController trayMenuController, Optional<MacFunctions> macFunctions) {
|
||||
this.trayMenuController = trayMenuController;
|
||||
this.imageFactory = imageFactory;
|
||||
this.trayIcon = new TrayIcon(imageFactory.loadImage(), "Cryptomator", trayMenuController.getMenu());
|
||||
this.macFunctions = macFunctions;
|
||||
}
|
||||
|
||||
public void initializeTrayIcon() {
|
||||
settings.theme().addListener(this::themeChanged);
|
||||
macFunctions.map(MacFunctions::uiAppearance).ifPresent(uiAppearance -> uiAppearance.addListener(this::macInterfaceThemeChanged));
|
||||
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
// TODO: test on windows: is this a double click?
|
||||
@@ -50,7 +47,7 @@ public class TrayIconController {
|
||||
trayMenuController.initTrayMenu();
|
||||
}
|
||||
|
||||
private void themeChanged(@SuppressWarnings("unused") Observable observable) {
|
||||
public void macInterfaceThemeChanged() {
|
||||
trayIcon.setImage(imageFactory.loadImage());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
package org.cryptomator.ui.traymenu;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.jni.MacApplicationUiAppearance;
|
||||
import org.cryptomator.jni.MacApplicationUiInterfaceStyle;
|
||||
import org.cryptomator.jni.MacFunctions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.util.Optional;
|
||||
|
||||
@TrayMenuScoped
|
||||
class TrayImageFactory {
|
||||
|
||||
private final Settings settings;
|
||||
private final Optional<MacFunctions> macFunctions;
|
||||
|
||||
@Inject
|
||||
TrayImageFactory(Settings settings) {
|
||||
this.settings = settings;
|
||||
TrayImageFactory(Optional<MacFunctions> macFunctions) {
|
||||
this.macFunctions = macFunctions;
|
||||
}
|
||||
|
||||
public Image loadImage() {
|
||||
@@ -23,7 +26,10 @@ class TrayImageFactory {
|
||||
}
|
||||
|
||||
private String getMacResourceName() {
|
||||
switch (settings.theme().get()) {
|
||||
MacApplicationUiInterfaceStyle interfaceStyle = macFunctions.map(MacFunctions::uiAppearance) //
|
||||
.map(MacApplicationUiAppearance::getCurrentInterfaceStyle) //
|
||||
.orElse(MacApplicationUiInterfaceStyle.LIGHT);
|
||||
switch (interfaceStyle) {
|
||||
case DARK:
|
||||
return "/tray_icon_mac_white.png";
|
||||
default:
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.cryptomator.ui.traymenu;
|
||||
|
||||
import dagger.Module;
|
||||
import org.cryptomator.common.JniModule;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationComponent;
|
||||
|
||||
@Module(subcomponents = {FxApplicationComponent.class})
|
||||
@Module(includes = {JniModule.class}, subcomponents = {FxApplicationComponent.class})
|
||||
abstract class TrayMenuModule {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user