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

Commit

Permalink
Remove code notes
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldieeins committed Jun 26, 2024
1 parent cf56a80 commit 10e9efa
Show file tree
Hide file tree
Showing 20 changed files with 723 additions and 283 deletions.
2 changes: 1 addition & 1 deletion application-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>application-main</artifactId>
<version>2024.7-beta.5</version>
<version>2024.7-beta.6</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
10 changes: 0 additions & 10 deletions application-main/src/main/java/com/zyneonstudios/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@ 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) {
// Creating new splash icon
splash = new ZyneonSplash();
// Showing splash icon
splash.setVisible(true);
// Creating application config
new ApplicationConfig(args);
// Launch new application object
new NexusApplication().launch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,62 @@
import com.zyneonstudios.application.main.NexusApplication;
import com.zyneonstudios.application.modules.ApplicationModule;
import com.zyneonstudios.application.modules.search.ModuleSearch;
import live.nerotv.shademebaby.file.OnlineConfig;

import java.awt.*;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

public class FrameConnector {

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

// Instance variable to hold the ApplicationFrame object
private final ApplicationFrame frame;
private ModuleSearch moduleSearch = new ModuleSearch("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex/index.json");
private final NexusApplication application;

// Constructor for FrameConnector class
public FrameConnector(ApplicationFrame frame) {
// Initializing the frame object
public FrameConnector(ApplicationFrame frame,NexusApplication application) {
this.application = application;
this.frame = frame;
}

// Method to resolve requests received by the FrameConnector
public void resolveRequest(String request) {
//If test or debug is enabled, print out every request
if(ApplicationConfig.test) {
NexusApplication.getLogger().error("[CONNECTOR] (Request-Reader) resolving "+request+"...");
} else {
NexusApplication.getLogger().debug("[CONNECTOR] (Request-Reader) resolving "+request+"...");
}

// Checking the type of request
if(request.startsWith("sync.")) {
// If the request starts with "sync.", call the sync method
sync(request.replace("sync.", ""));
// Log successful resolution
NexusApplication.getLogger().debug("[CONNECTOR] successfully resolved " + request);
} else if(request.startsWith("open.")) {
open(request.replaceFirst("open.",""));
} else if(request.startsWith("init.")) {
// If the request starts with "init.", call the init method
init(request.replace("init.", ""));
// Log successful resolution
NexusApplication.getLogger().debug("[CONNECTOR] successfully resolved " + request);
}
for(ApplicationModule module:frame.getApplication().getModuleLoader().getApplicationModules()) {
for(ApplicationModule module:NexusApplication.getModuleLoader().getApplicationModules()) {
module.getConnector().resolveFrameRequest(request);
}
}

private void open(String request) {
if(request.startsWith("url.")) {
request = request.replaceFirst("url.", "");
if(request.startsWith("decode.")) {
request = URLDecoder.decode(request.replaceFirst("decode.", ""), StandardCharsets.UTF_8);
}
if(Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(request));
} catch (Exception ignore) {}
}
}
}

private void init(String request) {
frame.executeJavaScript("syncDesktop();");
if(request.equals("discover")) {
Expand All @@ -65,16 +73,11 @@ private void init(String request) {
}
}

// Method to synchronize settings and updates
private void sync(String request) {
// Execute JavaScript function to sync with desktop
// Check the type of synchronization request
if(request.startsWith("title.")) {
// If the request starts with "title.", update the titlebar
String[] request_ = request.replace("title.","").split("-.-",2);
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;
Expand Down Expand Up @@ -104,33 +107,24 @@ private void sync(String request) {
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")) {
NexusApplication.stop();
} else if(request.equals("refresh")) {
frame.getBrowser().loadURL(ApplicationConfig.urlBase+ApplicationConfig.language+"/"+ApplicationConfig.startPage);
} else if(request.equals("restart")) {
frame.getApplication().restart();
application.restart();
} else if(request.startsWith("settings.")) {
// If the request starts with "settings.", synchronize settings
syncSettings(request.replaceFirst("settings.",""));
} else if(request.startsWith("autoUpdates.")) {
// If the request starts with "autoUpdates.", synchronize auto-update settings
request = request.replace("autoUpdates.","");

boolean update = request.equals("on");
// Update the auto-update setting
ApplicationConfig.getUpdateSettings().set("updater.settings.autoUpdate",update);

// Execute JavaScript to update the UI accordingly
frame.executeJavaScript("document.getElementById('updater-settings-enable-updates').checked = "+update+";");
} else if(request.startsWith("discover.")) {
syncDiscover(request.replaceFirst("discover.",""));
} else if(request.startsWith("updateChannel.")) {
// If the request starts with "updateChannel.", synchronize update channel settings
request = request.replace("updateChannel.","");
// Update the update channel setting
ApplicationConfig.getUpdateSettings().set("updater.settings.updateChannel",request);
} else if(request.startsWith("startPage.")) {
request = request.replaceFirst("startPage.","");
Expand All @@ -143,18 +137,15 @@ private void sync(String request) {
}
}

// Method to synchronize general settings
private void syncSettings(String request) {
if(request.equals("general")) {
String channel = "experimental"; boolean autoUpdate = false;
// Retrieve auto-update and update channel settings
if(ApplicationConfig.getUpdateSettings().getBoolean("updater.settings.autoUpdate")!=null) {
autoUpdate = ApplicationConfig.getUpdateSettings().getBool("updater.settings.autoUpdate");
}
if(ApplicationConfig.getUpdateSettings().getString("updater.settings.updateChannel")!=null) {
channel = ApplicationConfig.getUpdateSettings().getString("updater.settings.updateChannel");
}
// Execute JavaScript to update the UI with retrieved settings
frame.executeJavaScript("updates = "+autoUpdate+"; document.getElementById('updater-settings-enable-updates').checked = updates; document.getElementById('updater-settings-update-channel').value = \""+channel+"\"; document.getElementById('updater-settings').style.display = 'inherit'; document.getElementById('general-settings-start-page').value = '"+ApplicationConfig.startPage+"'; document.getElementById('updater-settings').style.display = 'inherit';");
} else if(request.equals("about")) {
frame.executeJavaScript("document.getElementById('settings-global-application-version').innerText = \""+ApplicationConfig.getApplicationVersion()+"\"");
Expand All @@ -164,9 +155,6 @@ private void syncSettings(String request) {
private void syncDiscover(String request) {
if(request.startsWith("search.")) {
if(request.replace("search.","").equals("modules")) {
if(moduleSearch==null) {
moduleSearch = new ModuleSearch("https://raw.githubusercontent.com/zyneonstudios/nexus-nex/main/zyndex/index.json");
}
if(moduleSearch.getCachedResults()==null) {
moduleSearch.search("");
}
Expand All @@ -178,19 +166,92 @@ private void syncDiscover(String request) {
for(HashMap<String,String> result : moduleSearch.getCachedResults()) {
String tags = "Tags: "+result.get("meta.tags").replace("[\"","").replace("\"]","").replace("\"","").replace(",",", ");
String meta = result.get("meta.id")+" | v"+result.get("info.version")+" | Hidden: "+result.get("meta.isHidden")+"<br>"+tags;
String actions = "<a onclick=\\\"connector('sync.discover.details.module.nexus-minecraft-module');\\\"><i class='bx bx-spreadsheet'></i> More</a> ";
String location = URLEncoder.encode(result.get("meta.location"),StandardCharsets.UTF_8);
String actions = "<a onclick=\\\"connector('sync.discover.details.module."+location+"');\\\"><i class='bx bx-spreadsheet'></i> More</a> ";
if(NexusApplication.getModuleLoader().getModuleIds().contains(result.get("meta.id"))) {
actions = "v"+NexusApplication.getModuleLoader().getModules().get(result.get("meta.id")).getVersion()+" <a onclick=\\\"connector('sync.discover.details.module.nexus-minecraft-module');\\\"><i class='bx bx-spreadsheet'></i> More</a> <a style=\\\"background: #473e5c !important; color: white!important; cursor: not-allowed !important; box-shadow: 0 0 0.2rem var(--shadow3) !important;\\\"><i class='bx bx-check'></i> Installed</a>";
actions = "v"+NexusApplication.getModuleLoader().getModules().get(result.get("meta.id")).getVersion()+" <a onclick=\\\"connector('sync.discover.details.module."+location+"');\\\"><i class='bx bx-spreadsheet'></i> More</a> <a style=\\\"background: #473e5c !important; color: white!important; cursor: not-allowed !important; box-shadow: 0 0 0.2rem var(--shadow3) !important;\\\"><i class='bx bx-check'></i> Installed</a>";
} else {
actions = actions+"<a style=\\\"background: #5632a8; color: white;\\\" onclick=\\\"connector('sync.discover.install.module.nexus-minecraft-module');\\\"><i class='bx bx-download'></i> Install</a>";
}
String command = "addResult(\""+result.get("meta.id")+"\",\""+result.get("resources.thumbnail")+"\",\""+result.get("info.name")+"\",\""+result.get("info.author")+"\",\""+result.get("info.description")+"\",\""+meta+"\",\""+actions+"\");";
String command = "addResult(\""+result.get("meta.id")+"\",\""+result.get("resources.thumbnail")+"\",\""+result.get("info.name")+"\",\""+result.get("info.authors")+"\",\""+formatForDetails(result.get("info.summary"))+"\",\""+meta+"\",\""+actions+"\",\""+location+"\");";
frame.executeJavaScript(command);
}
}
} else if(request.startsWith("details.")) {
request = request.replaceFirst("details.","");
frame.executeJavaScript("enableOverlay(\"https://www.zyneonstudios.com\");");
if(request.startsWith("module.")) {
OnlineConfig module = new OnlineConfig(URLDecoder.decode(request.replaceFirst("module.",""),StandardCharsets.UTF_8));
initDetails(module.getString("module.info.name"),module.getString("module.meta.id"),"Application module",module.getString("module.info.version"),module.getString("module.info.summary"),module.getString("module.info.authors"),module.getBool("module.meta.isHidden"),module.get("module.meta.tags").toString(),module.getString("module.meta.description"),module.get("module.meta.changelogs").toString(),module.get("module.meta.versions").toString(),module.getString("module.style.info"),module.getString("module.style.card"),module.getString("module.resources.background"),module.getString("module.resources.icon"),module.getString("module.resources.logo"));
}
}
}

private void initDetails(String name, String id, String type, String version, String summary, String authors, boolean isHidden, String tags, String description, String changelog, String versions, String customInfoHTML, String customInfoCardHTML, String background, String icon, String logo) {
String url = ApplicationConfig.urlBase+ApplicationConfig.language+"/sub-details.html";
if(name!=null) {
url = url+"?name="+formatForDetails(name);
}
if(id!=null) {
url = url+"&id="+formatForDetails(id);
}
if(type!=null) {
url = url+"&type="+formatForDetails(type);
}
if(version!=null) {
url = url+"&version="+formatForDetails(version);
}
if(summary!=null) {
url = url+"&summary="+formatForDetails(summary);
}
if(authors!=null) {
url = url+"&authors="+formatForDetails(authors);
}
url = url+"&hidden="+isHidden;
if(tags!=null) {
url = url+"&tags="+formatForDetails(tags.replace("[","").replace("]",""));
}
if(description!=null) {
url = url+"&description="+formatForDetails(description);
} else {
if(summary!=null) {
url = url+"&description="+formatForDetails(summary);
}
}
if(changelog!=null) {
url = url+"&changelog="+formatForDetails(changelog.replace("[","").replace("]","").replace(", ",","));
}
if(versions!=null) {
url = url+"&versions="+formatForDetails(versions.replace("[","").replace("]","").replace(", ",","));
}
if(customInfoHTML!=null) {
url = url+"&c="+formatForDetails(customInfoHTML);
}
if(customInfoCardHTML!=null) {
url = url+"&cc="+formatForDetails(customInfoCardHTML);
}
if(background!=null) {
String b = "&background="+formatForDetails(background);
url = url+b;
System.out.println(b);
}
if(icon!=null) {
url = url+"&icon="+formatForDetails(icon);
}
if(logo!=null) {
url = url+"&logo="+formatForDetails(logo);
}
frame.executeJavaScript("enableOverlay(\""+url+"\");");
}

private String formatForDetails(String input) {
if(input!=null) {
if(!input.isBlank()&&!input.isEmpty()) {
input = input.replace("\"","''");
input = input.replace("\n","<br>").replace("\\n","<br>").replace("+","%plus%");
return URLEncoder.encode(input, StandardCharsets.UTF_8).replace("+", "%20").replace("%plus%", "+");
}
return "";
}
return null;
}
}
Loading

0 comments on commit 10e9efa

Please sign in to comment.