mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Introduce app.gui.MainModule
This commit is contained in:
parent
21098afd45
commit
486cd9824e
@ -20,7 +20,6 @@ package io.bitsquare.app;
|
|||||||
import io.bitsquare.AbstractBitsquareModule;
|
import io.bitsquare.AbstractBitsquareModule;
|
||||||
import io.bitsquare.btc.BitcoinModule;
|
import io.bitsquare.btc.BitcoinModule;
|
||||||
import io.bitsquare.crypto.CryptoModule;
|
import io.bitsquare.crypto.CryptoModule;
|
||||||
import io.bitsquare.gui.GuiModule;
|
|
||||||
import io.bitsquare.msg.MessageModule;
|
import io.bitsquare.msg.MessageModule;
|
||||||
import io.bitsquare.msg.tomp2p.TomP2PMessageModule;
|
import io.bitsquare.msg.tomp2p.TomP2PMessageModule;
|
||||||
import io.bitsquare.offer.OfferModule;
|
import io.bitsquare.offer.OfferModule;
|
||||||
@ -29,15 +28,12 @@ import io.bitsquare.persistence.Persistence;
|
|||||||
import io.bitsquare.settings.Settings;
|
import io.bitsquare.settings.Settings;
|
||||||
import io.bitsquare.trade.TradeModule;
|
import io.bitsquare.trade.TradeModule;
|
||||||
import io.bitsquare.user.User;
|
import io.bitsquare.user.User;
|
||||||
import io.bitsquare.util.ConfigLoader;
|
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import net.tomp2p.connection.Ports;
|
import net.tomp2p.connection.Ports;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -46,19 +42,16 @@ import org.slf4j.LoggerFactory;
|
|||||||
import akka.actor.ActorSystem;
|
import akka.actor.ActorSystem;
|
||||||
import scala.concurrent.duration.Duration;
|
import scala.concurrent.duration.Duration;
|
||||||
|
|
||||||
public class BitsquareModule extends AbstractBitsquareModule {
|
/**
|
||||||
|
* Configures all non-UI modules necessary to run a Bitsquare application.
|
||||||
|
*/
|
||||||
|
public class AppModule extends AbstractBitsquareModule {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(AppModule.class);
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(BitsquareModule.class);
|
|
||||||
private final Stage primaryStage;
|
|
||||||
private final String appName;
|
private final String appName;
|
||||||
|
|
||||||
public BitsquareModule(Stage primaryStage, String appName) {
|
public AppModule(Properties properties, String appName) {
|
||||||
this(primaryStage, appName, ConfigLoader.loadConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
public BitsquareModule(Stage primaryStage, String appName, Properties properties) {
|
|
||||||
super(properties);
|
super(properties);
|
||||||
this.primaryStage = primaryStage;
|
|
||||||
this.appName = appName;
|
this.appName = appName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +66,6 @@ public class BitsquareModule extends AbstractBitsquareModule {
|
|||||||
install(cryptoModule());
|
install(cryptoModule());
|
||||||
install(tradeModule());
|
install(tradeModule());
|
||||||
install(offerModule());
|
install(offerModule());
|
||||||
install(guiModule());
|
|
||||||
|
|
||||||
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
bindConstant().annotatedWith(Names.named("appName")).to(appName);
|
||||||
bind(ActorSystem.class).toInstance(ActorSystem.create(appName));
|
bind(ActorSystem.class).toInstance(ActorSystem.create(appName));
|
||||||
@ -100,10 +92,6 @@ public class BitsquareModule extends AbstractBitsquareModule {
|
|||||||
|
|
||||||
protected OfferModule offerModule() { return new TomP2POfferModule(properties); }
|
protected OfferModule offerModule() { return new TomP2POfferModule(properties); }
|
||||||
|
|
||||||
protected GuiModule guiModule() {
|
|
||||||
return new GuiModule(properties, primaryStage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doClose(Injector injector) {
|
protected void doClose(Injector injector) {
|
||||||
ActorSystem actorSystem = injector.getInstance(ActorSystem.class);
|
ActorSystem actorSystem = injector.getInstance(ActorSystem.class);
|
@ -18,7 +18,6 @@
|
|||||||
package io.bitsquare.app.gui;
|
package io.bitsquare.app.gui;
|
||||||
|
|
||||||
import io.bitsquare.app.ArgumentParser;
|
import io.bitsquare.app.ArgumentParser;
|
||||||
import io.bitsquare.app.BitsquareModule;
|
|
||||||
import io.bitsquare.gui.Navigation;
|
import io.bitsquare.gui.Navigation;
|
||||||
import io.bitsquare.gui.SystemTray;
|
import io.bitsquare.gui.SystemTray;
|
||||||
import io.bitsquare.gui.ViewLoader;
|
import io.bitsquare.gui.ViewLoader;
|
||||||
@ -51,7 +50,7 @@ public class Main extends Application {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(Main.class);
|
private static final Logger log = LoggerFactory.getLogger(Main.class);
|
||||||
private static String appName = "Bitsquare";
|
private static String appName = "Bitsquare";
|
||||||
|
|
||||||
private BitsquareModule bitsquareModule;
|
private MainModule mainModule;
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -67,8 +66,8 @@ public class Main extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
bitsquareModule = new BitsquareModule(primaryStage, appName);
|
mainModule = new MainModule(appName, primaryStage);
|
||||||
injector = Guice.createInjector(bitsquareModule);
|
injector = Guice.createInjector(mainModule);
|
||||||
|
|
||||||
|
|
||||||
// route uncaught exceptions to a user-facing dialog
|
// route uncaught exceptions to a user-facing dialog
|
||||||
@ -138,7 +137,7 @@ public class Main extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
bitsquareModule.close(injector);
|
mainModule.close(injector);
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
src/main/java/io/bitsquare/app/gui/MainModule.java
Normal file
43
src/main/java/io/bitsquare/app/gui/MainModule.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Bitsquare.
|
||||||
|
*
|
||||||
|
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.bitsquare.app.gui;
|
||||||
|
|
||||||
|
import io.bitsquare.AbstractBitsquareModule;
|
||||||
|
import io.bitsquare.app.AppModule;
|
||||||
|
import io.bitsquare.gui.GuiModule;
|
||||||
|
import io.bitsquare.util.ConfigLoader;
|
||||||
|
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
class MainModule extends AbstractBitsquareModule {
|
||||||
|
|
||||||
|
private final String appName;
|
||||||
|
private final Stage primaryStage;
|
||||||
|
|
||||||
|
public MainModule(String appName, Stage primaryStage) {
|
||||||
|
super(ConfigLoader.loadConfig());
|
||||||
|
this.appName = appName;
|
||||||
|
this.primaryStage = primaryStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
install(new AppModule(properties, appName));
|
||||||
|
install(new GuiModule(properties, primaryStage));
|
||||||
|
}
|
||||||
|
}
|
@ -15,9 +15,11 @@
|
|||||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.bitsquare.gui;
|
package io.bitsquare.app.gui;
|
||||||
|
|
||||||
import io.bitsquare.app.BitsquareModule;
|
import io.bitsquare.gui.FatalException;
|
||||||
|
import io.bitsquare.gui.Navigation;
|
||||||
|
import io.bitsquare.gui.ViewLoader;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
@ -30,7 +32,7 @@ import org.junit.Before;
|
|||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ViewLoaderTest {
|
public class ViewLoaderTests {
|
||||||
|
|
||||||
public static class TestApp extends Application {
|
public static class TestApp extends Application {
|
||||||
static Stage primaryStage;
|
static Stage primaryStage;
|
||||||
@ -56,7 +58,7 @@ public class ViewLoaderTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Injector injector = Guice.createInjector(new BitsquareModule(TestApp.primaryStage, "testApp"));
|
Injector injector = Guice.createInjector(new MainModule("testApp", TestApp.primaryStage));
|
||||||
ViewLoader.setInjector(injector);
|
ViewLoader.setInjector(injector);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user