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:
parent
4f0518184a
commit
240d728227
27
Cargo.lock
generated
27
Cargo.lock
generated
@ -19,10 +19,11 @@ dependencies = [
|
||||
"serde_json",
|
||||
"surf",
|
||||
"tokio 1.44.0",
|
||||
"toml",
|
||||
"toml 0.8.20",
|
||||
"ureq 3.0.10",
|
||||
"ureq_multipart",
|
||||
"winit",
|
||||
"winres",
|
||||
"wry",
|
||||
"zip-extract",
|
||||
]
|
||||
@ -2457,7 +2458,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"windows-targets 0.48.5",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2795,7 +2796,7 @@ version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
|
||||
dependencies = [
|
||||
"proc-macro-crate 2.0.0",
|
||||
"proc-macro-crate 3.3.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
@ -4477,7 +4478,7 @@ dependencies = [
|
||||
"cfg-expr",
|
||||
"heck 0.5.0",
|
||||
"pkg-config",
|
||||
"toml",
|
||||
"toml 0.8.20",
|
||||
"version-compare",
|
||||
]
|
||||
|
||||
@ -4743,6 +4744,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "toml"
|
||||
version = "0.8.20"
|
||||
@ -5806,6 +5816,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.33.0"
|
||||
|
@ -2,6 +2,7 @@
|
||||
name = "CraftX"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
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" }
|
||||
rfd = "0.14"
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
winres = "0.1"
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
opt-level = "s"
|
||||
|
7
build.rs
Normal file
7
build.rs
Normal 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");
|
||||
}
|
1
launcher.rc
Normal file
1
launcher.rc
Normal file
@ -0,0 +1 @@
|
||||
launcher ICON "icon.ico"
|
@ -4,6 +4,11 @@ use std::io::Cursor;
|
||||
use std::path::PathBuf;
|
||||
use base64::Engine;
|
||||
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::io::{AsyncBufReadExt, BufReader};
|
||||
use tokio::process::Command;
|
||||
@ -753,4 +758,24 @@ impl Launcher {
|
||||
let _ = std::fs::create_dir_all(&assets);
|
||||
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)
|
||||
}
|
@ -307,6 +307,8 @@ async fn main() {
|
||||
p.push("bg.base64");
|
||||
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()));
|
||||
} 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" => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user