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

View File

@@ -12,6 +12,7 @@
"dependencies": {
"@fontsource/roboto": "5.2.6",
"@tauri-apps/api": "2.6.0",
"@tauri-apps/plugin-fs": "2.4.0",
"@tauri-apps/plugin-opener": "2.4.0",
"@tauri-apps/plugin-os": "2.3.0",
"axios": "1.10.0",

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) {
async fn download(app: AppHandle, url: String, name: String) -> Result<(), 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();
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();
//code from the wiki i didnt change it yet
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"
]
}
}

View File

@@ -41,7 +41,7 @@ export default function Sidebar({ setShowPopup, setPopupMode, setFadeOut }: Side
style={{
transform: `rotate(${rot}deg)`,
transition: 'transform 0.3s ease',
marginTop: platform() == 'macos' ? '20px' : '0px'
marginTop: ['windows','macos'].includes(platform()) ? '20px' : '0px'
}}
onClick={() =>
setRot(r => {

View File

@@ -41,7 +41,7 @@ function App () {
setDownloadProgress(prev => [...prev, ...newDownloads]);
newDownloads.forEach(download => {
invoke('download', { url: download.version.downloadUrls[download.version.platforms.indexOf(platform())] });
invoke('download', { url: download.version.downloadUrls[download.version.platforms.indexOf(platform())], name: download.version.version });
});
}
@@ -76,7 +76,10 @@ function App () {
return (
<>
<Sidebar setShowPopup={setShowPopup} setPopupMode={setPopupMode} setFadeOut={setFadeOut} />
<div className="relative z-[1] ml-[239px] w-[761px] border-b border-[#323232] h-[33px] bg-[#161616]" style={{ display: platform() == 'windows' ? 'block' : 'none' }}></div>
<div className="relative z-0">
<main style={{ marginLeft: '15rem' }}>{renderContent()}</main>
</div>
{showPopup && (
<div
className={`popup-overlay ${fadeOut ? 'fade-out' : ''}`}

View File

@@ -14,15 +14,15 @@ export default function Installs({ downloadProgress, showPopup, setShowPopup, se
}, [showPopup])
return (
<>
<p className='text-3xl ml-4 mt-4'>Installs</p>
<div className='flex justify-between items-center mt-4 mx-4'>
<p className='text-3xl'>Installs</p>
<button
className='button text-3xl mt-4 absolute right-4 top-4'
className='button text-3xl'
onClick={() => { setPopupMode(0); setShowPopup(true); setFadeOut(false) }}
disabled={downloadProgress.length != 0}
>
Download new version
</button>
</>
</div>
)
}

View File

@@ -699,6 +699,13 @@
"@tauri-apps/cli-win32-ia32-msvc" "2.6.2"
"@tauri-apps/cli-win32-x64-msvc" "2.6.2"
"@tauri-apps/plugin-fs@2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-fs/-/plugin-fs-2.4.0.tgz#d76e4d1b3061508b21427394b9063e904897c87c"
integrity sha512-Sp8AdDcbyXyk6LD6Pmdx44SH3LPeNAvxR2TFfq/8CwqzfO1yOyV+RzT8fov0NNN7d9nvW7O7MtMAptJ42YXA5g==
dependencies:
"@tauri-apps/api" "^2.6.0"
"@tauri-apps/plugin-opener@2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-opener/-/plugin-opener-2.4.0.tgz#57eae5998e1c396791af16832a9dde16eca06439"