Windows styles + downloading

This commit is contained in:
2025-07-19 23:07:42 -07:00
parent f17c3fc097
commit 2e2cb9b563
10 changed files with 796 additions and 43 deletions

700
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,4 +18,9 @@ serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.141"
tauri-plugin-os = "2.3.0"
base64 = "0.22.1"
reqwest = { version = "0.12.22", features = ["stream"] }
tokio = "1.46.1"
futures-util = "0.3.31"
tauri-plugin-decorum = "1.1.1"
tauri-plugin-fs = "2"

View File

@@ -10,6 +10,16 @@
"opener:default",
"os:default",
"core:window:default",
"core:window:allow-start-dragging"
"core:window:allow-close",
"core:window:allow-center",
"core:window:allow-minimize",
"core:window:allow-maximize",
"core:window:allow-set-size",
"core:window:allow-set-focus",
"core:window:allow-is-maximized",
"core:window:allow-start-dragging",
"core:window:allow-toggle-maximize",
"decorum:allow-show-snap-overlay",
"fs:default"
]
}

View File

@@ -1,23 +1,62 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
use base64::{Engine, engine::general_purpose};
use tauri::{AppHandle, Emitter};
use futures_util::StreamExt;
use tauri::{AppHandle, Emitter, Manager};
use tauri_plugin_decorum::WebviewWindowExt;
use tokio::io::AsyncWriteExt;
#[tauri::command]
fn download(app: AppHandle, url: String) {
app.emit("download-started", &url).unwrap();
for progress in [1, 15, 50, 80, 100] {
app.emit("download-progress", format!("{}:{}", general_purpose::STANDARD.encode(&url), progress)).unwrap();
}
app.emit("download-finished", &url).unwrap();
//code from the wiki i didnt change it yet
async fn download(app: AppHandle, url: String, name: String) -> Result<(), String> {
app.emit("download-started", &url).unwrap();
let client = reqwest::Client::new();
let resp = client.get(&url).send().await.map_err(|e| e.to_string())?;
let total_size = resp.content_length().unwrap_or(0);
let mut downloaded: u64 = 0;
let mut stream = resp.bytes_stream();
println!("{}", app.path().data_dir().unwrap().display().to_string());
let mut file = tokio::fs::File::create(app.path().data_dir().unwrap().join(format!("download_{}.zip", name)))
.await
.map_err(|e| e.to_string())?;
while let Some(chunk) = stream.next().await {
let chunk = chunk.map_err(|e| e.to_string())?;
file.write_all(&chunk).await.map_err(|e| e.to_string())?;
downloaded += chunk.len() as u64;
let progress = if total_size > 0 {
(downloaded * 100 / total_size) as u8
} else {
0
};
app.emit(
"download-progress",
format!("{}:{}", general_purpose::STANDARD.encode(&url), progress),
)
.unwrap();
}
app.emit("download-finished", &url).unwrap();
Ok(())
}
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_decorum::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![download])
.setup(|app| {
#[cfg(target_os = "windows")] {
let main_window = app.get_webview_window("main").unwrap();
main_window.create_overlay_titlebar().unwrap();
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,42 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "Berry Dash Launcher",
"version": "1.0.0",
"identifier": "xyz.lncvrt.berrydash-launcher",
"build": {
"beforeDevCommand": "yarn dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "yarn build",
"frontendDist": "../dist"
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "Berry Dash Launcher",
"width": 1000,
"height": 632,
"resizable": false,
"maximizable": false,
"titleBarStyle": "Overlay",
"hiddenTitle": true,
"decorations": false,
"shadow": false
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}