Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cdee73542 | |||
| e8ba8ffdba | |||
| 52298d1d46 |
@@ -10,14 +10,21 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with: { node-version: 20 }
|
||||
- name: Cache npm
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'npm'
|
||||
cache-dependency-path: 'web/package-lock.json'
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-npm-${{ hashFiles('web/package-lock.json') }}
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: Cache Rust target and registry
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
workspaces: 'web/src-tauri'
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
web/src-tauri/target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('web/src-tauri/Cargo.lock') }}
|
||||
- name: Install system deps
|
||||
run: sudo apt-get update && sudo apt-get install -y libwebkit2gtk-4.1-dev libgtk-3-dev libappindicator3-dev librsvg2-dev patchelf rpm
|
||||
- name: Build frontend
|
||||
@@ -40,10 +47,12 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with: { node-version: 20 }
|
||||
- name: Cache npm
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
node-version: 20
|
||||
cache: 'npm'
|
||||
cache-dependency-path: 'web/package-lock.json'
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-npm-${{ hashFiles('web/package-lock.json') }}
|
||||
- name: Install Rust
|
||||
run: |
|
||||
curl.exe -sLo rustup-init.exe https://win.rustup.rs/x86_64
|
||||
@@ -51,9 +60,14 @@ jobs:
|
||||
set PATH=%USERPROFILE%\.cargo\bin;%PATH%
|
||||
rustc --version
|
||||
shell: cmd
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: Cache Rust target and registry
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
workspaces: 'web/src-tauri'
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
web/src-tauri/target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('web/src-tauri/Cargo.lock') }}
|
||||
- name: Build frontend
|
||||
run: cd web && npm ci && npm run build
|
||||
shell: cmd
|
||||
|
||||
+10
-1
@@ -60,11 +60,20 @@
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
<script>
|
||||
// Register service worker
|
||||
// Register service worker (only for web, avoid in Tauri to prevent 404 cache bugs)
|
||||
if ('serviceWorker' in navigator) {
|
||||
if (!('__TAURI_INTERNALS__' in window) && !('__TAURI__' in window)) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/sw.js').catch(() => {});
|
||||
});
|
||||
} else {
|
||||
// In Tauri, aggressively unregister any old service workers that might be causing 404s
|
||||
navigator.serviceWorker.getRegistrations().then((registrations) => {
|
||||
for (let registration of registrations) {
|
||||
registration.unregister();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -3,6 +3,35 @@ import { createRoot } from 'react-dom/client';
|
||||
import './styles/index.css';
|
||||
import App from './App.tsx';
|
||||
|
||||
const isTauri = 'window' in globalThis && '__TAURI_INTERNALS__' in window;
|
||||
if (isTauri) {
|
||||
const TARGET = 'https://dumpster.dustin.coffee';
|
||||
const WS_TARGET = 'wss://dumpster.dustin.coffee';
|
||||
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = async (input, init) => {
|
||||
if (typeof input === 'string' && input.startsWith('/')) {
|
||||
input = TARGET + input;
|
||||
}
|
||||
return originalFetch(input, init);
|
||||
};
|
||||
|
||||
const OriginalWebSocket = window.WebSocket;
|
||||
window.WebSocket = function(url: string | URL, protocols?: string | string[]) {
|
||||
let urlStr = typeof url === 'string' ? url : url.toString();
|
||||
if (urlStr.includes('tauri.localhost') || urlStr.includes('tauri://localhost')) {
|
||||
urlStr = urlStr.replace(/^(wss?|https?|tauri):\/\/tauri\.localhost/, WS_TARGET);
|
||||
urlStr = urlStr.replace(/^tauri:\/\/localhost/, WS_TARGET);
|
||||
} else if (urlStr.startsWith('ws://localhost') && isTauri) {
|
||||
urlStr = urlStr.replace('ws://localhost', WS_TARGET);
|
||||
} else if (urlStr.startsWith('/')) {
|
||||
urlStr = WS_TARGET + urlStr;
|
||||
}
|
||||
return new OriginalWebSocket(urlStr, protocols);
|
||||
} as unknown as typeof WebSocket;
|
||||
window.WebSocket.prototype = OriginalWebSocket.prototype;
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
|
||||
Reference in New Issue
Block a user