mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-23 19:37:52 +00:00
fix bug
This commit is contained in:
parent
b665d229f3
commit
abb9eea4c4
@ -105,7 +105,7 @@ import { useRecoilState, useResetRecoilState, useSetRecoilState } from "recoil";
|
|||||||
import { canSaveSettingToQdnAtom, fullScreenAtom, hasSettingsChangedAtom, oldPinnedAppsAtom, settingsLocalLastUpdatedAtom, settingsQDNLastUpdatedAtom, sortablePinnedAppsAtom } from "./atoms/global";
|
import { canSaveSettingToQdnAtom, fullScreenAtom, hasSettingsChangedAtom, oldPinnedAppsAtom, settingsLocalLastUpdatedAtom, settingsQDNLastUpdatedAtom, sortablePinnedAppsAtom } from "./atoms/global";
|
||||||
import { useAppFullScreen } from "./useAppFullscreen";
|
import { useAppFullScreen } from "./useAppFullscreen";
|
||||||
import { NotAuthenticated } from "./ExtStates/NotAuthenticated";
|
import { NotAuthenticated } from "./ExtStates/NotAuthenticated";
|
||||||
import { sendMessageBackground, sendMessageState } from "./messaging/messagesToBackground";
|
|
||||||
|
|
||||||
type extStates =
|
type extStates =
|
||||||
| "not-authenticated"
|
| "not-authenticated"
|
||||||
|
@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import ReactDOM from 'react-dom/client'
|
import ReactDOM from 'react-dom/client'
|
||||||
import App from './App.tsx'
|
import App from './App.tsx'
|
||||||
import './index.css'
|
import './index.css'
|
||||||
|
import "./messaging/messagesToBackground";
|
||||||
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
||||||
import { CssBaseline } from '@mui/material';
|
import { CssBaseline } from '@mui/material';
|
||||||
import { MessageQueueProvider } from './MessageQueueContext.tsx';
|
import { MessageQueueProvider } from './MessageQueueContext.tsx';
|
||||||
|
@ -28,27 +28,30 @@ window.addEventListener("message", (event) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Define the sendMessage function
|
|
||||||
export const sendMessageBackground = (action, data = {}, timeout = 60000) => {
|
export const sendMessageBackground = (action, data = {}, timeout = 60000) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestId = generateRequestId(); // Unique ID for each request
|
const requestId = generateRequestId(); // Unique ID for each request
|
||||||
callbackMap.set(requestId, { resolve }); // Store resolve callback only
|
callbackMap.set(requestId, { resolve, reject }); // Store both resolve and reject callbacks
|
||||||
|
|
||||||
// Send the message with `backgroundMessage` type
|
// Send the message with `backgroundMessage` type
|
||||||
window.postMessage({ type: "backgroundMessage", action, requestId, payload: data }, "*");
|
window.postMessage({ type: "backgroundMessage", action, requestId, payload: data }, "*");
|
||||||
|
|
||||||
// Set up a timeout to automatically resolve with an error if no response is received
|
// Set up a timeout to automatically reject if no response is received
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
// Remove the callback to prevent memory leaks
|
// Remove the callback to prevent memory leaks
|
||||||
callbackMap.delete(requestId);
|
callbackMap.delete(requestId);
|
||||||
resolve({ error: "timeout", message: `Request timed out after ${timeout} ms` });
|
reject({ error: "timeout", message: `Request timed out after ${timeout} ms` });
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
||||||
// Adjust resolve to clear the timeout when a response arrives
|
// Adjust resolve/reject to clear the timeout when a response arrives
|
||||||
callbackMap.set(requestId, {
|
callbackMap.set(requestId, {
|
||||||
resolve: (response) => {
|
resolve: (response) => {
|
||||||
clearTimeout(timeoutId); // Clear the timeout if the response is received in time
|
clearTimeout(timeoutId); // Clear the timeout if the response is received in time
|
||||||
resolve(response);
|
resolve(response);
|
||||||
|
},
|
||||||
|
reject: (error) => {
|
||||||
|
clearTimeout(timeoutId); // Clear the timeout if an error occurs
|
||||||
|
reject(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
@ -61,6 +64,5 @@ export const sendMessageBackground = (action, data = {}, timeout = 60000) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Attach to window for global access
|
||||||
|
window.sendMessage = sendMessageBackground;
|
||||||
window.sendMessage = sendMessageBackground;
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user