Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Update to alpha 9: Add new settings and optimize module system
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldieeins committed May 24, 2024
1 parent 719b30a commit 6f1323b
Show file tree
Hide file tree
Showing 26 changed files with 732 additions and 226 deletions.
2 changes: 1 addition & 1 deletion application-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>application-main</artifactId>
<version>2024.5-alpha.7-fix.3</version>
<version>2024.5-alpha.9</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
Expand Down
5 changes: 5 additions & 0 deletions application-main/src/main/java/com/zyneonstudios/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.zyneonstudios;

import com.zyneonstudios.application.frame.ZyneonSplash;
import com.zyneonstudios.application.main.ApplicationConfig;
import com.zyneonstudios.application.main.NexusApplication;

public class Main {

public static ZyneonSplash splash = null;

/*
* Zyneon Application entry point
* by nerotvlive
* Contributions are welcome. Please add your name to the "by" line if you make any modifications.
*/

public static void main(String[] args) {
splash = new ZyneonSplash();
splash.setVisible(true);
// Creating application config
new ApplicationConfig(args);
// Launch new application object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,41 @@ private void sync(String request) {
Color background;
Color foreground;
// Set title bar background and foreground colors based on the request
String fReq = request_[0];
if(request_[0].equalsIgnoreCase("../assets/cronos/css/app-colors-dark.css")) {
background = Color.black;
foreground = Color.white;
} else if(request_[0].equalsIgnoreCase("../assets/cronos/css/app-colors-light.css")) {
background = Color.white;
foreground = Color.black;
} else if(request_[0].startsWith("automatic-")) {
request = request_[0].replaceFirst("automatic-","");
if(request.equals("dark")) {
background = Color.black;
foreground = Color.white;
} else {
background = Color.white;
foreground = Color.black;
}
fReq = "automatic";
} else {
background = Color.decode("#0a0310");
foreground = Color.white;
}
if(!ApplicationConfig.theme.equalsIgnoreCase(request_[0])) {
ApplicationConfig.theme = request_[0];
if(!ApplicationConfig.theme.equalsIgnoreCase(fReq)) {
ApplicationConfig.theme = fReq;
ApplicationConfig.getSettings().set("settings.theme", ApplicationConfig.theme);
}
String title = request_[1];
// Set the titlebar with the specified title, background, and foreground colors
frame.setTitlebar(title,background,foreground);
} else if(request.equals("exit")) {
frame.getApplication().getModuleLoader().deactivateModules();
System.exit(1);
} else if(request.equals("refresh")) {
frame.getBrowser().loadURL(ApplicationConfig.urlBase+ApplicationConfig.language+"/"+ApplicationConfig.startPage);
} else if(request.equals("restart")) {
frame.getApplication().restart();
} else if(request.startsWith("settings.")) {
// If the request starts with "settings.", synchronize settings
syncSettings(request.replaceFirst("settings.",""));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.zyneonstudios.application.frame;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.Objects;

public class ZyneonSplash extends JWindow {

public ZyneonSplash() {
super();
try {
setBackground(new Color(0, 0, 0, 0));
setSize(400, 400);
setLocationRelativeTo(null);
JLabel image;
image = new JLabel(new ImageIcon(ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/logo.png"))).getScaledInstance(getWidth(), getHeight(), Image.SCALE_SMOOTH)));
getContentPane().add(image);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ApplicationFrame extends WebFrame {

// Constructor
public ApplicationFrame(NexusApplication application, String url, String jcefPath) {
super(url, jcefPath); // Call superclass constructor
super(url, jcefPath, application); // Call superclass constructor
this.application = application; //Initialize application
this.connector = new FrameConnector(this); // Initialize FrameConnector
getClient().addDisplayHandler(new CefDisplayHandlerAdapter() {
Expand Down Expand Up @@ -85,4 +85,8 @@ public void executeJavaScript(String command) {
public void openCustomPage(String title, String pageId, String url) {
getBrowser().loadURL(ApplicationConfig.urlBase+ApplicationConfig.language+"/custom.html?title="+title+"&id="+pageId+"&url="+url);
}

public void executeCustomPageJS(String command) {
executeJavaScript("document.getElementById('iframe').contentWindow."+command);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zyneonstudios.application.frame.web;

import com.zyneonstudios.application.main.NexusApplication;
import javafx.application.Platform;
import live.nerotv.shademebaby.ShadeMeBaby;
import me.friwi.jcefmaven.CefAppBuilder;
Expand All @@ -17,12 +18,14 @@
import org.cef.handler.CefDownloadHandler;
import org.cef.handler.CefFocusHandlerAdapter;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.Objects;

public class WebFrame extends JFrame {

Expand All @@ -39,9 +42,9 @@ public class WebFrame extends JFrame {
private boolean browserFocus; // Flag indicating whether browser has focus

// Constructor
public WebFrame(String url, String jcefPath) {
public WebFrame(String url, String jcefPath, NexusApplication application) {
try {
init(url, jcefPath); // Initialize WebFrame
init(url, jcefPath, application); // Initialize WebFrame
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -65,7 +68,7 @@ public CefBrowser getBrowser() {
}

// Initialization method
private void init(String url, String jcefPath) throws UnsupportedPlatformException, IOException, CefInitializationException, InterruptedException {
private void init(String url, String jcefPath, NexusApplication application) throws UnsupportedPlatformException, IOException, CefInitializationException, InterruptedException {
browserFocus = true; // Initially, browser has focus
File installDir = new File(jcefPath); // Directory where jCEF is installed
ShadeMeBaby.getLogger().debug("[WEBFRAME] Is jCef installed: "+!installDir.mkdirs()); // Log whether jCEF is installed
Expand All @@ -74,9 +77,13 @@ private void init(String url, String jcefPath) throws UnsupportedPlatformExcepti
builder.setAppHandler(new MavenCefAppHandlerAdapter() {
@Override @Deprecated
public void stateHasChanged(CefApp.CefAppState state) {
if (state == CefApp.CefAppState.TERMINATED) Platform.exit(); // Exit JavaFX application when CEF terminates
if (state == CefApp.CefAppState.TERMINATED) {
application.getModuleLoader().deactivateModules();
Platform.exit(); System.exit(0); // Exit JavaFX application when CEF terminates
}
}
});
setIconImage(ImageIO.read(Objects.requireNonNull(getClass().getResource("/logo.png"))).getScaledInstance(32, 32, Image.SCALE_SMOOTH));
builder.getCefSettings().cache_path = jcefPath+"/cache"; // Set cache path for CEF
builder.getCefSettings().log_severity = CefSettings.LogSeverity.LOGSEVERITY_DISABLE; // Disable logging
builder.getCefSettings().persist_session_cookies = true; // Persist session cookies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ public record ApplicationConfig(String[] args) {
private static String os = null;
private static Config updateConfig = null;

public static String[] arguments = null;

// Constructor for ApplicationConfig class
public ApplicationConfig(String[] args) {
this.args = args;
this.arguments = this.args;
// Iterating through the command-line arguments
for (String arg : args) {
// Checking if the argument starts with "--ui:"
Expand Down Expand Up @@ -69,6 +72,10 @@ else if(arg.startsWith("--test")) {
}
}

public static String[] getArguments() {
return arguments;
}

// Method to get the application path as a string
public static String getApplicationPath() {
if (applicationPath == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.net.URL;
import java.security.CodeSource;

import static com.zyneonstudios.application.main.ApplicationConfig.getApplicationPath;

public class NexusApplication{
public class NexusApplication {

/*
* Zyneon Application "main" object
Expand Down Expand Up @@ -105,5 +107,36 @@ private static boolean update() {
public void launch() {
moduleLoader.activateModules();
frame.setVisible(true);
if(Main.splash!=null) {
Main.splash.setVisible(false);
Main.splash = null;
System.gc();
}
}

public void restart() {
CodeSource codeSource = Main.class.getProtectionDomain().getCodeSource();
if (codeSource != null) {
URL jarUrl = codeSource.getLocation();
String jarPath = jarUrl.getPath();
if(jarPath.startsWith("/")) {
jarPath = jarPath.replaceFirst("/","");
}
StringBuilder args = new StringBuilder();
if(ApplicationConfig.getArguments()!=null) {
for(String arg : ApplicationConfig.getArguments()) {
args.append(arg).append(" ");
}
}
ProcessBuilder pb = new ProcessBuilder("java", "-jar", jarPath, args.toString());
try {
pb.start();
} catch (Exception e) {
logger.error("[APP] Couldn't restart application: "+e.getMessage());
}
getModuleLoader().deactivateModules();
System.exit(0);
}
System.exit(-1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void resolveBackendRequest(String request) {
resolveRequest(request);
}

@Deprecated
public void resolveRequest(String request) {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.zyneonstudios.application.modules;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.zyneonstudios.application.main.NexusApplication;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import java.util.jar.JarFile;

public class ModuleLoader {

Expand All @@ -33,8 +39,17 @@ public Set<String> getModuleIds() {

public ApplicationModule readModule(File moduleJar) {
try {
String mainPath;
try (JarFile jarFile = new JarFile(moduleJar.getAbsolutePath())) {
InputStream is = jarFile.getInputStream(jarFile.getJarEntry("module.json"));
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
mainPath = new Gson().fromJson(reader, JsonObject.class).get("main").getAsString();
} catch (Exception e) {
NexusApplication.getLogger().error("[MODULES] Couldn't read module "+moduleJar.getPath()+": "+e.getMessage());
return null;
}
URLClassLoader classLoader = new URLClassLoader(new URL[]{moduleJar.toURI().toURL()});
Class<?> module = classLoader.loadClass("live.nerotv.requestreader.RequestReader");
Class<?> module = classLoader.loadClass(mainPath);
Constructor<?> constructor = module.getConstructor(NexusApplication.class);
return (ApplicationModule) constructor.newInstance(application);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zyneonstudios.application.modules.test;

import com.zyneonstudios.application.frame.web.ApplicationFrame;
import com.zyneonstudios.application.main.NexusApplication;
import com.zyneonstudios.application.modules.ApplicationModule;
import com.zyneonstudios.application.modules.ModuleConnector;

Expand All @@ -17,6 +18,7 @@ public TestConnector(ApplicationModule module) {

@Override
public void resolveRequest(String request) {
NexusApplication.getLogger().log("[REQUEST-READER] "+request);
if(request.startsWith("init.")) {
frame.executeJavaScript("addMenuEntry('test-page-button','bx bx-test-tube','Test','test.page');");
request = request.replaceFirst("init.","");
Expand Down
Binary file modified application-main/src/main/resources/content.zip
Binary file not shown.
22 changes: 22 additions & 0 deletions application-ui/content/assets/application/css/app-library.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
overflow-y: auto;
}

.library #add-game-module, .library #game-content, .library #add-module-advanced, .library #game-module-advanced {
display: none;
}

.library #add-game-module.active, .library #add-module-advanced.active, .library #game-module-advanced.active, .library #game-content.active {
display: inherit;
}

.library .library-content {
position: relative !important;
padding: 1rem 1rem 1rem 0.5rem;
Expand All @@ -24,6 +32,20 @@
width: calc(100% - 2.25rem);
}

.library #game-module-title {
overflow: hidden;
white-space: nowrap;
}

.library #game-module-title #select-game-module {
color: var(--foreground2);
font-size: 1.05rem;
}

.library #game-module-title #select-game-module option {
background: var(--background);
}

.search-bar {
width: fit-content;
}
Expand Down
Loading

0 comments on commit 6f1323b

Please sign in to comment.