Skip to content

Commit

Permalink
Add UpdateStatus enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
LZQCN committed Dec 24, 2023
1 parent cf58e31 commit f2f27d3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
10 changes: 9 additions & 1 deletion client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,16 @@ export namespace workshop {
current: bigint
total: bigint
}
export const enum UpdateStatus {
Invalid = 0,
PreparingConfig = 1,
PreparingContent = 2,
UploadingContent = 3,
UploadingPreviewFile = 4,
CommittingChanges = 5
}
export interface UpdateProgress {
status: number
status: UpdateStatus
progress: bigint
total: bigint
}
Expand Down
35 changes: 30 additions & 5 deletions src/api/workshop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod workshop {
use napi::threadsafe_function::ThreadsafeFunction;
use napi::threadsafe_function::ThreadsafeFunctionCallMode;
use std::path::Path;
use steamworks::{FileType, PublishedFileId, UpdateStatus};
use steamworks::{FileType, PublishedFileId};
use tokio::sync::oneshot;

#[napi(object)]
Expand Down Expand Up @@ -59,9 +59,34 @@ pub mod workshop {
pub total: BigInt,
}

#[napi]
pub enum UpdateStatus {
Invalid,
PreparingConfig,
PreparingContent,
UploadingContent,
UploadingPreviewFile,
CommittingChanges,
}

impl From<steamworks::UpdateStatus> for UpdateStatus {
fn from(visibility: steamworks::UpdateStatus) -> Self {
match visibility {
steamworks::UpdateStatus::Invalid => UpdateStatus::Invalid,
steamworks::UpdateStatus::PreparingConfig => UpdateStatus::PreparingConfig,
steamworks::UpdateStatus::PreparingContent => UpdateStatus::PreparingContent,
steamworks::UpdateStatus::UploadingContent => UpdateStatus::UploadingContent,
steamworks::UpdateStatus::UploadingPreviewFile => {
UpdateStatus::UploadingPreviewFile
}
steamworks::UpdateStatus::CommittingChanges => UpdateStatus::CommittingChanges,
}
}
}

#[napi(object)]
pub struct UpdateProgress {
pub status: u32,
pub status: UpdateStatus,
pub progress: BigInt,
pub total: BigInt,
}
Expand Down Expand Up @@ -241,14 +266,14 @@ pub mod workshop {
std::thread::spawn(move || loop {
let (status, progress, total) = update_watch_handle.progress();
let value = UpdateProgress {
status: status as u32,
status: status.into(),
progress: BigInt::from(progress),
total: BigInt::from(total),
};
progress_callback.call(value, ThreadsafeFunctionCallMode::Blocking);
match status {
UpdateStatus::Invalid => break,
UpdateStatus::CommittingChanges => break,
steamworks::UpdateStatus::Invalid => break,
steamworks::UpdateStatus::CommittingChanges => break,
_ => (),
}
std::thread::sleep(std::time::Duration::from_millis(
Expand Down

0 comments on commit f2f27d3

Please sign in to comment.