Skip to content

Commit

Permalink
themes and more
Browse files Browse the repository at this point in the history
  • Loading branch information
sirjonasxx committed Oct 2, 2021
1 parent e94db6c commit eb79ea0
Show file tree
Hide file tree
Showing 18 changed files with 1,055 additions and 104 deletions.
104 changes: 16 additions & 88 deletions G-Earth/src/main/java/gearth/Main.java
Original file line number Diff line number Diff line change
@@ -1,57 +1,50 @@
package gearth;

import gearth.misc.AdminValidator;
import gearth.misc.Cacher;
import gearth.misc.UpdateChecker;
import gearth.ui.GEarthController;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Region;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.json.JSONObject;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;

// run as root issue Invalid MIT-MAGIC-COOKIE-1 key fix: https://stackoverflow.com/questions/48139447/invalid-mit-magic-cookie-1-key

public class Main extends Application {

public static Application main;
public static String version = "1.5";
private static String gitApi = "https://api.github.com/repos/sirjonasxx/G-Earth/releases/latest";
public static String gitApi = "https://api.github.com/repos/sirjonasxx/G-Earth/releases/latest";
public static String theme = "G-Earth";

static {
if (Cacher.getCacheContents().has("theme")) {
theme = Cacher.getCacheContents().getString("theme");
}
}

@Override
public void start(Stage primaryStage) throws Exception{
main = this;

FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/G-Earth.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/G-Earth.fxml"));
Parent root = loader.load();
GEarthController companion = loader.getController();
companion.setStage(primaryStage);

primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("G-EarthLogoSmaller.png")));
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(String.format("/gearth/themes/%s/logoSmall.png", theme))));

primaryStage.setTitle("G-Earth " + version);
primaryStage.setTitle(theme + " " + version);
// https://stackoverflow.com/questions/20732100/javafx-why-does-stage-setresizablefalse-cause-additional-margins
// primaryStage.setScene(new Scene(root, 650, 295));
primaryStage.setScene(new Scene(root));
primaryStage.setResizable(false);
primaryStage.sizeToScene();

primaryStage.show();
primaryStage.getScene().getStylesheets().add(getClass().getResource("ui/bootstrap3.css").toExternalForm());
primaryStage.getScene().getStylesheets().add(getClass().getResource(String.format("/gearth/themes/%s/styling.css", theme)).toExternalForm());

primaryStage.setOnCloseRequest( event -> {
companion.exit();
Expand All @@ -61,61 +54,8 @@ public void start(Stage primaryStage) throws Exception{
System.exit(0);
});

new Thread(() -> {
if (!AdminValidator.isAdmin()) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.WARNING, "G-Earth needs admin privileges in order to work on Flash, please restart G-Earth with admin permissions unless you're using Unity", ButtonType.OK);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.setResizable(false);
alert.show();
});

}
}).start();

new Thread(() -> {
try {
JSONObject object = new JSONObject(IOUtils.toString(
new URL(gitApi).openStream(), StandardCharsets.UTF_8));

String gitv = (String)object.get("tag_name");
if (new ComparableVersion(version).compareTo(new ComparableVersion(gitv)) < 0) {
Platform.runLater(() -> {
String body = (String)object.get("body");
boolean isForcedUpdate = body.contains("(!)");

Alert alert = new Alert(isForcedUpdate ? Alert.AlertType.ERROR : Alert.AlertType.INFORMATION, "G-Earth is outdated!", ButtonType.OK);

FlowPane fp = new FlowPane();
Label lbl = new Label("A new version of G-Earth has been found ("+gitv+")" + System.lineSeparator()+ System.lineSeparator() + "Update to the latest version:");
Hyperlink link = new Hyperlink("https://github.com/sirjonasxx/G-Earth/releases");
fp.getChildren().addAll( lbl, link);
link.setOnAction(event -> {
Main.main.getHostServices().showDocument(link.getText());
event.consume();
});



WebView webView = new WebView();
webView.getEngine().loadContent("<html>A new version of G-Earth has been found ("+gitv+")<br><br>Update to the latest version:<br><a href=\"https://github.com/sirjonasxx/G-Earth/releases\">https://github.com/sirjonasxx/G-Earth/releases</a></html>");
webView.setPrefSize(500, 200);

alert.setResizable(false);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.getDialogPane().setContent(fp);
if (isForcedUpdate) {
alert.setOnCloseRequest(event -> System.exit(0));
}
alert.show();

});
}

} catch (IOException e) {
// e.printStackTrace();
}
}).start();
AdminValidator.validate();
UpdateChecker.checkForUpdates();

}

Expand Down Expand Up @@ -146,15 +86,3 @@ public static String getArgument(String... arg) {
return null;
}
}

// Hi
// I'm
// Lande
// I want
// The role
// Developer
// Pls
// You say :
// Change 10 lines
// I dit it.
// https://i.imgur.com/QEHV2NZ.png
19 changes: 19 additions & 0 deletions G-Earth/src/main/java/gearth/misc/AdminValidator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package gearth.misc;

import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.Region;

import java.io.PrintStream;
import java.util.prefs.Preferences;

Expand Down Expand Up @@ -34,4 +39,18 @@ public static boolean isAdmin() {
return isAdmin;
}

public static void validate() {
new Thread(() -> {
if (!AdminValidator.isAdmin()) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.WARNING, "G-Earth needs admin privileges in order to work on Flash, please restart G-Earth with admin permissions unless you're using Unity", ButtonType.OK);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.setResizable(false);
alert.show();
});

}
}).start();
}

}
71 changes: 71 additions & 0 deletions G-Earth/src/main/java/gearth/misc/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package gearth.misc;

import gearth.Main;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Region;
import javafx.scene.web.WebView;
import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.json.JSONObject;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import static gearth.Main.gitApi;
import static gearth.Main.version;

public class UpdateChecker {

public static void checkForUpdates() {
new Thread(() -> {
try {
JSONObject object = new JSONObject(IOUtils.toString(
new URL(gitApi).openStream(), StandardCharsets.UTF_8));

String gitv = (String)object.get("tag_name");
if (new ComparableVersion(version).compareTo(new ComparableVersion(gitv)) < 0) {
Platform.runLater(() -> {
String body = (String)object.get("body");
boolean isForcedUpdate = body.contains("(!)");

Alert alert = new Alert(isForcedUpdate ? Alert.AlertType.ERROR : Alert.AlertType.INFORMATION, "G-Earth is outdated!", ButtonType.OK);

FlowPane fp = new FlowPane();
Label lbl = new Label("A new version of G-Earth has been found ("+gitv+")" + System.lineSeparator()+ System.lineSeparator() + "Update to the latest version:");
Hyperlink link = new Hyperlink("https://github.com/sirjonasxx/G-Earth/releases");
fp.getChildren().addAll( lbl, link);
link.setOnAction(event -> {
Main.main.getHostServices().showDocument(link.getText());
event.consume();
});



WebView webView = new WebView();
webView.getEngine().loadContent("<html>A new version of G-Earth has been found ("+gitv+")<br><br>Update to the latest version:<br><a href=\"https://github.com/sirjonasxx/G-Earth/releases\">https://github.com/sirjonasxx/G-Earth/releases</a></html>");
webView.setPrefSize(500, 200);

alert.setResizable(false);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.getDialogPane().setContent(fp);
if (isForcedUpdate) {
alert.setOnCloseRequest(event -> System.exit(0));
}
alert.show();

});
}

} catch (IOException e) {
// e.printStackTrace();
}
}).start();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public GExtensionStore createForm(Stage stage) throws Exception {
stage.setHeight(530);

stage.setScene(new Scene(root));
stage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
stage.getIcons().add(new Image(Main.class.getResourceAsStream("G-EarthLogoSmaller.png")));
stage.getScene().getStylesheets().add(GEarthController.class.getResource(String.format("/gearth/themes/%s/styling.css", Main.theme)).toExternalForm());
stage.getIcons().add(new Image(Main.class.getResourceAsStream(String.format("/gearth/themes/%s/logoSmall.png", Main.theme))));

GExtensionStore gExtensionStore = new GExtensionStore();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gearth.services.internal_extensions.uilogger;

import gearth.Main;
import gearth.extensions.InternalExtensionFormLauncher;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
Expand All @@ -16,12 +17,12 @@ public UiLogger createForm(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(UiLogger.class.getResource("UiLogger.fxml"));

Parent root = loader.load();
stage.setTitle("G-Earth | Packet Logger");
stage.setTitle(String.format("%s | Packet Logger", Main.theme));
stage.initModality(Modality.NONE);
stage.getIcons().add(new Image(getClass().getResourceAsStream("/gearth/G-EarthLogoSmaller.png")));
stage.getIcons().add(new Image(getClass().getResourceAsStream(String.format("/gearth/themes/%s/logoSmall.png", Main.theme))));

Scene scene = new Scene(root);
scene.getStylesheets().add("/gearth/ui/bootstrap3.css");
scene.getStylesheets().add(String.format("/gearth/themes/%s/styling.css", Main.theme));
scene.getStylesheets().add("/gearth/services/internal_extensions/uilogger/logger.css");

UiLoggerController controller = loader.getController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;

Expand Down Expand Up @@ -133,7 +132,7 @@ private void getVersion(String revision, HttpServletResponse response, String ur

private void getLogo(HttpServletResponse response) throws IOException {
OutputStream out = response.getOutputStream();
InputStream in = Main.class.getResourceAsStream("G-EarthLogo.png");
InputStream in = Main.class.getResourceAsStream(String.format("/gearth/themes/%s/logo.png", Main.theme));

byte[] bytes = new byte[4096];
int bytesRead;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ private void initialize() {
parent.getChildren().add(this);

if (item.extensionType() == ExtensionType.INTERNAL) {
setBackground(new Background(new BackgroundFill(Paint.valueOf("F0FFFF"), CornerRadii.EMPTY, Insets.EMPTY)));
getStyleClass().clear();
getStyleClass().add("internalExtension");
}


Expand Down Expand Up @@ -176,7 +177,8 @@ void initExtension(){
ExtensionItemContainer this2 = this;
item.getDeletedObservable().addListener(() -> Platform.runLater(() -> {
if (item.isInstalledExtension()) {
setBackground(new Background(new BackgroundFill(Paint.valueOf("#cccccc"),null, null)));
getStyleClass().clear();
getStyleClass().add("disconnectedExtension");
getChildren().remove(buttonsBox);
add(additionalButtonBox, 4, 0);
reloadButton.setVisible(true);
Expand All @@ -191,7 +193,8 @@ void hasReconnected(GEarthExtension extension) {
item = extension;
initExtension();

setBackground(new Background(new BackgroundFill(Paint.valueOf("#ffffff"),null, null)));
getStyleClass().clear();
getStyleClass().add("connectedExtension");
getChildren().remove(additionalButtonBox);
if (buttonsBox != null) {
add(buttonsBox, 4, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gearth.ui.extensions.logger;

import gearth.Main;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
Expand Down Expand Up @@ -34,15 +35,15 @@ public ExtensionLogger() {


stage = new Stage();
stage.setTitle("G-Earth | Extension Console");
stage.setTitle(String.format("%s | Extension Console", Main.theme));
stage.initModality(Modality.NONE);
stage.getIcons().add(new Image(getClass().getResourceAsStream("/gearth/G-EarthLogoSmaller.png")));
stage.getIcons().add(new Image(getClass().getResourceAsStream(String.format("/gearth/themes/%s/logoSmall.png", Main.theme))));
stage.setAlwaysOnTop(true);
stage.setMinHeight(235);
stage.setMinWidth(370);

Scene scene = new Scene(root);
scene.getStylesheets().add("/gearth/ui/bootstrap3.css");
scene.getStylesheets().add(String.format("/gearth/themes/%s/styling.css", Main.theme));
scene.getStylesheets().add("/gearth/ui/extensions/logger/logger.css");
ExtensionLoggerController controller = loader.getController();
controller.setStage(stage);
Expand Down
4 changes: 2 additions & 2 deletions G-Earth/src/main/java/gearth/ui/info/InfoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import gearth.ui.SubForm;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Region;
import javafx.scene.web.WebView;

Expand Down Expand Up @@ -34,9 +33,10 @@ public static void activateHyperlink(Hyperlink link) {
}

public void initialize() {
version.setText(version.getText().replace("$theme", Main.theme));
version.setText(version.getText().replace("$version", Main.version));

img_logo.setImage(new Image("/gearth/G-EarthLogo.png"));
img_logo.setImage(new Image(String.format("/gearth/themes/%s/logo.png", Main.theme)));

link_ase.setTooltip(new Tooltip("https://allseeingeye.to"));
link_darkbox.setTooltip(new Tooltip("https://darkbox.nl"));
Expand Down
Loading

0 comments on commit eb79ea0

Please sign in to comment.