made Settings and DebugMode a Singleton

This commit is contained in:
Sebastian Stenzel
2019-02-20 23:28:33 +01:00
parent 98e5c3ff88
commit 8814372c68
6 changed files with 14 additions and 16 deletions

View File

@@ -27,6 +27,7 @@ public class Cryptomator {
if (endpoint.isConnectedToRemote()) {
LOG.info("Found running application instance. Shutting down.");
} else {
CRYPTOMATOR_COMPONENT.debugMode().initialize();
CleanShutdownPerformer.registerShutdownHook();
Application.launch(MainApp.class, args);
}
@@ -43,12 +44,9 @@ public class Cryptomator {
// We need a separate FX Application class, until we can use the module system. See https://stackoverflow.com/q/54756176/4014509
public static class MainApp extends Application {
private Stage primaryStage;
@Override
public void start(Stage primaryStage) {
LOG.info("JavaFX application started.");
this.primaryStage = primaryStage;
primaryStage.setMinWidth(652.0);
primaryStage.setMinHeight(440.0);
@@ -57,8 +55,6 @@ public class Cryptomator {
.mainWindow(primaryStage) //
.build();
fxApplicationComponent.debugMode().initialize();
MainController mainCtrl = fxApplicationComponent.fxmlLoader().load("/fxml/main.fxml");
mainCtrl.initStage(primaryStage);
primaryStage.show();
@@ -66,8 +62,6 @@ public class Cryptomator {
@Override
public void stop() {
assert primaryStage != null;
primaryStage.hide();
LOG.info("JavaFX application stopped.");
}

View File

@@ -3,6 +3,7 @@ package org.cryptomator.launcher;
import dagger.Component;
import org.cryptomator.common.CommonsModule;
import org.cryptomator.common.Environment;
import org.cryptomator.logging.DebugMode;
import javax.inject.Named;
import javax.inject.Singleton;
@@ -12,6 +13,8 @@ import java.util.Optional;
@Component(modules = {CryptomatorModule.class, CommonsModule.class})
public interface CryptomatorComponent {
DebugMode debugMode();
IpcFactory ipcFactory();
@Named("applicationVersion")

View File

@@ -2,6 +2,8 @@ package org.cryptomator.launcher;
import dagger.Module;
import dagger.Provides;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.settings.SettingsProvider;
import javax.inject.Named;
import javax.inject.Singleton;
@@ -13,6 +15,12 @@ import java.util.concurrent.BlockingQueue;
@Module
class CryptomatorModule {
@Provides
@Singleton
Settings provideSettings(SettingsProvider settingsProvider) {
return settingsProvider.get();
}
@Provides
@Singleton
@Named("fileOpenRequests")

View File

@@ -21,8 +21,6 @@ interface FxApplicationComponent {
ViewControllerLoader fxmlLoader();
DebugMode debugMode();
@Subcomponent.Builder
interface Builder {

View File

@@ -14,11 +14,12 @@ import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Collection;
import static java.util.Arrays.asList;
@FxApplicationScoped
@Singleton
public class DebugMode {
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(DebugMode.class);

View File

@@ -34,12 +34,6 @@ public class UiModule {
private static final int NUM_SCHEDULER_THREADS = 4;
@Provides
@FxApplicationScoped
Settings provideSettings(SettingsProvider settingsProvider) {
return settingsProvider.get();
}
@Provides
@FxApplicationScoped
ScheduledExecutorService provideScheduledExecutorService(@Named("shutdownTaskScheduler") Consumer<Runnable> shutdownTaskScheduler) {