mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Stop requesting persistent storage
This commit is contained in:
@@ -20,7 +20,6 @@ struct Inner {
|
||||
on_disk: HashSet<ResourceHash>,
|
||||
queue: VecDeque<Mutation>,
|
||||
worker_active: bool,
|
||||
persist_requested: bool,
|
||||
}
|
||||
|
||||
pub struct OpfsResourceStorage {
|
||||
@@ -43,7 +42,6 @@ impl OpfsResourceStorage {
|
||||
on_disk,
|
||||
queue: VecDeque::new(),
|
||||
worker_active: false,
|
||||
persist_requested: false,
|
||||
})),
|
||||
})
|
||||
}
|
||||
@@ -130,25 +128,16 @@ fn kick_worker(inner: &Arc<Mutex<Inner>>, guard: &mut Inner) {
|
||||
|
||||
async fn drain_queue(inner: Arc<Mutex<Inner>>) {
|
||||
loop {
|
||||
let (directory, mutation, persist_requested) = {
|
||||
let (directory, mutation) = {
|
||||
let mut guard = inner.lock().unwrap();
|
||||
let Some(mutation) = guard.queue.pop_front() else {
|
||||
guard.worker_active = false;
|
||||
return;
|
||||
};
|
||||
|
||||
let persist_requested = matches!(mutation, Mutation::Write { .. }) && !guard.persist_requested;
|
||||
if persist_requested {
|
||||
guard.persist_requested = true;
|
||||
}
|
||||
|
||||
(guard.directory.clone(), mutation, persist_requested)
|
||||
(guard.directory.clone(), mutation)
|
||||
};
|
||||
|
||||
if persist_requested {
|
||||
request_persistence().await;
|
||||
}
|
||||
|
||||
match mutation {
|
||||
Mutation::Write { hash, bytes } => {
|
||||
if let Err(error) = write_file(&directory, &hash, &bytes).await {
|
||||
@@ -164,23 +153,6 @@ async fn drain_queue(inner: Arc<Mutex<Inner>>) {
|
||||
}
|
||||
}
|
||||
|
||||
async fn request_persistence() {
|
||||
let Some(window) = web_sys::window() else {
|
||||
log::warn!("OPFS persist() skipped: no window");
|
||||
return;
|
||||
};
|
||||
let storage = window.navigator().storage();
|
||||
|
||||
match storage.persist() {
|
||||
Ok(promise) => match JsFuture::from(promise).await {
|
||||
Ok(value) if value.as_bool() == Some(true) => {}
|
||||
Ok(_) => log::warn!("OPFS persistence was not granted; browser may evict resources under storage pressure"),
|
||||
Err(error) => log::warn!("OPFS persist() rejected: {error:?}"),
|
||||
},
|
||||
Err(error) => log::warn!("OPFS persist() threw: {error:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
async fn open_resource_directory(directory_name: &str) -> Result<FileSystemDirectoryHandle, JsValue> {
|
||||
let storage = web_sys::window().ok_or_else(|| JsValue::from_str("no window"))?.navigator().storage();
|
||||
let root: FileSystemDirectoryHandle = JsFuture::from(storage.get_directory()).await?.dyn_into()?;
|
||||
|
||||
Reference in New Issue
Block a user