modified: Cargo.lock

modified:   Cargo.toml
	new file:   build.rs
	new file:   icon.ico
	new file:   launcher.rc
	modified:   src/launcher.rs
	modified:   src/main.rs
This commit is contained in:
Michael Wain 2025-03-24 04:53:57 +03:00
parent 4f0518184a
commit 240d728227
7 changed files with 62 additions and 4 deletions

27
Cargo.lock generated
View File

@ -19,10 +19,11 @@ dependencies = [
"serde_json", "serde_json",
"surf", "surf",
"tokio 1.44.0", "tokio 1.44.0",
"toml", "toml 0.8.20",
"ureq 3.0.10", "ureq 3.0.10",
"ureq_multipart", "ureq_multipart",
"winit", "winit",
"winres",
"wry", "wry",
"zip-extract", "zip-extract",
] ]
@ -2457,7 +2458,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"windows-targets 0.48.5", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -2795,7 +2796,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.0", "proc-macro-crate 3.3.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.100", "syn 2.0.100",
@ -4477,7 +4478,7 @@ dependencies = [
"cfg-expr", "cfg-expr",
"heck 0.5.0", "heck 0.5.0",
"pkg-config", "pkg-config",
"toml", "toml 0.8.20",
"version-compare", "version-compare",
] ]
@ -4743,6 +4744,15 @@ dependencies = [
"tokio 0.2.25", "tokio 0.2.25",
] ]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.20" version = "0.8.20"
@ -5806,6 +5816,15 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "winres"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c"
dependencies = [
"toml 0.5.11",
]
[[package]] [[package]]
name = "wit-bindgen-rt" name = "wit-bindgen-rt"
version = "0.33.0" version = "0.33.0"

View File

@ -2,6 +2,7 @@
name = "CraftX" name = "CraftX"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
build = "build.rs"
[dependencies] [dependencies]
winit = "0.30.9" winit = "0.30.9"
@ -24,6 +25,9 @@ toml = "0.8.20"
nicotine = { git = "https://gitea.awain.net/alterwain/Nicotine.git", version = "0.1.22" } nicotine = { git = "https://gitea.awain.net/alterwain/Nicotine.git", version = "0.1.22" }
rfd = "0.14" rfd = "0.14"
[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
[profile.release] [profile.release]
strip = true strip = true
opt-level = "s" opt-level = "s"

7
build.rs Normal file
View File

@ -0,0 +1,7 @@
extern crate winres;
fn main() {
let mut res = winres::WindowsResource::new();
res.set_icon("icon.ico");
res.compile().expect("Failed to compile Windows resource");
}

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

1
launcher.rc Normal file
View File

@ -0,0 +1 @@
launcher ICON "icon.ico"

View File

@ -4,6 +4,11 @@ use std::io::Cursor;
use std::path::PathBuf; use std::path::PathBuf;
use base64::Engine; use base64::Engine;
use base64::prelude::BASE64_STANDARD; use base64::prelude::BASE64_STANDARD;
use rand::rngs::StdRng;
use rand::seq::IndexedRandom;
use rand::SeedableRng;
use serde::{Deserialize, Serialize};
use surf::StatusCode;
use tokio::fs::File; use tokio::fs::File;
use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::process::Command; use tokio::process::Command;
@ -753,4 +758,24 @@ impl Launcher {
let _ = std::fs::create_dir_all(&assets); let _ = std::fs::create_dir_all(&assets);
let _ = std::fs::create_dir_all(&libraries); let _ = std::fs::create_dir_all(&libraries);
} }
}
#[derive(Serialize, Deserialize)]
struct BackgroundFiles {
name: String
}
pub async fn get_random_bg() -> Result<Option<String>, Box<dyn Error + Send + Sync>> {
let mut r = surf::get("https://minecraft.awain.net/xcraft/").await?;
if r.status() != StatusCode::Ok { return Ok(None); }
let resp = r.body_bytes().await?;
let resp: Vec<BackgroundFiles> = serde_json::from_slice(&resp)?;
let mut rng = StdRng::from_os_rng();
if let Some(resp) = resp.choose(&mut rng) {
let mut r = surf::get(["https://minecraft.awain.net/xcraft/", &resp.name].concat()).await?;
if r.status() != StatusCode::Ok { return Ok(None); }
let resp = r.body_bytes().await?;
return Ok(Some(["data:image/jpeg;base64,", &BASE64_STANDARD.encode(resp)].concat()));
}
Ok(None)
} }

View File

@ -307,6 +307,8 @@ async fn main() {
p.push("bg.base64"); p.push("bg.base64");
if let Ok(data) = std::fs::read(p) { if let Ok(data) = std::fs::read(p) {
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["fetch_bg".to_string(), String::from_utf8(data).unwrap()] }).unwrap())); responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["fetch_bg".to_string(), String::from_utf8(data).unwrap()] }).unwrap()));
} else if let Ok(Some(data)) = launcher::get_random_bg().await {
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["fetch_bg".to_string(), data] }).unwrap()));
} }
} }
"update_settings" => { "update_settings" => {