mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-20 09:36:55 -04:00
show vault list in tray menu
This commit is contained in:
@@ -8,15 +8,19 @@
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.ui;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import javafx.beans.binding.Binding;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.frontend.webdav.WebDavServer;
|
||||
import org.cryptomator.keychain.KeychainModule;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationScoped;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
import org.cryptomator.ui.model.VaultList;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
import javax.inject.Named;
|
||||
@@ -31,13 +35,17 @@ import java.util.function.Consumer;
|
||||
// TODO move to common...
|
||||
@Deprecated(forRemoval = true, since = "1.5.0")
|
||||
@Module(includes = {KeychainModule.class})
|
||||
public class UiModule {
|
||||
public abstract class UiModule {
|
||||
|
||||
private static final int NUM_SCHEDULER_THREADS = 4;
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract ObservableList<Vault> bindVaultList(VaultList vaultList);
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
ScheduledExecutorService provideScheduledExecutorService(@Named("shutdownTaskScheduler") Consumer<Runnable> shutdownTaskScheduler) {
|
||||
static ScheduledExecutorService provideScheduledExecutorService(@Named("shutdownTaskScheduler") Consumer<Runnable> shutdownTaskScheduler) {
|
||||
final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(NUM_SCHEDULER_THREADS, r -> {
|
||||
Thread t = new Thread(r);
|
||||
@@ -52,7 +60,7 @@ public class UiModule {
|
||||
// TODO @Binds abstract ExecutorService bindExecutorService(ScheduledExecutorService executor); ?
|
||||
@Provides
|
||||
@Singleton
|
||||
ExecutorService provideExecutorService(@Named("shutdownTaskScheduler") Consumer<Runnable> shutdownTaskScheduler) {
|
||||
static ExecutorService provideExecutorService(@Named("shutdownTaskScheduler") Consumer<Runnable> shutdownTaskScheduler) {
|
||||
final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
ExecutorService executorService = Executors.newCachedThreadPool(r -> {
|
||||
Thread t = new Thread(r);
|
||||
@@ -66,7 +74,7 @@ public class UiModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Binding<InetSocketAddress> provideServerSocketAddressBinding(Settings settings) {
|
||||
static Binding<InetSocketAddress> provideServerSocketAddressBinding(Settings settings) {
|
||||
return Bindings.createObjectBinding(() -> {
|
||||
String host = SystemUtils.IS_OS_WINDOWS ? "127.0.0.1" : "localhost";
|
||||
return InetSocketAddress.createUnresolved(host, settings.port().intValue());
|
||||
@@ -75,7 +83,7 @@ public class UiModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
WebDavServer provideWebDavServer(Binding<InetSocketAddress> serverSocketAddressBinding) {
|
||||
static WebDavServer provideWebDavServer(Binding<InetSocketAddress> serverSocketAddressBinding) {
|
||||
WebDavServer server = WebDavServer.create();
|
||||
// no need to unsubscribe eventually, because server is a singleton
|
||||
EasyBind.subscribe(serverSocketAddressBinding, server::bind);
|
||||
|
||||
@@ -28,10 +28,6 @@ abstract class FxApplicationModule {
|
||||
@FxApplicationScoped
|
||||
abstract Application provideApplication(FxApplication application);
|
||||
|
||||
// TODO move to commons...
|
||||
@Binds
|
||||
abstract ObservableList<Vault> bindVaultList(VaultList vaultList);
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
static ObjectProperty<Vault> provideSelectedVault() {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.cryptomator.ui.traymenu;
|
||||
|
||||
import javafx.beans.Observable;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -17,13 +20,15 @@ class TrayMenuController {
|
||||
private final FxApplicationStarter fxApplicationStarter;
|
||||
private final CountDownLatch shutdownLatch;
|
||||
private final Settings settings;
|
||||
private final ObservableList<Vault> vaults;
|
||||
private final PopupMenu menu;
|
||||
|
||||
@Inject
|
||||
TrayMenuController(FxApplicationStarter fxApplicationStarter, @Named("shutdownLatch") CountDownLatch shutdownLatch, Settings settings) {
|
||||
TrayMenuController(FxApplicationStarter fxApplicationStarter, @Named("shutdownLatch") CountDownLatch shutdownLatch, Settings settings, ObservableList<Vault> vaults) {
|
||||
this.fxApplicationStarter = fxApplicationStarter;
|
||||
this.shutdownLatch = shutdownLatch;
|
||||
this.settings = settings;
|
||||
this.vaults = vaults;
|
||||
this.menu = new PopupMenu();
|
||||
}
|
||||
|
||||
@@ -32,7 +37,8 @@ class TrayMenuController {
|
||||
}
|
||||
|
||||
public void initTrayMenu() {
|
||||
// TODO add listeners
|
||||
vaults.addListener(this::vaultListChanged);
|
||||
|
||||
rebuildMenu();
|
||||
|
||||
// register preferences shortcut
|
||||
@@ -46,7 +52,13 @@ class TrayMenuController {
|
||||
}
|
||||
}
|
||||
|
||||
private void vaultListChanged(Observable observable) {
|
||||
rebuildMenu();
|
||||
}
|
||||
|
||||
private void rebuildMenu() {
|
||||
menu.removeAll();
|
||||
|
||||
MenuItem showMainWindowItem = new MenuItem("TODO show");
|
||||
showMainWindowItem.addActionListener(this::showMainWindow);
|
||||
menu.add(showMainWindowItem);
|
||||
@@ -56,7 +68,11 @@ class TrayMenuController {
|
||||
menu.add(showPreferencesItem);
|
||||
|
||||
menu.addSeparator();
|
||||
// foreach vault: add submenu
|
||||
for (Vault v : vaults) {
|
||||
// TODO what do we want to do with these? lock/unlock? reveal? submenu?
|
||||
MenuItem vaultItem = new MenuItem(v.getDisplayableName());
|
||||
menu.add(vaultItem);
|
||||
}
|
||||
menu.addSeparator();
|
||||
|
||||
MenuItem quitApplicationItem = new MenuItem("TODO quit");
|
||||
|
||||
Reference in New Issue
Block a user