summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerWolv <werwolv98@gmail.com>2022-03-31 15:28:40 +0200
committerWerWolv <werwolv98@gmail.com>2022-03-31 15:28:40 +0200
commit4c5ca4e567480d1edf39e5b448bd4f93c1c414c5 (patch)
tree092981c08b66fb7116fb939f58a9ce0f3a09b65c
parenta38e03094b49fdc44389d4a558e55108d6db827a (diff)
downloaddecky-loader-4c5ca4e567480d1edf39e5b448bd4f93c1c414c5.tar.gz
decky-loader-4c5ca4e567480d1edf39e5b448bd4f93c1c414c5.zip
sys: Added basic plugin loader
-rw-r--r--.idea/.gitignore8
-rw-r--r--.idea/SteamOS-Plugin-Manager.iml11
-rw-r--r--.idea/modules.xml8
-rw-r--r--.idea/vcs.xml6
-rw-r--r--src/main.rs27
-rw-r--r--src/plugin_page.js62
6 files changed, 118 insertions, 4 deletions
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..13566b81
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/SteamOS-Plugin-Manager.iml b/.idea/SteamOS-Plugin-Manager.iml
new file mode 100644
index 00000000..c254557e
--- /dev/null
+++ b/.idea/SteamOS-Plugin-Manager.iml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="CPP_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module> \ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..8875d58a
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea/SteamOS-Plugin-Manager.iml" filepath="$PROJECT_DIR$/.idea/SteamOS-Plugin-Manager.iml" />
+ </modules>
+ </component>
+</project> \ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..94a25f7f
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ </component>
+</project> \ No newline at end of file
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
}
};
diff --git a/src/plugin_page.js b/src/plugin_page.js
index 50dc419c..537f53a3 100644
--- a/src/plugin_page.js
+++ b/src/plugin_page.js
@@ -1,4 +1,8 @@
(function () {
+ let plugins = [];
+
+ {{ PLUGINS }}
+
const PLUGIN_ICON = `
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plugin" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M1 8a7 7 0 1 1 2.898 5.673c-.167-.121-.216-.406-.002-.62l1.8-1.8a3.5 3.5 0 0 0
@@ -8,13 +12,65 @@
</svg>
`;
+ function createTitle(text) {
+ return `<div class="quickaccessmenu_Title_34nl5">${text}</div>`;
+ }
+
+ function createTabGroupPanel(content) {
+ return `<div class="quickaccessmenu_TabGroupPanel_1QO7b Panel Focusable">${content}</div>`;
+ }
+
+ function createPanelSelection(content) {
+ return `<div class="quickaccesscontrols_PanelSection_Ob5uo">${content}</div>`;
+ }
+
+ function createPanelSelectionRow(content) {
+ return `<div class="quickaccesscontrols_PanelSectionRow_26R5w">${content}</div>`;
+ }
+
+ function createButton(text, id) {
+ return `
+ <div class="basicdialog_Field_ugL9c basicdialog_WithChildrenBelow_1RjOd basicdialog_InlineWrapShiftsChildrenBelow_3a6QZ basicdialog_ExtraPaddingOnChildrenBelow_2-owv basicdialog_StandardPadding_1HrfN basicdialog_HighlightOnFocus_1xh2W Panel Focusable" style="--indent-level:0;">
+ <div class="basicdialog_FieldChildren_279n8">
+ <button id="${id}" type="button" tabindex="0" class="DialogButton _DialogLayout Secondary basicdialog_Button_1Ievp Focusable">${text}</button>
+ </div>
+ </div>
+ `;
+ }
+
+ function createPluginList() {
+ let pages = document.getElementsByClassName("quickaccessmenu_AllTabContents_2yKG4 quickaccessmenu_Down_3rR0o")[0];
+ let pluginPage = pages.children[pages.children.length - 1];
+
+ pluginPage.innerHTML = createTitle("Plugins");
+
+ let buttons = "";
+ for (let i = 0; i < plugins.length; i++) {
+ buttons += createPanelSelectionRow(createButton(plugins[i].getName(), "plugin_btn_" + i))
+ }
+
+ pluginPage.innerHTML += createTabGroupPanel(createPanelSelection(buttons));
+
+ for (let i = 0; i < plugins.length; i++) {
+ document.getElementById("plugin_btn_" + i).onclick = (function(plugin, pluginPage) {
+ return function() {
+ pluginPage.innerHTML = createButton("Back", "plugin_back") + createTitle(plugin.getName()) + createTabGroupPanel(plugin.getPageContent());
+ plugin.runCode();
+
+ document.getElementById("plugin_back").onclick = (e) => {
+ createPluginList();
+ };
+ };
+ }(plugins[i], pluginPage))
+ }
+
+ }
+
function inject() {
let tabs = document.getElementsByClassName("quickaccessmenu_TabContentColumn_2z5NL Panel Focusable")[0];
tabs.children[tabs.children.length - 1].innerHTML = PLUGIN_ICON;
- let pages = document.getElementsByClassName("quickaccessmenu_AllTabContents_2yKG4 quickaccessmenu_Down_3rR0o")[0];
- let pluginPage = pages.children[pages.children.length - 1];
- pluginPage.innerHTML = "Hello from Rust!";
+ createPluginList();
}
let injector = setInterval(function () {