mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 18:25:34 +01:00
Language packs: fmt, a Status struct for clippy, std Result in the tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
44afcbfb2a
commit
fef393ddc0
4 files changed
+28
-11
No files matched your search
@@ -65,6 +65,8 @@ pub(crate) mod objects_on_path;
|
||||
mod opacitymask;
|
||||
mod overprint;
|
||||
pub mod package;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod packs;
|
||||
mod paint;
|
||||
mod panelcmds;
|
||||
pub mod params;
|
||||
@@ -92,8 +94,6 @@ pub(crate) mod shaper;
|
||||
pub mod shortcutset;
|
||||
pub(crate) mod slices;
|
||||
pub mod spelling;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub mod packs;
|
||||
mod stroke;
|
||||
mod style;
|
||||
pub use style::styled_node;
|
||||
|
||||
@@ -67,7 +67,7 @@ fn list(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let (installing, refreshing, errors) = packs::status();
|
||||
let packs::Status { installing, refreshing, errors } = packs::status();
|
||||
// An install that ended since the last frame shows in every document's layout.
|
||||
s.poll_language_packs();
|
||||
Ok(json!({
|
||||
|
||||
@@ -154,11 +154,24 @@ pub fn available() -> Vec<Pack> {
|
||||
backend().map(|b| b.cached_index()).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// What `proof.packs` reports about the jobs: the installs running as (locale, done, total), whether
|
||||
/// the index is being fetched, and the last error of each locale (`""`: the index).
|
||||
pub fn status() -> (Vec<(String, u64, u64)>, bool, BTreeMap<String, String>) {
|
||||
/// What `proof.packs` reports about the jobs.
|
||||
pub struct Status {
|
||||
/// The installs running, as (locale, bytes done, bytes in all).
|
||||
pub installing: Vec<(String, u64, u64)>,
|
||||
/// Whether the index is being fetched.
|
||||
pub refreshing: bool,
|
||||
/// The last error of each locale (`""`: the index fetch).
|
||||
pub errors: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// The jobs running and the last errors.
|
||||
pub fn status() -> Status {
|
||||
let j = jobs();
|
||||
(j.installing.iter().map(|(l, job)| (l.clone(), job.done, job.total)).collect(), j.refreshing.is_some(), j.errors.clone())
|
||||
Status {
|
||||
installing: j.installing.iter().map(|(l, job)| (l.clone(), job.done, job.total)).collect(),
|
||||
refreshing: j.refreshing.is_some(),
|
||||
errors: j.errors.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// What an install or a fetch did.
|
||||
@@ -176,7 +189,11 @@ fn run(f: impl FnOnce() + Send + 'static) -> Result<Outcome, String> {
|
||||
f();
|
||||
return Ok(Outcome::Done);
|
||||
}
|
||||
std::thread::Builder::new().name("language-pack".into()).spawn(f).map(|_| Outcome::Started).map_err(|e| format!("couldn't start the download: {e}"))
|
||||
std::thread::Builder::new()
|
||||
.name("language-pack".into())
|
||||
.spawn(f)
|
||||
.map(|_| Outcome::Started)
|
||||
.map_err(|e| format!("couldn't start the download: {e}"))
|
||||
}
|
||||
|
||||
/// Fetches the pinned pack index again. Needs downloads on.
|
||||
|
||||
@@ -119,11 +119,11 @@ impl Backend for Fake {
|
||||
vec![nl]
|
||||
}
|
||||
|
||||
fn fetch_index(&self, _: &Cancel) -> Result<Vec<Pack>, String> {
|
||||
fn fetch_index(&self, _: &Cancel) -> std::result::Result<Vec<Pack>, String> {
|
||||
Ok(self.cached_index())
|
||||
}
|
||||
|
||||
fn install(&self, locale: &str, cancel: &Cancel, progress: &mut dyn FnMut(u64, u64)) -> Result<(), String> {
|
||||
fn install(&self, locale: &str, cancel: &Cancel, progress: &mut dyn FnMut(u64, u64)) -> std::result::Result<(), String> {
|
||||
progress(1, 2);
|
||||
while self.hold.load(Ordering::Relaxed) {
|
||||
if cancel.is_cancelled() {
|
||||
@@ -139,7 +139,7 @@ impl Backend for Fake {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove(&self, locale: &str) -> Result<(), String> {
|
||||
fn remove(&self, locale: &str) -> std::result::Result<(), String> {
|
||||
std::fs::remove_dir_all(self.dir.join(locale)).map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user