Skip to content

Commit

Permalink
Hella lot
Browse files Browse the repository at this point in the history
  • Loading branch information
strawmelonjuice committed Aug 16, 2024
1 parent 0ae9b41 commit 24abacd
Show file tree
Hide file tree
Showing 12 changed files with 860 additions and 481 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,30 @@ path = "./source/Main/main.rs"
default = ["js_runtime"]
js_runtime = []


[profile.dev]
opt-level = 3
debug = true
strip = "none"
debug-assertions = true
overflow-checks = true
lto = false
panic = 'unwind'
incremental = true
codegen-units = 256

[profile.release]
opt-level = 3
lto = true
panic = 'abort'

[dependencies]
futures = "0.3.30"
actix-web = "4"
actix-files = "0.6"
serde = { version = "1.0.104", features = ["derive"] }
serde_yaml = "0.9.29"
colored = "2.0.4"
# colored = "2.0.4" // No longer needed, Cynthia uses its own color module
chrono = "0.4.38"
simplelog = "0.12.2"
indicatif = "0.17.8"
Expand Down
10 changes: 5 additions & 5 deletions source/Main/config/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use super::{CynthiaConf, CynthiaConfig};
use crate::jsrun;
use crate::jsrun::RunJSAndDeserializeResult;
use colored::Colorize;
use crate::tell::CynthiaColors;
use std::path::PathBuf;
use std::{fs, process};

Expand Down Expand Up @@ -161,7 +161,7 @@ pub(crate) fn load_config() -> CynthiaConf {
.to_string_lossy()
.replace("\\\\?\\", "")
)
.on_red(),
.color_error_red(),
"ERROR: ".bright_red()
);
process::exit(1);
Expand Down Expand Up @@ -208,7 +208,7 @@ pub(crate) fn load_config() -> CynthiaConf {
.replace("\\\\?\\", "")
)
.bright_red(),
format!("{}", e).on_red()
format!("{}", e).color_error_red()
);
process::exit(1);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ pub(crate) fn load_config() -> CynthiaConf {
.replace("\\\\?\\", "")
)
.bright_red(),
format!("{}", e).on_red()
format!("{}", e).color_error_red()
);
process::exit(1);
}
Expand Down Expand Up @@ -484,7 +484,7 @@ pub(crate) fn save_config(to_ex: &str, config: CynthiaConf) {

let config_serialised: String = match to {
"javascript" | "js" => {
format!("/*\n\tCynthiaConfig.js\n\n\n\tThis is the configuration file for Cynthia. It is written in Javascript, a scripting language.\n\tThis kind of CynthiaConfig is the most powerful and flexible,\n\tbut also the most complex. It is recommended for advanced users\n\twho want to take full control of Cynthia's behavior.\n\n\n\tMore info about this config can be found on <{cynthiaconfdoclink}>\n\n\n\tTo convert it to another config language, use the `cynthiaweb convert` command.\n*/\nlet myCynthiaConfig = {};\n\n// We must return the configuration object at the end of the file.\nreturn myCynthiaConfig;\n",
format!("/*\n\tCynthiaConfig.js\n\n\n\tThis is the configuration file for Cynthia. It is written in Javascript, a scripting language.\n\tThis kind of CynthiaConfig is the most powerful and flexible,\n\tbut also the most complex. It is recommended for advanced users\n\twho want to take full control of Cynthia's behavior.\n\n\n\tMore info about this config can be found on <{cynthiaconfdoclink}>\n\n\n\tTo convert it to another config language, use the `cynthiaweb convert` command.\n*/\nlet myCynthiaConfig = {};\n\n// We must return the configuration object at the end of the file.\nreturn myCynthiaConfig;\n",
regex::Regex::new(r#""([^"]*)":"#).unwrap().replace_all(&anyways_this_is_jsonc(config.hard_clone()), "\t$1:")
)
}
Expand Down
18 changes: 12 additions & 6 deletions source/Main/externalpluginservers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// This module will be a testing ground. V2 was unreliable and had a lot of issues, especially because it didn't keep the servers attached. It just let them run.
// This module will be a testing ground for a new system that will be more reliable and more secure.
// More specifically: The plugins will attach to js again, but inside of a controlled environment.

use crate::config::ConfigExternalJavascriptRuntime;

#[cfg(feature = "js_runtime")]
Expand Down Expand Up @@ -47,8 +46,8 @@ use actix_web::web::Data;
#[cfg(feature = "js_runtime")]
use interactive_process::InteractiveProcess;

use log::warn;
#[cfg(feature = "js_runtime")]
use log::warn;
use log::{debug, error, info};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -113,6 +112,8 @@ pub(crate) async fn main(
server_context_mutex: Arc<Mutex<ServerContext>>,
mut eps_r: Receiver<EPSRequest>,
) {
use crate::tell::CynthiaColors;

let config_clone = {
// We need to clone the config because we can't hold the lock while we're in the tokio runtime.
let server_context = server_context_mutex.lock().await;
Expand All @@ -124,8 +125,8 @@ pub(crate) async fn main(
let jsfile = include_bytes!("../../target/generated/js/plugins-runtime.js");
std::fs::write(jstempfolder.join("main.mjs"), jsfile).unwrap();
// now we can run the javascript
let node_runtime: &str = config_clone.runtimes.ext_js_rt.as_ref();
let mut r = Command::new(node_runtime);
let external_js_runtime_binary: &str = config_clone.runtimes.ext_js_rt.as_ref();
let mut r = Command::new(external_js_runtime_binary);
if config_clone.runtimes.ext_js_rt.validate().is_err() {
error!("Invalid node runtime path. Plugins will not run.");
loop {
Expand All @@ -151,10 +152,15 @@ pub(crate) async fn main(
}
};
let rt = tokio::runtime::Runtime::new().unwrap();
if node_runtime.contains("deno") {
if external_js_runtime_binary.contains("deno") {
r.arg("run");
r.arg("--allow-read");
}
if external_js_runtime_binary.contains("node") {
r.arg("--expose-gc");
} else if external_js_runtime_binary.contains("deno") {
r.arg("--v8-flags=--predictable-gc-schedule");
}
r.arg(jstempfolder.join("main.mjs"));
r.args([
"--config",
Expand Down Expand Up @@ -200,7 +206,7 @@ pub(crate) async fn main(
} else if o.starts_with("warn: ") {
warn!(
"[JsPluginRuntime]: {}",
o.split("warn: ").collect::<Vec<&str>>()[1]
format!("{}", o.split("warn: ").collect::<Vec<&str>>()[1]).orange()
);
} else if o.starts_with("log: ") {
config_clone.clone().tell(format!(
Expand Down
Loading

0 comments on commit 24abacd

Please sign in to comment.