sys: Added basic plugin loader

This commit is contained in:
WerWolv
2022-03-31 15:28:40 +02:00
parent a38e03094b
commit 4c5ca4e567
6 changed files with 118 additions and 4 deletions
+8
View File
@@ -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
+11
View File
@@ -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>
+8
View File
@@ -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>
Generated
+6
View File
@@ -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>
+26 -1
View File
@@ -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
}
};
+59 -3
View File
@@ -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 () {