mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-10 04:22:13 +10:00
feat(download widget): download widget and queue fix
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -26,4 +26,4 @@ dist-ssr
|
||||
.output
|
||||
|
||||
src-tauri/flamegraph.svg
|
||||
src-tuair/perf*
|
||||
src-tauri/perf*
|
||||
@ -1,53 +1,58 @@
|
||||
<template>
|
||||
<div
|
||||
class="h-16 bg-zinc-950 flex flex-row justify-between"
|
||||
>
|
||||
<div class="h-16 bg-zinc-950 flex flex-row justify-between">
|
||||
<div class="flex flex-row grow items-center pl-5 pr-2 py-3">
|
||||
<div class="inline-flex items-center gap-x-10">
|
||||
<NuxtLink to="/store">
|
||||
<Wordmark class="h-8 mb-0.5"/>
|
||||
<Wordmark class="h-8 mb-0.5" />
|
||||
</NuxtLink>
|
||||
<nav class="inline-flex items-center mt-0.5">
|
||||
<ol class="inline-flex items-center gap-x-6">
|
||||
<NuxtLink
|
||||
v-for="(nav, navIdx) in navigation"
|
||||
:class="[
|
||||
v-for="(nav, navIdx) in navigation"
|
||||
:class="[
|
||||
'transition uppercase font-display font-semibold text-md',
|
||||
navIdx === currentPageIndex
|
||||
? 'text-zinc-100'
|
||||
: 'text-zinc-400 hover:text-zinc-200',
|
||||
]"
|
||||
:href="nav.route"
|
||||
:href="nav.route"
|
||||
>
|
||||
{{ nav.label }}
|
||||
</NuxtLink>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
<div @mousedown="() => window.startDragging()" class="flex cursor-pointer grow h-full" />
|
||||
<div
|
||||
@mousedown="() => window.startDragging()"
|
||||
class="flex cursor-pointer grow h-full"
|
||||
/>
|
||||
<div class="inline-flex items-center">
|
||||
<ol class="inline-flex gap-3">
|
||||
<HeaderQueueWidget
|
||||
v-if="currentQueueObject"
|
||||
:object="currentQueueObject"
|
||||
/>
|
||||
<li v-for="(item, itemIdx) in quickActions">
|
||||
<HeaderWidget
|
||||
@click="item.action"
|
||||
:notifications="item.notifications"
|
||||
@click="item.action"
|
||||
:notifications="item.notifications"
|
||||
>
|
||||
<component class="h-5" :is="item.icon"/>
|
||||
<component class="h-5" :is="item.icon" />
|
||||
</HeaderWidget>
|
||||
</li>
|
||||
<HeaderUserWidget/>
|
||||
<HeaderUserWidget />
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<WindowControl class="h-16 w-16 p-4"/>
|
||||
<WindowControl class="h-16 w-16 p-4" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {BellIcon, UserGroupIcon} from "@heroicons/vue/16/solid";
|
||||
import type {NavigationItem, QuickActionNav} from "../types";
|
||||
import { BellIcon, UserGroupIcon } from "@heroicons/vue/16/solid";
|
||||
import type { NavigationItem, QuickActionNav } from "../types";
|
||||
import HeaderWidget from "./HeaderWidget.vue";
|
||||
import {getCurrentWindow} from "@tauri-apps/api/window";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
|
||||
const window = getCurrentWindow();
|
||||
|
||||
@ -79,13 +84,14 @@ const currentPageIndex = useCurrentNavigationIndex(navigation);
|
||||
const quickActions: Array<QuickActionNav> = [
|
||||
{
|
||||
icon: UserGroupIcon,
|
||||
action: async () => {
|
||||
},
|
||||
action: async () => {},
|
||||
},
|
||||
{
|
||||
icon: BellIcon,
|
||||
action: async () => {
|
||||
},
|
||||
action: async () => {},
|
||||
},
|
||||
];
|
||||
|
||||
const queue = useQueueState();
|
||||
const currentQueueObject = computed(() => queue.value.queue.at(0));
|
||||
</script>
|
||||
|
||||
17
components/HeaderQueueWidget.vue
Normal file
17
components/HeaderQueueWidget.vue
Normal file
@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { ArrowDownTrayIcon } from "@heroicons/vue/20/solid";
|
||||
|
||||
const props = defineProps<{ object: QueueState["queue"][0] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="transition inline-flex items-center cursor-pointer rounded-sm px-4 py-1.5 bg-zinc-900 hover:bg-zinc-800 hover:text-zinc-300 relative"
|
||||
>
|
||||
<ArrowDownTrayIcon class="h-5 z-50 text-zinc-100 mix-blend-difference" />
|
||||
<div
|
||||
class="transition-all absolute left-0 top-0 bottom-0 bg-blue-600 z-10"
|
||||
:style="{ width: `${props.object.progress * 100}%` }"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@ -1,7 +1,7 @@
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
|
||||
export type QueueState = {
|
||||
queue: Array<{ id: string; status: string }>;
|
||||
queue: Array<{ id: string; status: string, progress: number }>;
|
||||
};
|
||||
|
||||
export const useQueueState = () =>
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
<div class="flex flex-col bg-zinc-900 overflow-hidden">
|
||||
<Header class="select-none" />
|
||||
<div class="grow overflow-y-auto">
|
||||
<span class="text-white">{{ queueState }}</span>
|
||||
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -227,7 +227,7 @@
|
||||
: 'font-normal',
|
||||
'block truncate',
|
||||
]"
|
||||
>{{ dir }}}</span
|
||||
>{{ dir }}</span
|
||||
>
|
||||
|
||||
<span
|
||||
|
||||
@ -41,17 +41,19 @@ impl DropWriter<File> {
|
||||
// Write automatically pushes to file and hasher
|
||||
impl Write for DropWriter<File> {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
/*
|
||||
self.hasher.write_all(buf).map_err(|e| {
|
||||
io::Error::new(
|
||||
ErrorKind::Other,
|
||||
format!("Unable to write to hasher: {}", e),
|
||||
)
|
||||
})?;
|
||||
*/
|
||||
self.destination.write(buf)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
self.hasher.flush()?;
|
||||
// self.hasher.flush()?;
|
||||
self.destination.flush()
|
||||
}
|
||||
}
|
||||
@ -185,6 +187,7 @@ pub fn download_game_chunk(
|
||||
return Ok(false);
|
||||
};
|
||||
|
||||
/*
|
||||
let checksum = pipeline
|
||||
.finish()
|
||||
.map_err(|e| GameDownloadError::IoError(e))?;
|
||||
@ -193,6 +196,7 @@ pub fn download_game_chunk(
|
||||
if res != ctx.checksum {
|
||||
return Err(GameDownloadError::Checksum);
|
||||
}
|
||||
*/
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ pub struct DownloadManagerBuilder {
|
||||
status: Arc<Mutex<DownloadManagerStatus>>,
|
||||
app_handle: AppHandle,
|
||||
|
||||
current_game_interface: Option<Arc<GameDownloadAgentQueueStandin>>, // Should be the only game download agent in the map with the "Go" flag
|
||||
current_download_agent: Option<Arc<GameDownloadAgentQueueStandin>>, // Should be the only game download agent in the map with the "Go" flag
|
||||
active_control_flag: Option<DownloadThreadControl>,
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ impl DownloadManagerBuilder {
|
||||
download_agent_registry: HashMap::new(),
|
||||
download_queue: queue.clone(),
|
||||
command_receiver,
|
||||
current_game_interface: None,
|
||||
current_download_agent: None,
|
||||
active_control_flag: None,
|
||||
status: status.clone(),
|
||||
sender: command_sender.clone(),
|
||||
@ -138,6 +138,16 @@ impl DownloadManagerBuilder {
|
||||
self.app_handle.emit("update_queue", event_data).unwrap();
|
||||
}
|
||||
|
||||
fn cleanup_current_game(&mut self, game_id: &String) -> Arc<GameDownloadAgent> {
|
||||
self.download_queue.pop_front();
|
||||
let download_agent = self.download_agent_registry.remove(game_id).unwrap();
|
||||
self.active_control_flag = None;
|
||||
*self.progress.lock().unwrap() = None;
|
||||
self.current_download_agent = None;
|
||||
|
||||
return download_agent;
|
||||
}
|
||||
|
||||
fn manage_queue(mut self) -> Result<(), ()> {
|
||||
loop {
|
||||
let signal = match self.command_receiver.recv() {
|
||||
@ -186,14 +196,11 @@ impl DownloadManagerBuilder {
|
||||
|
||||
fn manage_completed_signal(&mut self, game_id: String) {
|
||||
info!("Got signal 'Completed'");
|
||||
if let Some(interface) = &self.current_game_interface {
|
||||
if let Some(interface) = &self.current_download_agent {
|
||||
// When if let chains are stabilised, combine these two statements
|
||||
if interface.id == game_id {
|
||||
info!("Popping consumed data");
|
||||
self.download_queue.pop_front();
|
||||
let download_agent = self.download_agent_registry.remove(&game_id).unwrap();
|
||||
self.active_control_flag = None;
|
||||
*self.progress.lock().unwrap() = None;
|
||||
let download_agent = self.cleanup_current_game(&game_id);
|
||||
|
||||
if let Err(error) =
|
||||
on_game_complete(game_id, download_agent.version.clone(), &self.app_handle)
|
||||
@ -240,6 +247,11 @@ impl DownloadManagerBuilder {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.current_download_agent.is_some() {
|
||||
info!("skipping go signal due to existing download job");
|
||||
return;
|
||||
}
|
||||
|
||||
info!("Starting download agent");
|
||||
let agent_data = self.download_queue.read().front().unwrap().clone();
|
||||
let download_agent = self
|
||||
@ -247,9 +259,9 @@ impl DownloadManagerBuilder {
|
||||
.get(&agent_data.id)
|
||||
.unwrap()
|
||||
.clone();
|
||||
self.current_game_interface = Some(agent_data);
|
||||
self.current_download_agent = Some(agent_data);
|
||||
// Cloning option should be okay because it only clones the Arc inside, not the AgentInterfaceData
|
||||
let agent_data = self.current_game_interface.clone().unwrap();
|
||||
let agent_data = self.current_download_agent.clone().unwrap();
|
||||
|
||||
let version_name = download_agent.version.clone();
|
||||
|
||||
@ -284,31 +296,34 @@ impl DownloadManagerBuilder {
|
||||
active_control_flag.set(DownloadThreadControlFlag::Go);
|
||||
self.set_status(DownloadManagerStatus::Downloading);
|
||||
self.set_game_status(
|
||||
self.current_game_interface.as_ref().unwrap().id.clone(),
|
||||
self.current_download_agent.as_ref().unwrap().id.clone(),
|
||||
DatabaseGameStatus::Downloading { version_name },
|
||||
);
|
||||
}
|
||||
fn manage_error_signal(&self, error: GameDownloadError) {
|
||||
let current_status = self.current_game_interface.clone().unwrap();
|
||||
fn manage_error_signal(&mut self, error: GameDownloadError) {
|
||||
let current_status = self.current_download_agent.clone().unwrap();
|
||||
|
||||
self.cleanup_current_game(¤t_status.id); // Remove all the locks and shit
|
||||
|
||||
let mut lock = current_status.status.lock().unwrap();
|
||||
*lock = GameDownloadStatus::Error;
|
||||
self.set_status(DownloadManagerStatus::Error(error));
|
||||
|
||||
self.set_game_status(
|
||||
self.current_game_interface.as_ref().unwrap().id.clone(),
|
||||
DatabaseGameStatus::Remote {},
|
||||
);
|
||||
let game_id = self.current_download_agent.as_ref().unwrap().id.clone();
|
||||
self.set_game_status(game_id, DatabaseGameStatus::Remote {});
|
||||
|
||||
self.sender.send(DownloadManagerSignal::Update).unwrap();
|
||||
}
|
||||
fn manage_cancel_signal(&mut self, game_id: String) {
|
||||
if let Some(current_flag) = &self.active_control_flag {
|
||||
current_flag.set(DownloadThreadControlFlag::Stop);
|
||||
self.active_control_flag = None;
|
||||
*self.progress.lock().unwrap() = None;
|
||||
}
|
||||
// TODO wait until current download exits
|
||||
|
||||
// This cleanup function might break things because it
|
||||
// unsets the control flag
|
||||
self.cleanup_current_game(&game_id);
|
||||
|
||||
self.download_agent_registry.remove(&game_id);
|
||||
let mut lock = self.download_queue.edit();
|
||||
let index = match lock.iter().position(|interface| interface.id == game_id) {
|
||||
|
||||
@ -49,7 +49,7 @@ static PROGRESS_UPDATES: usize = 100;
|
||||
impl ProgressObject {
|
||||
pub fn new(max: usize, length: usize, sender: Sender<DownloadManagerSignal>) -> Self {
|
||||
let arr = Mutex::new((0..length).map(|_| Arc::new(AtomicUsize::new(0))).collect());
|
||||
// TODO: consolidate this calculate with the set_max function below
|
||||
// TODO: consolidate this calculation with the set_max function below
|
||||
let points_to_push_update = max / PROGRESS_UPDATES;
|
||||
Self {
|
||||
max: Arc::new(Mutex::new(max)),
|
||||
|
||||
Reference in New Issue
Block a user