diff --git a/.changeset/media-session-wait.md b/.changeset/media-session-wait.md
new file mode 100644
index 0000000000..a504910d4c
--- /dev/null
+++ b/.changeset/media-session-wait.md
@@ -0,0 +1,5 @@
+---
+default: patch
+---
+
+Fix media failing to load until a view is reopened, and load sticker grids faster.
diff --git a/src-tauri/src/network/media_protocol.rs b/src-tauri/src/network/media_protocol.rs
index fa04588f59..cc58a5592f 100644
--- a/src-tauri/src/network/media_protocol.rs
+++ b/src-tauri/src/network/media_protocol.rs
@@ -3,7 +3,10 @@ use std::{
fs,
io::{Read, Seek, SeekFrom},
path::{Path, PathBuf},
- sync::{Arc, Mutex, OnceLock, RwLock, Weak},
+ sync::{
+ atomic::{AtomicBool, Ordering},
+ Arc, Mutex, OnceLock, RwLock, Weak,
+ },
time::Duration,
};
@@ -20,7 +23,10 @@ use tauri_plugin_http::reqwest::{
header::{AUTHORIZATION, CONTENT_TYPE},
Client, Url,
};
-use tokio::sync::{Mutex as AsyncMutex, Semaphore};
+use tokio::{
+ sync::{Mutex as AsyncMutex, Notify, Semaphore},
+ time::{timeout_at, Instant},
+};
pub const MEDIA_URI_SCHEME: &str = "sable-media";
@@ -37,7 +43,10 @@ const CACHE_SUBDIR: &str = "sable-media";
const READ_TIMEOUT: Duration = Duration::from_secs(30);
const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
const MAX_CONCURRENT_THUMBNAIL_REQUESTS: usize = 4;
-const MAX_CONCURRENT_DOWNLOAD_REQUESTS: usize = 2;
+const MAX_CONCURRENT_DOWNLOAD_REQUESTS: usize = 6;
+// The frontend mounts (and starts requesting media) before it hands us the session, so a request
+// may arrive first. `
` never retries, so waiting beats answering 503.
+const SESSION_WAIT: Duration = Duration::from_secs(5);
const MAX_CACHE_BYTES: u64 = 512 * 1024 * 1024;
const MAX_RANGE_CHUNK: u64 = 2 * 1024 * 1024;
@@ -48,6 +57,8 @@ type FetchResult = Result<(String, Option>>, PathBuf), StatusCode>;
pub struct MediaSessionState {
inner: RwLock