mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
Can now unlock directly from menu bar
This commit is contained in:
@@ -7,10 +7,12 @@ import javafx.beans.value.ObservableValue;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.settings.UiTheme;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.jni.MacApplicationUiAppearance;
|
||||
import org.cryptomator.jni.MacFunctions;
|
||||
import org.cryptomator.ui.mainwindow.MainWindowComponent;
|
||||
import org.cryptomator.ui.preferences.PreferencesComponent;
|
||||
import org.cryptomator.ui.unlock.UnlockComponent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -27,13 +29,15 @@ public class FxApplication extends Application {
|
||||
private final Settings settings;
|
||||
private final Lazy<MainWindowComponent> mainWindow;
|
||||
private final Lazy<PreferencesComponent> preferencesWindow;
|
||||
private final UnlockComponent.Builder unlockWindowBuilder;
|
||||
private final Optional<MacFunctions> macFunctions;
|
||||
|
||||
@Inject
|
||||
FxApplication(Settings settings, Lazy<MainWindowComponent> mainWindow, Lazy<PreferencesComponent> preferencesWindow, Optional<MacFunctions> macFunctions) {
|
||||
FxApplication(Settings settings, Lazy<MainWindowComponent> mainWindow, Lazy<PreferencesComponent> preferencesWindow, UnlockComponent.Builder unlockWindowBuilder, Optional<MacFunctions> macFunctions) {
|
||||
this.settings = settings;
|
||||
this.mainWindow = mainWindow;
|
||||
this.preferencesWindow = preferencesWindow;
|
||||
this.unlockWindowBuilder = unlockWindowBuilder;
|
||||
this.macFunctions = macFunctions;
|
||||
}
|
||||
|
||||
@@ -64,6 +68,13 @@ public class FxApplication extends Application {
|
||||
});
|
||||
}
|
||||
|
||||
public void showUnlockWindow(Vault vault) {
|
||||
Platform.runLater(() -> {
|
||||
unlockWindowBuilder.vault(vault).build().showUnlockWindow();
|
||||
LOG.debug("Showing UnlockWindow for {}", vault.getDisplayableName());
|
||||
});
|
||||
}
|
||||
|
||||
private void themeChanged(@SuppressWarnings("unused") ObservableValue<? extends UiTheme> observable, @SuppressWarnings("unused") UiTheme oldValue, UiTheme newValue) {
|
||||
loadSelectedStyleSheet(newValue);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ package org.cryptomator.ui.mainwindow;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||
import javafx.fxml.FXML;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.common.Tasks;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.ui.unlock.UnlockComponent;
|
||||
import org.cryptomator.ui.fxapp.FxApplication;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -15,31 +15,23 @@ import java.util.concurrent.ExecutorService;
|
||||
|
||||
@MainWindowScoped
|
||||
public class VaultDetailController implements FxController {
|
||||
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(VaultDetailController.class);
|
||||
|
||||
|
||||
private final ReadOnlyObjectProperty<Vault> vault;
|
||||
private final ExecutorService executor;
|
||||
private final UnlockComponent.Builder unlockWindow;
|
||||
private final FxApplication application;
|
||||
|
||||
@Inject
|
||||
VaultDetailController(ObjectProperty<Vault> vault, ExecutorService executor, UnlockComponent.Builder unlockWindow) {
|
||||
VaultDetailController(ObjectProperty<Vault> vault, ExecutorService executor, FxApplication application) {
|
||||
this.vault = vault;
|
||||
this.executor = executor;
|
||||
this.unlockWindow = unlockWindow;
|
||||
}
|
||||
|
||||
public ReadOnlyObjectProperty<Vault> vaultProperty() {
|
||||
return vault;
|
||||
}
|
||||
|
||||
public Vault getVault() {
|
||||
return vault.get();
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void unlock() {
|
||||
unlockWindow.vault(vault.get()).build().showUnlockWindow();
|
||||
application.showUnlockWindow(vault.get());
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -55,4 +47,15 @@ public class VaultDetailController implements FxController {
|
||||
// TODO
|
||||
}).runOnce(executor);
|
||||
}
|
||||
|
||||
/* Observable Properties */
|
||||
|
||||
public ReadOnlyObjectProperty<Vault> vaultProperty() {
|
||||
return vault;
|
||||
}
|
||||
|
||||
public Vault getVault() {
|
||||
return vault.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import java.awt.Menu;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.EventObject;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@TrayMenuScoped
|
||||
class TrayMenuController {
|
||||
@@ -94,6 +96,7 @@ class TrayMenuController {
|
||||
// TODO add action listeners
|
||||
if (vault.isLocked()) {
|
||||
MenuItem unlockItem = new MenuItem("TODO unlock");
|
||||
unlockItem.addActionListener(createActionListenerForVault(vault, this::unlockVault));
|
||||
submenu.add(unlockItem);
|
||||
} else if (vault.isUnlocked()) {
|
||||
MenuItem lockItem = new MenuItem("TODO lock");
|
||||
@@ -104,6 +107,14 @@ class TrayMenuController {
|
||||
}
|
||||
}
|
||||
|
||||
private ActionListener createActionListenerForVault(Vault vault, Consumer<Vault> consumer) {
|
||||
return actionEvent -> consumer.accept(vault);
|
||||
}
|
||||
|
||||
private void unlockVault(Vault vault) {
|
||||
fxApplicationStarter.get(true).thenAccept(app -> app.showUnlockWindow(vault));
|
||||
}
|
||||
|
||||
void showMainWindow(@SuppressWarnings("unused") ActionEvent actionEvent) {
|
||||
fxApplicationStarter.get(true).thenAccept(FxApplication::showMainWindow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user