Skip to content

Commit

Permalink
Merge pull request #3 from klimuts/develop
Browse files Browse the repository at this point in the history
New DI mechanism
  • Loading branch information
klimuts authored Jul 20, 2022
2 parents 2d67363 + 61986bf commit 7cb3e71
Show file tree
Hide file tree
Showing 32 changed files with 253 additions and 105 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SNX Client v1.0.0
# SNX Client v1.0.1

Graphical user interface for CheckPoint SSL Network Extender (SNX) for Linux OS.

Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ dependencies {
implementation 'com.dorkbox:SystemTray:4.1'
implementation 'com.dorkbox:SystemTray-Dorkbox-Util:2.20'

implementation 'io.github.classgraph:classgraph:4.8.149'
implementation 'io.github.toolfactory:jvm-driver:9.1.1'

compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testImplementation "org.projectlombok:lombok:1.18.24"
Expand Down
2 changes: 1 addition & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SNX Client v1.0.0
# SNX Client v1.0.1

## ENG

Expand Down
6 changes: 6 additions & 0 deletions release/up_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# Create a git tag according to the version of the application

version=$(cat ../src/main/resources/version)

git tag v"$version"
3 changes: 0 additions & 3 deletions release/up_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ fi

new_version=$(cat ../src/main/resources/version)

# Create an appropriate git tag
git tag v"$new_version"

# Change the version in the Readme files
sed -i "1c\# SNX Client v$new_version" ../doc/README.md
sed -i "1c\# SNX Client v$new_version" ../README.md
47 changes: 28 additions & 19 deletions src/main/java/com/klimuts/snxgui/SnxClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.klimuts.snxgui.config.AppConfig;
import com.klimuts.snxgui.di.Context;
import com.klimuts.snxgui.model.ConfigKey;
import com.klimuts.snxgui.di.ContextInitializer;
import com.klimuts.snxgui.di.annotation.Autowired;
import com.klimuts.snxgui.di.annotation.Component;
import com.klimuts.snxgui.model.enums.ConfigKey;
import com.klimuts.snxgui.service.ConfigService;
import com.klimuts.snxgui.service.ConnectionService;
import com.klimuts.snxgui.service.ModalWindowService;
Expand All @@ -20,24 +23,35 @@

import java.io.IOException;

@Component
public class SnxClient extends Application {

@Autowired private ConfigService configService;
@Autowired private ConnectionService connectionService;
@Autowired private ModalWindowService modalWindowService;

private double xOffset = 0;
private double yOffset = 0;

private SystemTray systemTray;
private ConfigService configService;
private ConnectionService connectionService;
private ModalWindowService modalWindowService;

@Override
public void start(Stage stage) throws IOException {
Platform.setImplicitExit(false);

initDependencies();
Parent root = initMainStage(stage);
initGlobalExceptionHandlers(stage);
initDragSettings(stage, root);
initSystemTray(stage);

stage.show();
}

private Parent initMainStage(Stage stage) throws IOException {
Context context = ContextInitializer.init(this, SnxClient.class.getPackageName());

FXMLLoader loader = new FXMLLoader(SnxClient.class.getResource("main.fxml"));
loader.setControllerFactory(context::getBean);
Parent root = loader.load();

Scene scene = new Scene(root, 640, 460);
Expand All @@ -49,18 +63,8 @@ public void start(Stage stage) throws IOException {
stage.getIcons().add(new javafx.scene.image.Image("app_icon.png"));
stage.setTitle(AppConfig.APP_NAME);
stage.setScene(scene);
stage.show();

initDragSettings(stage, root);
initSystemTray(stage);
}

private void initDependencies() throws IOException {
Context.init();
modalWindowService = Context.getBean(ModalWindowService.class);
connectionService = Context.getBean(ConnectionService.class);
configService = Context.getBean(ConfigService.class);
configService.initConfig();
return root;
}

private void initDragSettings(Stage stage, Parent root) {
Expand All @@ -81,6 +85,7 @@ public void initSystemTray(Stage stage) {
throw new RuntimeException("Unable to load SystemTray!");
}
systemTray.installShutdownHook();

systemTray.getMenu().add(new MenuItem("Show", e -> {
Platform.runLater(() -> {
if (stage.isShowing()) {
Expand All @@ -91,10 +96,14 @@ public void initSystemTray(Stage stage) {
});
})).setShortcut('o');

systemTray.getMenu().add(new MenuItem("Quit", e -> {
systemTray.getMenu().add(new MenuItem("Quit", event -> {
systemTray.shutdown();
if (Boolean.parseBoolean(configService.getConfig().get(ConfigKey.DISCONNECT_ON_EXIT))) {
connectionService.disconnect();
try {
if (Boolean.parseBoolean(configService.getConfig().get(ConfigKey.DISCONNECT_ON_EXIT))) {
connectionService.disconnect();
}
} catch (Exception e) {
Platform.exit();
}
Platform.exit();
})).setShortcut('q');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.klimuts.snxgui.SnxClient;
import com.klimuts.snxgui.config.AppConfig;
import com.klimuts.snxgui.di.annotation.Component;
import com.klimuts.snxgui.exception.ShownOnModalException;
import javafx.application.Platform;
import javafx.fxml.FXML;
Expand All @@ -14,18 +15,18 @@
import java.util.Optional;
import java.util.stream.Collectors;

@Component
public class AboutWindowController extends WindowController {

@FXML public Label version;
@FXML public Label authorLabel;

public void initialize() {
super.initialize();

Platform.runLater(this::readVersion);
}

public void onAuthorLabelClicked(MouseEvent mouseEvent) {
@FXML
public void onAuthorLabelClick(MouseEvent mouseEvent) {
new SnxClient().getHostServices().showDocument("mailto:" + authorLabel.getText() + "?subject=SNX Client");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.klimuts.snxgui.controller;

import com.klimuts.snxgui.di.Context;
import com.klimuts.snxgui.di.annotation.Component;
import com.klimuts.snxgui.exception.ShownOnModalException;
import com.klimuts.snxgui.model.ConfigKey;
import com.klimuts.snxgui.service.ConfigService;
import com.klimuts.snxgui.model.enums.ConfigKey;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
Expand All @@ -12,19 +11,15 @@
import java.io.IOException;
import java.util.Map;

@Component
public class ConfigWindowController extends WindowController {

@FXML public TextField serverAddress;
@FXML public TextField login;
@FXML public CheckBox enableDebug;
@FXML public CheckBox disconnectOnExit;

private ConfigService configService;

public void initialize() {
super.initialize();
configService = Context.getBean(ConfigService.class);

Map<ConfigKey, String> config = configService.getConfig();

serverAddress.setText(config.get(ConfigKey.SERVER_ADDRESS));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.klimuts.snxgui.controller;

import com.klimuts.snxgui.di.annotation.Component;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Label;

@Component
public class ErrorWindowController extends WindowController {

@FXML
public Label message;

public void initialize() {
super.initialize();

Platform.runLater(() -> message.setText(modalWindowService.getErrorMessage()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.klimuts.snxgui.controller;

import com.klimuts.snxgui.SnxClient;
import com.klimuts.snxgui.di.annotation.Autowired;
import com.klimuts.snxgui.di.annotation.Component;
import com.klimuts.snxgui.model.ModalWindowConfig;
import com.klimuts.snxgui.model.ModalWindowType;
import com.klimuts.snxgui.model.enums.ModalWindowType;
import com.klimuts.snxgui.service.ConfigService;
import com.klimuts.snxgui.service.ConnectionService;
import com.klimuts.snxgui.service.ModalWindowService;
import dorkbox.systemTray.SystemTray;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand All @@ -14,8 +19,13 @@

import java.net.URL;

@Component
public class MainWindowController extends WindowController {

@Autowired private ConfigService configService;
@Autowired private ConnectionService connectionService;
@Autowired private ModalWindowService modalWindowService;

@FXML public Button closeButton;
@FXML public Button minButton;
@FXML public Button connectButton;
Expand All @@ -32,7 +42,6 @@ public class MainWindowController extends WindowController {
private URL disconnectedTrayIconUrl;

public void initialize() {
super.initialize();
systemTray = SystemTray.get("SNX");

connectedTrayIconUrl = SnxClient.class.getResource("tray_icons/connected_icon.png");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.klimuts.snxgui.controller;

import com.klimuts.snxgui.di.annotation.Component;
import com.klimuts.snxgui.exception.ShownOnModalException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand All @@ -9,14 +10,14 @@

import java.io.IOException;

@Component
public class PasswordWindowController extends WindowController {

@FXML public ToggleButton unmaskButton;
@FXML public PasswordField passwordField;
@FXML public TextField passwordTextField;

public void initialize() {
super.initialize();
this.onUnmaskButtonClick(null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.klimuts.snxgui.controller;

import com.klimuts.snxgui.di.annotation.Component;
import com.klimuts.snxgui.exception.ShownOnModalException;
import com.klimuts.snxgui.model.SessionInfoKey;
import com.klimuts.snxgui.model.enums.SessionInfoKey;
import javafx.fxml.FXML;
import javafx.scene.control.Label;

import java.io.IOException;
import java.util.Map;

@Component
public class SessionInfoWindowController extends WindowController {

@FXML public Label officeModeIP;
Expand All @@ -17,7 +19,6 @@ public class SessionInfoWindowController extends WindowController {
@FXML public Label timeout;

public void initialize() {
super.initialize();
try {
Map<SessionInfoKey, String> sessionInfo = connectionService.getConnectionInfo();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.klimuts.snxgui.controller;

import com.klimuts.snxgui.di.Context;
import com.klimuts.snxgui.di.annotation.Autowired;
import com.klimuts.snxgui.service.ConfigService;
import com.klimuts.snxgui.service.ConnectionService;
import com.klimuts.snxgui.service.ModalWindowService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;

public class WindowController {

protected ModalWindowService modalWindowService;
protected ConnectionService connectionService;
@Autowired protected ConfigService configService;
@Autowired protected ConnectionService connectionService;
@Autowired protected ModalWindowService modalWindowService;

public void initialize() {
connectionService = Context.getBean(ConnectionService.class);
modalWindowService = Context.getBean(ModalWindowService.class);
}

public void onCloseButtonClick(ActionEvent actionEvent) {
@FXML
protected void onCloseButtonClick(ActionEvent actionEvent) {
modalWindowService.closeModalWindow();
}

Expand Down
22 changes: 9 additions & 13 deletions src/main/java/com/klimuts/snxgui/di/Context.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
package com.klimuts.snxgui.di;

import com.klimuts.snxgui.handler.ShellCommandHandler;
import com.klimuts.snxgui.service.*;
import com.klimuts.snxgui.di.annotation.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class Context {

private static Map<Class<?>, Object> beans;
private final Map<Class<?>, Object> beans;

public static void init() {
beans = new HashMap<>();
public Context(Map<Class<?>, Object> beans) {
this.beans = beans;
}

beans.put(ModalWindowService.class, new ModalWindowService());
beans.put(ShellCommandHandler.class, new ShellCommandHandler());
beans.put(ModalPaneLoader.class, new ModalPaneLoader());
beans.put(StateFileService.class, new StateFileService());
beans.put(ConnectionService.class, new ConnectionService(getBean(ShellCommandHandler.class), getBean(StateFileService.class)));
beans.put(ConfigService.class, new ConfigService());
public void addBean(Class<?> clazz, Object bean) {
beans.put(clazz, bean);
}

@SuppressWarnings("unchecked")
public static <T> T getBean(Class<?> clazz) {
public <T> T getBean(Class<?> clazz) {
return (T) beans.get(clazz);
}

Expand Down
Loading

0 comments on commit 7cb3e71

Please sign in to comment.