TransferBot/src/main/java/it/cavallium/App.java
Andrea Cavalli 85e8550e1b Update title
2020-10-20 03:00:10 +02:00

83 lines
2.1 KiB
Java

package it.cavallium;
import io.vertx.core.Vertx;
import it.tdlight.common.Init;
import it.tdlight.common.utils.CantLoadLibrary;
import it.tdlight.tdlibsession.td.middle.TdClusterManager;
import java.time.Duration;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
import org.slf4j.event.Level;
/**
* JavaFX App
*/
public class App extends Application {
public static final String VERSION = "1.0.0";
private static TdClusterManager clusterManager;
private static SettingsService settingsService;
private static TransferService transferService;
private static LogService logService;
private static Scene scene;
@Override
public void start(Stage stage) throws IOException, CantLoadLibrary {
Init.start();
clusterManager = new TdClusterManager(null, null, Vertx.vertx(), null);
settingsService = new SettingsServiceImpl();
logService = new LogServiceImpl();
logService.append(Level.INFO, "Initializing");
transferService = new TransferServiceImpl(clusterManager);
transferService.setApiId(94575);
transferService.setApiHash("a3406de8d171bb422bb6ddf3bbd800e2");
scene = new Scene(loadFXML("primary"), 800, 600);
stage.setScene(scene);
stage.setTitle("TransferBot");
stage.show();
logService.append(Level.INFO, "Initialized");
}
@Override
public void stop() throws Exception {
App.getTransferService().quit().block(Duration.ofSeconds(15));
System.exit(0);
}
static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml));
}
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
}
public static void main(String[] args) {
launch();
}
public static SettingsService getSettingsService() {
return settingsService;
}
public static LogService getLogService() {
return logService;
}
public static TransferService getTransferService() {
return transferService;
}
}