From e566db3074489a96991a93873de6bc81b07dad57 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Tue, 21 Jul 2026 11:43:41 -0500 Subject: [PATCH] cahce media and fix mac workflow --- .github/workflows/tauri-build.yml | 15 ++++++++++++--- src/sw.ts | 32 +++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tauri-build.yml b/.github/workflows/tauri-build.yml index 48c429698..b9cad9c95 100644 --- a/.github/workflows/tauri-build.yml +++ b/.github/workflows/tauri-build.yml @@ -122,16 +122,19 @@ jobs: asset-platform: macos-universal rust-targets: aarch64-apple-darwin,x86_64-apple-darwin args: --target universal-apple-darwin + bundle_path: src-tauri/target/universal-apple-darwin/release/bundle - name: Windows platform: windows-latest asset-platform: windows-x86_64 rust-targets: '' args: '' + bundle_path: src-tauri/target/release/bundle - name: Linux (CEF) platform: ubuntu-22.04 asset-platform: linux-x86_64 rust-targets: '' cef: true + bundle_path: src-tauri/target/release/bundle env: TAG: ${{ needs.setup-release.outputs.tag }} VERSION: ${{ needs.setup-release.outputs.version }} @@ -218,8 +221,10 @@ jobs: shell: bash env: ASSET_PLATFORM: ${{ matrix.asset-platform }} + BUNDLE_PATH: ${{ matrix.bundle_path }} run: | - find src-tauri/target/release/bundle -type f -print0 \ + test -d "$BUNDLE_PATH" || { echo "Bundle directory not found: $BUNDLE_PATH" >&2; exit 1; } + find "$BUNDLE_PATH" -type f -print0 \ | while IFS= read -r -d '' path; do case "$path" in *.app.tar.gz.sig) suffix='.app.tar.gz.sig' ;; @@ -252,8 +257,10 @@ jobs: shell: bash env: GH_TOKEN: ${{ github.token }} + BUNDLE_PATH: ${{ matrix.bundle_path }} run: | - find src-tauri/target/release/bundle -type f -name 'Sable-*' -print0 \ + test -d "$BUNDLE_PATH" || { echo "Bundle directory not found: $BUNDLE_PATH" >&2; exit 1; } + find "$BUNDLE_PATH" -type f -name 'Sable-*' -print0 \ | while IFS= read -r -d '' path; do echo "Uploading $path" gh release upload "$TAG" "$path" --clobber @@ -294,8 +301,10 @@ jobs: shell: bash env: GH_TOKEN: ${{ github.token }} + BUNDLE_PATH: ${{ matrix.bundle_path }} run: | - BUNDLE="src-tauri/target/release/bundle" + BUNDLE="$BUNDLE_PATH" + test -d "$BUNDLE" || { echo "Bundle directory not found: $BUNDLE" >&2; exit 1; } for f in "$BUNDLE"/deb/Sable-*-linux-x86_64.deb \ "$BUNDLE"/rpm/Sable-*-linux-x86_64.rpm \ "$BUNDLE"/appimage/Sable-*-linux-x86_64.AppImage \ diff --git a/src/sw.ts b/src/sw.ts index ac3b9720b..ca56d182a 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -700,6 +700,25 @@ function fetchConfig(token: string): RequestInit { }; } +const inflightMediaFetches = new Map>(); + +function respondWithInflightMedia( + url: string, + token: string, + redirect: RequestRedirect +): Promise { + const key = `${token}\x00${url}\x00${redirect}`; + const existing = inflightMediaFetches.get(key); + if (existing) { + return existing.then((res) => res.clone()); + } + const promise = fetch(url, { ...fetchConfig(token), redirect }).finally(() => { + inflightMediaFetches.delete(key); + }); + inflightMediaFetches.set(key, promise); + return promise; +} + self.addEventListener('message', (event: ExtendableMessageEvent) => { if (event.data.type === 'togglePush') { const token = event.data?.token; @@ -749,7 +768,7 @@ self.addEventListener('fetch', (event: FetchEvent) => { const session = clientId ? sessions.get(clientId) : undefined; if (session && validMediaRequest(url, session.baseUrl)) { - event.respondWith(fetch(url, { ...fetchConfig(session.accessToken), redirect })); + event.respondWith(respondWithInflightMedia(url, session.accessToken, redirect)); return; } @@ -769,7 +788,7 @@ self.addEventListener('fetch', (event: FetchEvent) => { ? preloadedSession : undefined); if (byBaseUrl) { - event.respondWith(fetch(url, { ...fetchConfig(byBaseUrl.accessToken), redirect })); + event.respondWith(respondWithInflightMedia(url, byBaseUrl.accessToken, redirect)); return; } @@ -779,10 +798,7 @@ self.addEventListener('fetch', (event: FetchEvent) => { event.respondWith( loadPersistedSession().then((persisted) => { if (persisted && validMediaRequest(url, persisted.baseUrl)) { - return fetch(url, { - ...fetchConfig(persisted.accessToken), - redirect, - }); + return respondWithInflightMedia(url, persisted.accessToken, redirect); } return fetch(event.request); }) @@ -794,13 +810,13 @@ self.addEventListener('fetch', (event: FetchEvent) => { requestSessionWithTimeout(clientId).then(async (s) => { // Primary: session received from the live client window. if (s && validMediaRequest(url, s.baseUrl)) { - return fetch(url, { ...fetchConfig(s.accessToken), redirect }); + return respondWithInflightMedia(url, s.accessToken, redirect); } // Fallback: try the persisted session (helps when SW restarts on iOS and // the client window hasn't responded to requestSession yet). const persisted = await loadPersistedSession(); if (persisted && validMediaRequest(url, persisted.baseUrl)) { - return fetch(url, { ...fetchConfig(persisted.accessToken), redirect }); + return respondWithInflightMedia(url, persisted.accessToken, redirect); } console.warn( '[SW fetch] No valid session for media request',