restore desktop/liveview minification
This commit is contained in:
1 parent
2404bfeeb3
commit
1d664c616e
6 files changed
+43
-44
No files matched your search
+21
-12
@@ -16,7 +16,7 @@ fn main() {
|
|||||||
let target_id = find_real_id(target);
|
let target_id = find_real_id(target);
|
||||||
if (target_id !== null) {
|
if (target_id !== null) {
|
||||||
const send = (event_name) => {
|
const send = (event_name) => {
|
||||||
const message = serializeIpcMessage("file_diolog", { accept: target.getAttribute("accept"), directory: target.getAttribute("webkitdirectory") === "true", multiple: target.hasAttribute("multiple"), target: parseInt(target_id), bubbles: event_bubbles(event_name), event: event_name });
|
const message = window.interpreter.serializeIpcMessage("file_diolog", { accept: target.getAttribute("accept"), directory: target.getAttribute("webkitdirectory") === "true", multiple: target.hasAttribute("multiple"), target: parseInt(target_id), bubbles: event_bubbles(event_name), event: event_name });
|
||||||
window.ipc.postMessage(message);
|
window.ipc.postMessage(message);
|
||||||
};
|
};
|
||||||
send("change&input");
|
send("change&input");
|
||||||
@@ -26,9 +26,21 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
|
let polling_request = r#"// Poll for requests
|
||||||
|
window.interpreter.wait_for_request = () => {
|
||||||
|
fetch(new Request("dioxus://index.html/edits"))
|
||||||
|
.then(response => {
|
||||||
|
response.arrayBuffer()
|
||||||
|
.then(bytes => {
|
||||||
|
run_from_bytes(bytes);
|
||||||
|
window.interpreter.wait_for_request();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}"#;
|
||||||
let mut interpreter = SLEDGEHAMMER_JS
|
let mut interpreter = SLEDGEHAMMER_JS
|
||||||
.replace("/*POST_HANDLE_EDITS*/", prevent_file_upload)
|
.replace("/*POST_HANDLE_EDITS*/", prevent_file_upload)
|
||||||
.replace("export", "");
|
.replace("export", "")
|
||||||
|
+ polling_request;
|
||||||
while let Some(import_start) = interpreter.find("import") {
|
while let Some(import_start) = interpreter.find("import") {
|
||||||
let import_end = interpreter[import_start..]
|
let import_end = interpreter[import_start..]
|
||||||
.find(|c| c == ';' || c == '\n')
|
.find(|c| c == ';' || c == '\n')
|
||||||
@@ -38,15 +50,12 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let js = format!("{interpreter}\nconst config = new InterpreterConfig(false);");
|
let js = format!("{interpreter}\nconst config = new InterpreterConfig(false);");
|
||||||
let mut file = std::fs::File::create("src/minified.js").unwrap();
|
|
||||||
file.write_all(js.as_bytes()).unwrap();
|
|
||||||
|
|
||||||
// TODO: Enable minification on desktop
|
use minify_js::*;
|
||||||
// use minify_js::*;
|
let session = Session::new();
|
||||||
// let session = Session::new();
|
let mut out = Vec::new();
|
||||||
// let mut out = Vec::new();
|
minify(&session, TopLevelMode::Module, js.as_bytes(), &mut out).unwrap();
|
||||||
// minify(&session, TopLevelMode::Module, js.as_bytes(), &mut out).unwrap();
|
let minified = String::from_utf8(out).unwrap();
|
||||||
// let minified = String::from_utf8(out).unwrap();
|
let mut file = std::fs::File::create("src/minified.js").unwrap();
|
||||||
// let mut file = std::fs::File::create("src/minified.js").unwrap();
|
file.write_all(minified.as_bytes()).unwrap();
|
||||||
// file.write_all(minified.as_bytes()).unwrap();
|
|
||||||
}
|
}
|
||||||
@@ -17,27 +17,15 @@ fn module_loader(root_name: &str) -> String {
|
|||||||
r#"
|
r#"
|
||||||
<script type="module">
|
<script type="module">
|
||||||
{MINIFIED}
|
{MINIFIED}
|
||||||
|
|
||||||
function wait_for_request() {{
|
|
||||||
fetch(new Request("dioxus://index.html/edits"))
|
|
||||||
.then(response => {{
|
|
||||||
response.arrayBuffer()
|
|
||||||
.then(bytes => {{
|
|
||||||
run_from_bytes(bytes);
|
|
||||||
wait_for_request();
|
|
||||||
}});
|
|
||||||
}})
|
|
||||||
}}
|
|
||||||
|
|
||||||
// Wait for the page to load
|
// Wait for the page to load
|
||||||
window.onload = function() {{
|
window.onload = function() {{
|
||||||
let rootname = "{root_name}";
|
let rootname = "{root_name}";
|
||||||
let root_element = window.document.getElementById(rootname);
|
let root_element = window.document.getElementById(rootname);
|
||||||
if (root_element != null) {{
|
if (root_element != null) {{
|
||||||
initialize(root_element);
|
window.interpreter.initialize(root_element);
|
||||||
window.ipc.postMessage(serializeIpcMessage("initialize"));
|
window.ipc.postMessage(window.interpreter.serializeIpcMessage("initialize"));
|
||||||
}}
|
}}
|
||||||
wait_for_request();
|
window.interpreter.wait_for_request();
|
||||||
}}
|
}}
|
||||||
</script>
|
</script>
|
||||||
"#
|
"#
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function handler(event, name, bubbles, config) {
|
|||||||
const href = a_element.getAttribute("href");
|
const href = a_element.getAttribute("href");
|
||||||
if (href !== "" && href !== null && href !== undefined) {
|
if (href !== "" && href !== null && href !== undefined) {
|
||||||
window.ipc.postMessage(
|
window.ipc.postMessage(
|
||||||
serializeIpcMessage("browser_open", { href })
|
window.interpreter.serializeIpcMessage("browser_open", { href })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ function handler(event, name, bubbles, config) {
|
|||||||
if (realId === null) {
|
if (realId === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const message = serializeIpcMessage("user_event", {
|
const message = window.interpreter.serializeIpcMessage("user_event", {
|
||||||
name: name,
|
name: name,
|
||||||
element: parseInt(realId),
|
element: parseInt(realId),
|
||||||
data: contents,
|
data: contents,
|
||||||
@@ -132,7 +132,7 @@ function handler(event, name, bubbles, config) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.ipc.postMessage(
|
window.ipc.postMessage(
|
||||||
serializeIpcMessage("user_event", {
|
window.interpreter.serializeIpcMessage("user_event", {
|
||||||
name: name,
|
name: name,
|
||||||
element: parseInt(realId),
|
element: parseInt(realId),
|
||||||
data: contents,
|
data: contents,
|
||||||
@@ -231,11 +231,7 @@ let stack = [];
|
|||||||
let root;
|
let root;
|
||||||
const templates = {};
|
const templates = {};
|
||||||
let node, els, end, k;
|
let node, els, end, k;
|
||||||
function initialize(root) {
|
|
||||||
nodes = [root];
|
|
||||||
stack = [root];
|
|
||||||
listeners.root = root;
|
|
||||||
}
|
|
||||||
function AppendChildren(id, many) {
|
function AppendChildren(id, many) {
|
||||||
root = nodes[id];
|
root = nodes[id];
|
||||||
els = stack.splice(stack.length - many);
|
els = stack.splice(stack.length - many);
|
||||||
@@ -246,6 +242,12 @@ function AppendChildren(id, many) {
|
|||||||
|
|
||||||
window.interpreter = {}
|
window.interpreter = {}
|
||||||
|
|
||||||
|
window.interpreter.initialize = function (root) {
|
||||||
|
nodes = [root];
|
||||||
|
stack = [root];
|
||||||
|
listeners.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
window.interpreter.getClientRect = function (id) {
|
window.interpreter.getClientRect = function (id) {
|
||||||
const node = nodes[id];
|
const node = nodes[id];
|
||||||
if (!node) {
|
if (!node) {
|
||||||
@@ -560,7 +562,7 @@ function serialize_event(event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function serializeIpcMessage(method, params = {}) {
|
window.interpreter.serializeIpcMessage = function (method, params = {}) {
|
||||||
return JSON.stringify({ method, params });
|
return JSON.stringify({ method, params });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ pub mod binary_protocol {
|
|||||||
// if this is a mounted listener, we send the event immediately
|
// if this is a mounted listener, we send the event immediately
|
||||||
if (event_name === "mounted") {
|
if (event_name === "mounted") {
|
||||||
window.ipc.postMessage(
|
window.ipc.postMessage(
|
||||||
serializeIpcMessage("user_event", {
|
window.interpreter.serializeIpcMessage("user_event", {
|
||||||
name: event_name,
|
name: event_name,
|
||||||
element: id,
|
element: id,
|
||||||
data: null,
|
data: null,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fn main() {
|
|||||||
if (realId === null) {
|
if (realId === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const message = serializeIpcMessage("user_event", {
|
const message = window.interpreter.serializeIpcMessage("user_event", {
|
||||||
name: name,
|
name: name,
|
||||||
element: parseInt(realId),
|
element: parseInt(realId),
|
||||||
data: contents,
|
data: contents,
|
||||||
@@ -56,9 +56,9 @@ fn main() {
|
|||||||
let js = format!("{interpreter}\n{main_js}");
|
let js = format!("{interpreter}\n{main_js}");
|
||||||
|
|
||||||
let session = Session::new();
|
let session = Session::new();
|
||||||
// let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
// minify(&session, TopLevelMode::Module, js.as_bytes(), &mut out).unwrap();
|
minify(&session, TopLevelMode::Module, js.as_bytes(), &mut out).unwrap();
|
||||||
// let minified = String::from_utf8(out).unwrap();
|
let minified = String::from_utf8(out).unwrap();
|
||||||
let mut file = std::fs::File::create("src/minified.js").unwrap();
|
let mut file = std::fs::File::create("src/minified.js").unwrap();
|
||||||
file.write_all(js.as_bytes()).unwrap();
|
file.write_all(minified.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ function main() {
|
|||||||
|
|
||||||
class IPC {
|
class IPC {
|
||||||
constructor(root) {
|
constructor(root) {
|
||||||
initialize(root);
|
window.interpreter.initialize(root);
|
||||||
const ws = new WebSocket(WS_ADDR);
|
const ws = new WebSocket(WS_ADDR);
|
||||||
ws.binaryType = "arraybuffer";
|
ws.binaryType = "arraybuffer";
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ class IPC {
|
|||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
// we ping every 30 seconds to keep the websocket alive
|
// we ping every 30 seconds to keep the websocket alive
|
||||||
setInterval(ping, 30000);
|
setInterval(ping, 30000);
|
||||||
ws.send(serializeIpcMessage("initialize"));
|
ws.send(window.interpreter.serializeIpcMessage("initialize"));
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = (err) => {
|
ws.onerror = (err) => {
|
||||||
|
|||||||
Reference in new issue
Block a user