mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Fix corrupted font resource loading in older documents
This commit is contained in:
@@ -153,6 +153,9 @@ async fn drain_queue(inner: Arc<Mutex<Inner>>) {
|
||||
Mutation::Write { hash, bytes } => {
|
||||
if let Err(error) = write_file(&directory, &hash, &bytes).await {
|
||||
log::error!("OPFS write for {hash} failed: {error:?}");
|
||||
|
||||
// Nothing reached disk, so leaving the hash listed would claim a file that later sessions cannot read
|
||||
inner.lock().unwrap().on_disk.remove(&hash);
|
||||
}
|
||||
}
|
||||
Mutation::Delete { hash } => {
|
||||
|
||||
@@ -269,8 +269,19 @@ pub async fn resource<'a: 'n>(
|
||||
hash: Item<ResourceHash>,
|
||||
) -> Item<Resource> {
|
||||
let hash = hash.into_element();
|
||||
let application_io = editor_api.into_element().application_io.as_ref().expect("ApplicationIo must be available when using resources");
|
||||
let resource = application_io.load_resource(hash).await.unwrap_or_else(|| panic!("Resource {hash} not found"));
|
||||
let placeholder = || -> Item<Resource> { Item::new_from_element(Resource::empty()) };
|
||||
|
||||
let Some(application_io) = editor_api.into_element().application_io.as_ref() else {
|
||||
log::error!("Resource {hash} is unavailable because the platform's application IO is missing");
|
||||
return placeholder();
|
||||
};
|
||||
|
||||
// Stored bytes go missing when the browser evicts its storage or a write is interrupted
|
||||
let Some(resource) = application_io.load_resource(hash).await else {
|
||||
log::error!("Resource {hash} was not found in storage");
|
||||
return placeholder();
|
||||
};
|
||||
|
||||
Item::new_from_element(resource)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user