cache media and fix mac workflow (#1179)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

Fixes #

#### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
7w1 authored and GitHub committed 2026-07-21 11:49:37 -05:00
commit 4773ee2399
2 files changed
+36 -11

No files matched your search

+12 -3
View File
@@ -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 \
+24 -8
View File
@@ -700,6 +700,25 @@ function fetchConfig(token: string): RequestInit {
};
}
const inflightMediaFetches = new Map<string, Promise<Response>>();
function respondWithInflightMedia(
url: string,
token: string,
redirect: RequestRedirect
): Promise<Response> {
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',