diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b6df7b1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "livePreview.defaultPreviewPath": "/src/www/log_screen.html" +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 0667e7e..3a7078c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,6 +6,7 @@ version = 4 name = "CraftX" version = "0.1.0" dependencies = [ + "dirs", "tokio", "winit", "wry", @@ -483,6 +484,27 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dirs" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.59.0", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -555,7 +577,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1760,6 +1782,12 @@ version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cde51589ab56b20a6f686b2c68f7a0bd6add753d697abf720d63f8db3ab7b1ad" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "orbclient" version = "0.3.48" @@ -2199,6 +2227,17 @@ dependencies = [ "bitflags 2.9.0", ] +[[package]] +name = "redox_users" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" +dependencies = [ + "getrandom 0.2.15", + "libredox", + "thiserror 2.0.12", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -2224,7 +2263,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3157,7 +3196,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0b72704..1abd903 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2024" [dependencies] winit = "0.30.9" wry = "0.50.4" -tokio = { version = "1", features = ["full"] } \ No newline at end of file +tokio = { version = "1", features = ["full"] } +dirs = "6.0.0" diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..2ac7d77 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,30 @@ +use std::path::PathBuf; + +#[derive(Default)] +pub struct LauncherConfig { + is_portable: bool +} + +impl LauncherConfig { + + pub fn set_portable(&mut self, is_portable: bool) { + self.is_portable = is_portable; + } + + pub fn launcher_dir(&self) -> PathBuf { + match self.is_portable { + true => get_relative_launcher_dir(), + false => get_absolute_launcher_dir() + } + } +} + +fn get_relative_launcher_dir() -> PathBuf { + std::env::current_dir().unwrap() +} + +fn get_absolute_launcher_dir() -> PathBuf { + let mut p = dirs::data_dir().unwrap(); + p.push("xcraft"); + p +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b4c968d..eeff925 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,41 +1,94 @@ +use std::sync::{Arc, Mutex}; + +use config::LauncherConfig; +use tokio::runtime::Runtime; +use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use winit::application::ApplicationHandler; use winit::event_loop::{ControlFlow, EventLoop}; use winit::event::{Event, WindowEvent}; use winit::platform::run_on_demand::EventLoopExtRunOnDemand; use winit::window::{Window, WindowId}; use winit::event_loop::ActiveEventLoop; -use wry::WebViewBuilder; +use wry::dpi::LogicalSize; +use wry::http::Request; +use wry::{WebView, WebViewBuilder, WebViewBuilderExtWindows}; + +mod config; + +static SENDER: Mutex>>> = Mutex::new(None); +static SENDERGUI: Mutex>> = Mutex::new(None); + +enum UIAction { + DoSomething +} #[derive(Default)] struct App { window: Option, - webview: Option, } impl ApplicationHandler for App { fn resumed(&mut self, event_loop: &ActiveEventLoop) { - let window = event_loop.create_window(Window::default_attributes()).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() - .with_html(include_str!("www/sign_in.html")) + .with_html(include_str!("www/portable.html")) + .with_ipc_handler(|request| { + SENDER.lock().unwrap().as_ref().unwrap().send(request); + }) .build(&window) .unwrap(); + + 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) { match event { WindowEvent::CloseRequested => { event_loop.exit(); - } + }, _ => {} } } } -fn main() { +impl App { + fn launcher_start(&mut self, webview: Arc) { + 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] +async fn main() { + let (snd, mut receiver) = mpsc::unbounded_channel(); + + *SENDER.lock().unwrap() = Some(snd); + let event_loop = EventLoop::new().unwrap(); let mut app = App::default(); + + let rt = Runtime::new().unwrap(); + + rt.spawn(async move { + loop { + if let Some(request) = receiver.recv().await { + println!("Request: {}", request.body()); + SENDERGUI.lock().unwrap().as_ref().unwrap().send(UIAction::DoSomething); + } + } + }); + event_loop.run_app(&mut app).unwrap(); } \ No newline at end of file diff --git a/src/www/html b/src/www/html index c1f0ada..48bad76 100644 --- a/src/www/html +++ b/src/www/html @@ -3,73 +3,34 @@ - Minecraft Launcher + Launcher Settings
-

Minecraft Launcher

+

Launcher Settings

- - - - - - - - -
or
- - - - - -
- -
-

Minecraft Launcher v1.0

+ +
diff --git a/src/www/log_screen b/src/www/log_screen.html similarity index 100% rename from src/www/log_screen rename to src/www/log_screen.html diff --git a/src/www/logged_in b/src/www/logged_in.html similarity index 100% rename from src/www/logged_in rename to src/www/logged_in.html diff --git a/src/www/notification.html b/src/www/notification.html new file mode 100644 index 0000000..99ebe0c --- /dev/null +++ b/src/www/notification.html @@ -0,0 +1,42 @@ + + \ No newline at end of file diff --git a/src/www/portable.html b/src/www/portable.html new file mode 100644 index 0000000..527b92b --- /dev/null +++ b/src/www/portable.html @@ -0,0 +1,345 @@ + + + + + + + + + + + + +
+
+

Welcome to Minecraft Launcher

+

Choose how you want to set up Minecraft.

+ + + +

No installation required. Saves everything in a local folder.

+ + + +

Installs Minecraft on your system for long-term use.

+
+ + + + + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/src/www/profile_customization b/src/www/profile_customization.html similarity index 100% rename from src/www/profile_customization rename to src/www/profile_customization.html diff --git a/src/www/public_release b/src/www/public_release.html similarity index 100% rename from src/www/public_release rename to src/www/public_release.html diff --git a/src/www/sign_in.html b/src/www/sign_in.html index 0f7cd15..f57bf5e 100644 --- a/src/www/sign_in.html +++ b/src/www/sign_in.html @@ -4,6 +4,7 @@ Minecraft Launcher - Login + @@ -78,15 +79,15 @@
- - - - + + + +
-
-

๐Ÿš€ Launcher Settings

+
+

Launcher Settings

-