modified: src/main.rs

modified:   src/www/portable.html
This commit is contained in:
Michael Wain 2025-03-12 16:06:36 +03:00
parent 72b345ac82
commit 12a85b7b2c
2 changed files with 15 additions and 21 deletions

View File

@ -10,7 +10,7 @@ use winit::platform::run_on_demand::EventLoopExtRunOnDemand;
use winit::window::{Window, WindowId}; use winit::window::{Window, WindowId};
use winit::event_loop::ActiveEventLoop; use winit::event_loop::ActiveEventLoop;
use wry::dpi::LogicalSize; use wry::dpi::LogicalSize;
use wry::http::Request; use wry::http::{Request, Response};
use wry::{WebView, WebViewBuilder, WebViewBuilderExtWindows}; use wry::{WebView, WebViewBuilder, WebViewBuilderExtWindows};
mod config; mod config;
@ -25,6 +25,7 @@ enum UIAction {
#[derive(Default)] #[derive(Default)]
struct App { struct App {
window: Option<Window>, window: Option<Window>,
webview: Option<WebView>
} }
impl ApplicationHandler for App { impl ApplicationHandler for App {
@ -32,8 +33,13 @@ impl ApplicationHandler for App {
let window = event_loop.create_window(Window::default_attributes().with_inner_size(LogicalSize::new(900, 600)).with_min_inner_size(LogicalSize::new(900, 600)).with_title("XCraft")).unwrap(); let window = event_loop.create_window(Window::default_attributes().with_inner_size(LogicalSize::new(900, 600)).with_min_inner_size(LogicalSize::new(900, 600)).with_title("XCraft")).unwrap();
let webview = WebViewBuilder::new() let webview = WebViewBuilder::new()
.with_html(include_str!("www/portable.html")) .with_html(include_str!("www/portable.html"))
.with_ipc_handler(|request| { .with_asynchronous_custom_protocol("xcraft".into(), move |wid, request, responder| {
SENDER.lock().unwrap().as_ref().unwrap().send(request); let uri = request.uri().to_string();
println!("GOTCHA");
let response = "yeeah!".as_bytes();
tokio::spawn(async move {
responder.respond(Response::new(response));
});
}) })
.build(&window) .build(&window)
.unwrap(); .unwrap();
@ -41,8 +47,7 @@ impl ApplicationHandler for App {
self.window = Some(window); self.window = Some(window);
self.webview = Some(webview);
self.launcher_start(Arc::new(webview));
} }
fn window_event(&mut self, event_loop: &ActiveEventLoop, _window_id: WindowId, event: WindowEvent) { fn window_event(&mut self, event_loop: &ActiveEventLoop, _window_id: WindowId, event: WindowEvent) {
@ -55,21 +60,6 @@ impl ApplicationHandler for App {
} }
} }
impl App {
fn launcher_start(&mut self, webview: Arc<WebView>) {
tokio::spawn(async move {
let (sender_gui, mut receiver_gui) = mpsc::unbounded_channel();
*SENDERGUI.lock().unwrap() = Some(sender_gui);
loop {
if let Some(action) = receiver_gui.recv().await {
println!("YUPPIE");
webview.evaluate_script("alert('done')");
}
}
});
}
}
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let (snd, mut receiver) = mpsc::unbounded_channel(); let (snd, mut receiver) = mpsc::unbounded_channel();

View File

@ -318,8 +318,12 @@
<script type="text/javascript"> <script type="text/javascript">
function runPortable() { async function runPortable() {
window.ipc.postMessage("run_portable"); window.ipc.postMessage("run_portable");
let response = await fetch('xcraft://data/fetch.json');
let data = await response.body;
alert(data);
} }
function installMinecraft() { function installMinecraft() {