mirror of
https://github.com/actualbudget/actual.git
synced 2026-05-10 05:50:49 -05:00
🐛 Fix error modal not showing when in non-secure context (#4499)
* init when not ssl * bringing it all back * huh * race conditions.... * release notes * remove unneeded console log
This commit is contained in:
@@ -36,11 +36,28 @@ const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => {
|
||||
}
|
||||
};
|
||||
|
||||
const RECONNECT_INTERVAL_MS = 200;
|
||||
const MAX_RECONNECT_ATTEMPTS = 500;
|
||||
let reconnectAttempts = 0;
|
||||
|
||||
const postMessageWithRetry = message => {
|
||||
const reconnectToClientInterval = setInterval(() => {
|
||||
self.postMessage(message);
|
||||
|
||||
reconnectAttempts++;
|
||||
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||
clearInterval(reconnectToClientInterval);
|
||||
}
|
||||
}, RECONNECT_INTERVAL_MS);
|
||||
|
||||
return reconnectToClientInterval;
|
||||
};
|
||||
|
||||
let appInitFailureInterval;
|
||||
self.addEventListener('message', async event => {
|
||||
try {
|
||||
const msg = event.data;
|
||||
if (!hasInitialized) {
|
||||
const msg = event.data;
|
||||
|
||||
if (msg.type === 'init') {
|
||||
hasInitialized = true;
|
||||
const isDev = !!msg.isDev;
|
||||
@@ -51,10 +68,11 @@ self.addEventListener('message', async event => {
|
||||
!self.SharedArrayBuffer &&
|
||||
!msg.isSharedArrayBufferOverrideEnabled
|
||||
) {
|
||||
self.postMessage({
|
||||
appInitFailureInterval = postMessageWithRetry({
|
||||
type: 'app-init-failure',
|
||||
SharedArrayBufferMissing: true,
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,19 +83,23 @@ self.addEventListener('message', async event => {
|
||||
|
||||
backend.initApp(isDev, self).catch(err => {
|
||||
console.log(err);
|
||||
const msg = {
|
||||
appInitFailureInterval = postMessageWithRetry({
|
||||
type: 'app-init-failure',
|
||||
IDBFailure: err.message.includes('indexeddb-failure'),
|
||||
};
|
||||
self.postMessage(msg);
|
||||
});
|
||||
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.name === '__app-init-failure-acknowledged') {
|
||||
// Clear the interval if the client has acknowledged the failure, otherwise keep retrying
|
||||
clearInterval(appInitFailureInterval);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('Failed initializing backend:', error);
|
||||
self.postMessage({
|
||||
appInitFailureInterval = postMessageWithRetry({
|
||||
type: 'app-init-failure',
|
||||
BackendInitFailure: true,
|
||||
});
|
||||
|
||||
@@ -127,9 +127,9 @@ function AppInner() {
|
||||
}
|
||||
|
||||
initAll().catch(showErrorBoundary);
|
||||
// Removed cloudFileId from dependencies to prevent hard crash when closing budget in Electron
|
||||
// Removed cloudFileId & t from dependencies to prevent hard crash when closing budget in Electron
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [dispatch, showErrorBoundary, t]);
|
||||
}, [dispatch, showErrorBoundary]);
|
||||
|
||||
useEffect(() => {
|
||||
global.Actual.updateAppMenu(budgetId);
|
||||
|
||||
@@ -107,6 +107,9 @@ function connectWorker(worker, onOpen, onError) {
|
||||
});
|
||||
onOpen();
|
||||
} else if (msg.type === 'app-init-failure') {
|
||||
globalWorker.postMessage({
|
||||
name: '__app-init-failure-acknowledged',
|
||||
});
|
||||
onError(msg);
|
||||
} else if (msg.type === 'capture-exception') {
|
||||
captureException(
|
||||
|
||||
@@ -110,7 +110,7 @@ export const init: T.Init = function (serverChn, handlers) {
|
||||
let reconnectAttempts = 0;
|
||||
|
||||
const reconnectToClientInterval = setInterval(() => {
|
||||
console.info('Backend: Atempting to connect to client');
|
||||
console.info('Backend: Trying to connect to client');
|
||||
serverChannel.postMessage({ type: 'connect' });
|
||||
reconnectAttempts++;
|
||||
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
||||
|
||||
6
upcoming-release-notes/4499.md
Normal file
6
upcoming-release-notes/4499.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [MikesGlitch]
|
||||
---
|
||||
|
||||
Fixed error modal not showing when using non-secure context
|
||||
Reference in New Issue
Block a user