diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 2df5ab3..ba7454a 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -261,6 +261,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
name = "berry-dash-launcher"
version = "1.0.0"
dependencies = [
+ "base64 0.22.1",
"serde",
"serde_json",
"tauri",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 7c47b17..e7e309e 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -17,4 +17,5 @@ tauri-plugin-opener = "2.4.0"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.141"
tauri-plugin-os = "2.3.0"
+base64 = "0.22.1"
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index fbbbab4..903cdae 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1,9 +1,23 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
+
+use base64::{Engine, engine::general_purpose};
+use tauri::{AppHandle, Emitter};
+
+#[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
+}
+
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_opener::init())
- .invoke_handler(tauri::generate_handler![])
+ .invoke_handler(tauri::generate_handler![download])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
diff --git a/src/Globals.css b/src/Globals.css
index c7c05be..f3ae65f 100644
--- a/src/Globals.css
+++ b/src/Globals.css
@@ -22,3 +22,44 @@ body {
@apply bg-[#555] w-1 rounded-lg active:bg-[#888];
}
+@keyframes fadeIn {
+ from {
+ opacity: 0;
+ }
+ to {
+ opacity: 1;
+ }
+}
+
+@keyframes fadeOut {
+ from {
+ opacity: 1;
+ }
+ to {
+ opacity: 0;
+ }
+}
+
+.popup-overlay {
+ @apply fixed w-screen h-screen z-[99999] flex justify-center items-center animate-[fadeIn_0.2s_ease-out_forwards] left-0 top-0 bg-[rgba(0,0,0,0.5)];
+}
+
+.popup-overlay.fade-out {
+ @apply animate-[fadeOut_0.2s_ease-out_forwards];
+}
+
+.popup-box {
+ @apply relative w-[60vw] h-[80vh] shadow-[0_0_20px_rgba(0,0,0,0.2)] rounded-lg bg-[#191919] flex flex-col p-6;
+}
+
+.popup-content {
+ @apply flex-1 overflow-auto border border-[#323232] rounded-lg mt-4;
+}
+
+.popup-entry {
+ @apply relative h-[100px] bg-[#242424] m-2 p-2 rounded-lg border border-[#484848];
+}
+
+.popup-entry button {
+ @apply absolute;
+}
diff --git a/src/componets/Sidebar.tsx b/src/componets/Sidebar.tsx
index 21b0c65..3d45127 100644
--- a/src/componets/Sidebar.tsx
+++ b/src/componets/Sidebar.tsx
@@ -9,7 +9,7 @@ import { platform } from '@tauri-apps/plugin-os'
import { getCurrentWindow } from '@tauri-apps/api/window'
import { SidebarProps } from '../types/SidebarProps'
-export default function Sidebar({ downloadProgress }: SidebarProps) {
+export default function Sidebar({ setShowPopup, setPopupMode, setFadeOut }: SidebarProps) {
const [rot, setRot] = useState(0)
const [dir, setDir] = useState(1)
@@ -76,7 +76,7 @@ export default function Sidebar({ downloadProgress }: SidebarProps) {
Settings
openUrl("https://berrydash.lncvrt.xyz/discord")} className="link">Community
-
+
{ setPopupMode(1); setShowPopup(true); setFadeOut(false) }}>
Downloads
diff --git a/src/main.tsx b/src/main.tsx
index 4717ff2..b6741e7 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useState } from 'react'
+import { useEffect, useState } from 'react'
import ReactDOM from 'react-dom/client'
import Installs from './routes/Installs'
import Settings from './routes/Settings'
@@ -6,18 +6,49 @@ import Sidebar from './componets/Sidebar'
import './Globals.css'
import { LauncherVersion } from './types/LauncherVersion'
import { DownloadProgress } from './types/DownloadProgress'
+import { platform } from '@tauri-apps/plugin-os'
+import { invoke } from '@tauri-apps/api/core'
+import { listen } from '@tauri-apps/api/event'
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
+import { faAdd, faRemove, faX } from '@fortawesome/free-solid-svg-icons'
function App () {
const [hash, setHash] = useState(window.location.hash || '#installs')
+ const [versionList, setVersionList] = useState
(null);
+ const [selectedVersionList, setSelectedVersionList] = useState([]);
const [downloadProgress, setDownloadProgress] = useState([]);
+ const [showPopup, setShowPopup] = useState(false)
+ const [popupMode, setPopupMode] = useState(null)
+ const [fadeOut, setFadeOut] = useState(false)
+
+ listen('download-progress', (event) => {
+ const [urlEnc, progStr] = event.payload.split(':')
+ const url = atob(urlEnc)
+ const prog = Number(progStr)
+ setDownloadProgress(prev => {
+ const i = prev.findIndex(d => d.version.downloadUrls[d.version.platforms.indexOf(platform())] === url)
+ if (i === -1) return prev
+ if (prog >= 100) return prev.filter((_, j) => j !== i)
+ const copy = [...prev]
+ copy[i] = { ...copy[i], progress: prog }
+ return copy
+ })
+ })
function downloadVersions(versions: LauncherVersion[]) {
- setDownloadProgress(prev => [
- ...prev,
- ...versions.map(v => new DownloadProgress(v, 0, false))
- ])
+ const newDownloads = versions.map(v => new DownloadProgress(v, 0, false));
+ setDownloadProgress(prev => [...prev, ...newDownloads]);
- return;
+ newDownloads.forEach(download => {
+ invoke('download', { url: download.version.downloadUrls[download.version.platforms.indexOf(platform())] });
+ });
+ }
+
+ function handleOverlayClick (e: React.MouseEvent) {
+ if (e.target === e.currentTarget) {
+ setFadeOut(true)
+ setTimeout(() => setShowPopup(false), 200)
+ }
}
useEffect(() => {
@@ -34,7 +65,7 @@ function App () {
function renderContent () {
if (hash === '#installs') {
- return
+ return
} else if (hash === '#settings') {
return
}
@@ -43,14 +74,79 @@ function App () {
return (
<>
-
+
{renderContent()}
+ {showPopup && (
+
+
+
+ {popupMode === 0 ? (
+ <>
+
Select versions to download
+
+ {versionList == null ? (
+
Getting version list...
+ ) : (
+ versionList.map((v, i) =>
+
+
Berry Dash v{v.displayName}
+
+
+ )
+ )}
+
+ >
+ ) : popupMode === 1 ? (
+ <>
+
Downloads
+
+ {downloadProgress.length === 0 ? (
+
Nothing here...
+ ) : (
+ downloadProgress.map((v, i) => (
+
+
Berry Dash v{v.version.displayName}
+
{v.progress}% downloaded
+
+ ))
+ )}
+
+ >
+ ) : null}
+ {popupMode == 0 && versionList != null && (
+
+
+
+ )}
+
+
+ )}
>
)
}
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
-
-
-
+
)
diff --git a/src/routes/Installs.css b/src/routes/Installs.css
index b495d31..1f38d98 100644
--- a/src/routes/Installs.css
+++ b/src/routes/Installs.css
@@ -1,47 +1,5 @@
@import 'tailwindcss';
-@keyframes fadeIn {
- from {
- opacity: 0;
- }
- to {
- opacity: 1;
- }
-}
-
-@keyframes fadeOut {
- from {
- opacity: 1;
- }
- to {
- opacity: 0;
- }
-}
-
-.popup-overlay {
- @apply fixed w-screen h-screen z-[9999] flex justify-center items-center animate-[fadeIn_0.2s_ease-out_forwards] left-0 top-0 bg-[rgba(0,0,0,0.5)];
-}
-
-.popup-overlay.fade-out {
- @apply animate-[fadeOut_0.2s_ease-out_forwards];
-}
-
-.popup-box {
- @apply relative w-[60vw] h-[80vh] shadow-[0_0_20px_rgba(0,0,0,0.2)] rounded-lg bg-[#191919] flex flex-col p-6;
-}
-
-.popup-content {
- @apply flex-1 overflow-auto border border-[#323232] rounded-lg mt-4;
-}
-
-.popup-entry {
- @apply relative h-[100px] bg-[#242424] m-2 p-2 rounded-lg border border-[#484848];
-}
-
-.popup-entry button {
- @apply absolute;
-}
-
.close-button {
@apply flex justify-center items-center absolute bg-[#323232] hover:bg-[#484848] text-2xl cursor-pointer text-gray-300 hover:text-white h-12 w-12 p-3 rounded-xl border-[none] left-2 top-2 transition-colors;
}
diff --git a/src/routes/Installs.tsx b/src/routes/Installs.tsx
index 5a505d2..6d5154c 100644
--- a/src/routes/Installs.tsx
+++ b/src/routes/Installs.tsx
@@ -1,29 +1,9 @@
-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import './Installs.css'
-import { useEffect, useState } from 'react'
-import { faAdd, faRemove, faX } from '@fortawesome/free-solid-svg-icons'
-import { LauncherVersion } from '../types/LauncherVersion'
+import { useEffect } from 'react'
import axios from 'axios'
import { InstallsProps } from '../types/InstallsProps'
-export default function Installs({ downloadVersions, downloadProgress }: InstallsProps) {
- const [showPopup, setShowPopup] = useState(false)
- const [fadeOut, setFadeOut] = useState(false)
- const [versionList, setVersionList] = useState(null);
- const [selectedVersionList, setSelectedVersionList] = useState([]);
-
- function downloadVersion () {
- setShowPopup(true)
- setFadeOut(false)
- }
-
- function handleOverlayClick (e: React.MouseEvent) {
- if (e.target === e.currentTarget) {
- setFadeOut(true)
- setTimeout(() => setShowPopup(false), 200)
- }
- }
-
+export default function Installs({ downloadProgress, showPopup, setShowPopup, setPopupMode, setFadeOut, setSelectedVersionList, setVersionList }: InstallsProps) {
useEffect(() => {
if (!showPopup) return
setSelectedVersionList([]);
@@ -38,58 +18,11 @@ export default function Installs({ downloadVersions, downloadProgress }: Install
Installs
- {showPopup && (
-
-
-
-
Select versions to download
-
- {versionList == null ? (
-
Downloading version list...
- ) : (
- versionList.map((v, i) =>
-
-
Berry Dash v{v.displayName}
-
-
- )
- )}
-
- {versionList != null && (
-
-
-
- )}
-
-
- )}
>
)
}
diff --git a/src/types/DownloadProgress.ts b/src/types/DownloadProgress.ts
index 5bbe87f..763ca2d 100644
--- a/src/types/DownloadProgress.ts
+++ b/src/types/DownloadProgress.ts
@@ -4,6 +4,6 @@ export class DownloadProgress {
constructor (
public version: LauncherVersion,
public progress: number,
- public done: boolean
+ public failed: boolean
) {}
}
diff --git a/src/types/InstallsProps.ts b/src/types/InstallsProps.ts
index 53aed51..3c4519a 100644
--- a/src/types/InstallsProps.ts
+++ b/src/types/InstallsProps.ts
@@ -2,6 +2,11 @@ import { DownloadProgress } from './DownloadProgress'
import { LauncherVersion } from './LauncherVersion'
export type InstallsProps = {
- downloadVersions: (versions: LauncherVersion[]) => void
downloadProgress: DownloadProgress[]
+ showPopup: boolean
+ setShowPopup: (v: boolean) => void
+ setPopupMode: (v: null | number) => void
+ setFadeOut: (v: boolean) => void
+ setSelectedVersionList: (v: LauncherVersion[]) => void
+ setVersionList: (v: null | LauncherVersion[]) => void
}
diff --git a/src/types/SidebarProps.ts b/src/types/SidebarProps.ts
index 810cbb5..e2bca3b 100644
--- a/src/types/SidebarProps.ts
+++ b/src/types/SidebarProps.ts
@@ -1,5 +1,5 @@
-import { DownloadProgress } from './DownloadProgress'
-
export type SidebarProps = {
- downloadProgress: DownloadProgress[]
+ setShowPopup: (v: boolean) => void
+ setPopupMode: (v: null | number) => void
+ setFadeOut: (v: boolean) => void
}