diff options
| author | WerWolv <werwolv98@gmail.com> | 2022-03-31 15:28:40 +0200 |
|---|---|---|
| committer | WerWolv <werwolv98@gmail.com> | 2022-03-31 15:28:40 +0200 |
| commit | 4c5ca4e567480d1edf39e5b448bd4f93c1c414c5 (patch) | |
| tree | 092981c08b66fb7116fb939f58a9ce0f3a09b65c /src/main.rs | |
| parent | a38e03094b49fdc44389d4a558e55108d6db827a (diff) | |
| download | decky-loader-4c5ca4e567480d1edf39e5b448bd4f93c1c414c5.tar.gz decky-loader-4c5ca4e567480d1edf39e5b448bd4f93c1c414c5.zip | |
sys: Added basic plugin loader
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 90d23a26..6d35cdf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use std::fmt::{Debug, Display, Formatter}; +use std::fs; use hyper::{Client, Uri}; use hyper::body::Buf; use serde::{ Serialize, Deserialize }; @@ -72,6 +73,30 @@ async fn get_web_content(url: Uri) -> TokioResult<Vec<WebContent>> { Ok(serde_json::from_str(data.as_str())?) } +fn load_plugins() -> String { + let paths = fs::read_dir("./plugins"); + if let Ok(paths) = paths { + + let mut result = String::new(); + + for entry in paths { + if let Ok(entry) = entry { + if let Ok(file_type) = entry.file_type() { + if file_type.is_file() { + if let Ok(content) = fs::read_to_string(entry.path()) { + result.push_str(format!("plugins.push(new {});", content).as_str()); + } + } + } + } + } + + result + } else { + String::from("") + } +} + #[tokio::main] async fn main() -> TokioResult<()> { let url = "http://127.0.0.1:8080/json".parse::<hyper::Uri>().unwrap(); @@ -98,7 +123,7 @@ async fn main() -> TokioResult<()> { id: 1, method: String::from("Runtime.evaluate"), params: DebuggerCommandParams { - expression: String::from(include_str!("plugin_page.js")), + expression: String::from(include_str!("plugin_page.js").replace("{{ PLUGINS }}", load_plugins().as_str())), userGesture: true } }; |
