modified: Cargo.lock
modified: Cargo.toml modified: src/config.rs modified: src/launcher.rs modified: src/main.rs modified: src/www/portable.html modified: .gitignore
This commit is contained in:
parent
46e19a87f8
commit
c4430fb848
44
Cargo.lock
generated
44
Cargo.lock
generated
@ -11,6 +11,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"toml",
|
||||||
"winit",
|
"winit",
|
||||||
"wry",
|
"wry",
|
||||||
]
|
]
|
||||||
@ -924,7 +925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc"
|
checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.4.1",
|
"heck 0.4.1",
|
||||||
"proc-macro-crate 2.0.2",
|
"proc-macro-crate 2.0.0",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1495,7 +1496,7 @@ version = "0.7.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
|
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate 2.0.2",
|
"proc-macro-crate 1.3.1",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.100",
|
"syn 2.0.100",
|
||||||
@ -2072,11 +2073,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "2.0.2"
|
version = "2.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24"
|
checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"toml_datetime",
|
|
||||||
"toml_edit 0.20.2",
|
"toml_edit 0.20.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2811,21 +2811,21 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.8.2"
|
version = "0.8.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d"
|
checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_spanned",
|
"serde_spanned",
|
||||||
"toml_datetime",
|
"toml_datetime",
|
||||||
"toml_edit 0.20.2",
|
"toml_edit 0.22.24",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.6.3"
|
version = "0.6.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
|
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@ -2838,7 +2838,7 @@ checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 2.8.0",
|
"indexmap 2.8.0",
|
||||||
"toml_datetime",
|
"toml_datetime",
|
||||||
"winnow",
|
"winnow 0.5.40",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2846,12 +2846,23 @@ name = "toml_edit"
|
|||||||
version = "0.20.2"
|
version = "0.20.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338"
|
checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap 2.8.0",
|
||||||
|
"toml_datetime",
|
||||||
|
"winnow 0.5.40",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.22.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap 2.8.0",
|
"indexmap 2.8.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_spanned",
|
"serde_spanned",
|
||||||
"toml_datetime",
|
"toml_datetime",
|
||||||
"winnow",
|
"winnow 0.7.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3653,6 +3664,15 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winnow"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wit-bindgen-rt"
|
name = "wit-bindgen-rt"
|
||||||
version = "0.33.0"
|
version = "0.33.0"
|
||||||
|
@ -10,4 +10,5 @@ tokio = { version = "1", features = ["full"] }
|
|||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
rand = "0.9.0"
|
rand = "0.9.0"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
toml = "0.8.20"
|
@ -1,8 +1,12 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Default)]
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
pub struct LauncherConfig {
|
pub struct LauncherConfig {
|
||||||
is_portable: bool
|
is_portable: bool,
|
||||||
|
pub user_name: String,
|
||||||
|
pub user_secret: String
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LauncherConfig {
|
impl LauncherConfig {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use core::str;
|
||||||
|
|
||||||
use crate::config::LauncherConfig;
|
use crate::config::LauncherConfig;
|
||||||
|
|
||||||
|
|
||||||
@ -16,6 +18,24 @@ impl Launcher {
|
|||||||
self.config.config_path().exists()
|
self.config.config_path().exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_config(&mut self) {
|
||||||
|
if self.is_config_exist() {
|
||||||
|
self.config = toml::from_str(
|
||||||
|
str::from_utf8(&std::fs::read(self.config.config_path()).unwrap()).unwrap()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save_config(&self) {
|
||||||
|
std::fs::write(self.config.config_path(), toml::to_string_pretty(&self.config).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_config(&mut self, user_name: String) {
|
||||||
|
self.load_config();
|
||||||
|
self.config.user_name = user_name;
|
||||||
|
self.config.user_secret = crate::util::random_string(32);
|
||||||
|
self.save_config();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init_dirs(&self) {
|
pub fn init_dirs(&self) {
|
||||||
let root = self.config.launcher_dir();
|
let root = self.config.launcher_dir();
|
||||||
std::fs::create_dir_all(&root);
|
std::fs::create_dir_all(&root);
|
||||||
|
11
src/main.rs
11
src/main.rs
@ -38,7 +38,6 @@ impl ApplicationHandler for App {
|
|||||||
let webview = WebViewBuilder::new()
|
let webview = WebViewBuilder::new()
|
||||||
.with_asynchronous_custom_protocol("xcraft".into(), move |wid, request, responder| {
|
.with_asynchronous_custom_protocol("xcraft".into(), move |wid, request, responder| {
|
||||||
let uri = request.uri().to_string();
|
let uri = request.uri().to_string();
|
||||||
println!("Body: {}", String::from_utf8(request.body().to_vec()).unwrap());
|
|
||||||
if let Ok(msg) = serde_json::from_slice(request.body()) {
|
if let Ok(msg) = serde_json::from_slice(request.body()) {
|
||||||
let _ = SENDER.lock().unwrap().as_ref().unwrap().send((uri, Some(msg), responder));
|
let _ = SENDER.lock().unwrap().as_ref().unwrap().send((uri, Some(msg), responder));
|
||||||
return;
|
return;
|
||||||
@ -89,23 +88,27 @@ async fn main() {
|
|||||||
"portable" => {
|
"portable" => {
|
||||||
launcher.config.set_portable(true);
|
launcher.config.set_portable(true);
|
||||||
launcher.init_dirs();
|
launcher.init_dirs();
|
||||||
|
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_login".to_string()] }).unwrap()))
|
||||||
}
|
}
|
||||||
"installation" => {
|
"installation" => {
|
||||||
launcher.init_dirs();
|
launcher.init_dirs();
|
||||||
|
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_login".to_string()] }).unwrap()))
|
||||||
}
|
}
|
||||||
"check_installation" => {
|
"check_installation" => {
|
||||||
if launcher.is_portable() {
|
if launcher.is_portable() {
|
||||||
launcher.config.set_portable(true);
|
launcher.config.set_portable(true);
|
||||||
launcher.init_dirs();
|
launcher.init_dirs();
|
||||||
if !launcher.is_config_exist() {
|
if !launcher.is_config_exist() {
|
||||||
responder.respond(Response::new("show_login".as_bytes()))
|
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_login".to_string()] }).unwrap()))
|
||||||
} else {
|
} else {
|
||||||
responder.respond(Response::new("show_add".as_bytes()))
|
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_add".to_string(), "sidebar_on".to_string()] }).unwrap()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"sign_up" => {
|
"sign_up" => {
|
||||||
|
let user_name = params.as_ref().unwrap().params.get(0).unwrap();
|
||||||
|
launcher.init_config(user_name.to_string());
|
||||||
|
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_add".to_string(), "sidebar_on".to_string()] }).unwrap()));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,23 @@
|
|||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
href="#"
|
||||||
|
onclick="showSection(this, 'screenshots')"
|
||||||
|
class="menu-btn group relative flex justify-center rounded-sm px-2 py-1.5 text-gray-500 hover:bg-gray-50 hover:text-gray-700"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-image"></i>
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="invisible absolute start-full top-1/2 ms-4 -translate-y-1/2 rounded-sm bg-gray-900 px-2 py-1.5 text-xs font-medium text-white group-hover:visible"
|
||||||
|
>
|
||||||
|
Screenshots
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
href="#"
|
href="#"
|
||||||
@ -130,8 +146,8 @@
|
|||||||
<h2 class="text-2xl font-semibold text-gray-700">CraftX v1.0</h2>
|
<h2 class="text-2xl font-semibold text-gray-700">CraftX v1.0</h2>
|
||||||
|
|
||||||
<!-- Username -->
|
<!-- Username -->
|
||||||
<input id="sign_up_username" type="text" placeholder="Username" class="mt-4 w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500">
|
<input id="sign_up_username" type="text" placeholder="Username" class="mt-4 w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500"> <!-- bg-red-50 border border-red-500 text-red-900 placeholder-red-700 focus:ring-2 focus:ring-red-500 -->
|
||||||
|
<p class="mt-2 text-sm text-red-600 dark:text-red-500 text-left hidden">Username has invalid characters or too short</p>
|
||||||
<!-- Sign In Button -->
|
<!-- Sign In Button -->
|
||||||
<button
|
<button
|
||||||
onclick="signUp()"
|
onclick="signUp()"
|
||||||
@ -316,21 +332,29 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function processParams(r) {
|
||||||
|
let params = JSON.parse(r).params;
|
||||||
async function signUp() {
|
for( let i = 0; i < params.length; i++ ) {
|
||||||
$.post({url: "sign_up", data: JSON.stringify({ params: [$("#sign_up_username").val()] }) }, function(r) {
|
if( params[i].startsWith("show_") ) {
|
||||||
if( r.startsWith("show_") ) {
|
showSection(undefined, params[i].substring(5));
|
||||||
showSection(undefined, r.substring(5));
|
} else if( params[i] == "sidebar_on" ) {
|
||||||
|
$("#sidebar").removeClass('hidden');
|
||||||
|
} else if( params[i] == "sidebar_off") {
|
||||||
|
$("#sidebar").addClass('hidden');
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function signUp() {
|
||||||
|
$.post({url: "sign_up", data: JSON.stringify({ params: [$("#sign_up_username").val()] }) }, processParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
function runPortable() {
|
function runPortable() {
|
||||||
console.log($.get("portable", function() {}));
|
console.log($.get("portable", processParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
function installMinecraft() {
|
function installMinecraft() {
|
||||||
|
console.log($.get("installation", processParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSection(obj, section) {
|
function showSection(obj, section) {
|
||||||
@ -350,13 +374,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$( document ).ready(async function() {
|
$( document ).ready(async function() {
|
||||||
|
$.get("check_installation", processParams)
|
||||||
$.get("check_installation", function(r) {
|
|
||||||
console.log(r);
|
|
||||||
if( r.startsWith("show_") ) {
|
|
||||||
showSection(undefined, r.substring(5));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user