mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-03-31 01:35:54 +00:00
change targetOrigin
This commit is contained in:
parent
c541f5731d
commit
1f1387f141
@ -329,9 +329,10 @@ async function checkWebviewFocus() {
|
|||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
resolve(false); // No response within 1 second, assume not focused
|
resolve(false); // No response within 1 second, assume not focused
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
// Send a message to check focus
|
// Send a message to check focus
|
||||||
window.postMessage({ action: "CHECK_FOCUS" }, "*");
|
window.postMessage({ action: "CHECK_FOCUS" }, targetOrigin);
|
||||||
|
|
||||||
// Listen for the response
|
// Listen for the response
|
||||||
const handleMessage = (event) => {
|
const handleMessage = (event) => {
|
||||||
@ -1277,14 +1278,16 @@ const getStoredData = async (key) => {
|
|||||||
|
|
||||||
export async function handleActiveGroupDataFromSocket({ groups, directs }) {
|
export async function handleActiveGroupDataFromSocket({ groups, directs }) {
|
||||||
try {
|
try {
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
window.postMessage({
|
window.postMessage({
|
||||||
action: "SET_GROUPS",
|
action: "SET_GROUPS",
|
||||||
payload: groups,
|
payload: groups,
|
||||||
}, "*");
|
}, targetOrigin);
|
||||||
window.postMessage({
|
window.postMessage({
|
||||||
action: "SET_DIRECTS",
|
action: "SET_DIRECTS",
|
||||||
payload: directs,
|
payload: directs,
|
||||||
}, "*");
|
}, targetOrigin);
|
||||||
|
|
||||||
groups = groups;
|
groups = groups;
|
||||||
directs = directs;
|
directs = directs;
|
||||||
@ -2949,11 +2952,13 @@ export const checkNewMessages = async () => {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
const savedtimestampAfter = await getTimestampGroupAnnouncement();
|
const savedtimestampAfter = await getTimestampGroupAnnouncement();
|
||||||
window.postMessage({
|
window.postMessage({
|
||||||
action: "SET_GROUP_ANNOUNCEMENTS",
|
action: "SET_GROUP_ANNOUNCEMENTS",
|
||||||
payload: savedtimestampAfter,
|
payload: savedtimestampAfter,
|
||||||
}, "*");
|
}, targetOrigin);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
@ -3098,10 +3103,12 @@ export const checkThreads = async (bringBack) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const savedtimestampAfter = await getTimestampGroupAnnouncement();
|
const savedtimestampAfter = await getTimestampGroupAnnouncement();
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
window.postMessage({
|
window.postMessage({
|
||||||
action: "SET_GROUP_ANNOUNCEMENTS",
|
action: "SET_GROUP_ANNOUNCEMENTS",
|
||||||
payload: savedtimestampAfter,
|
payload: savedtimestampAfter,
|
||||||
}, "*");
|
}, targetOrigin);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
@ -3141,16 +3148,17 @@ LocalNotifications.addListener('localNotificationActionPerformed', async (event)
|
|||||||
const type = extraData?.type;
|
const type = extraData?.type;
|
||||||
const from = extraData?.from;
|
const from = extraData?.from;
|
||||||
|
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
// Determine notification type based on `type` field
|
// Determine notification type based on `type` field
|
||||||
if (type === 'direct') {
|
if (type === 'direct') {
|
||||||
window.postMessage({ action: "NOTIFICATION_OPEN_DIRECT", payload: { from } }, "*");
|
window.postMessage({ action: "NOTIFICATION_OPEN_DIRECT", payload: { from } }, targetOrigin);
|
||||||
} else if (type === 'group') {
|
} else if (type === 'group') {
|
||||||
window.postMessage({ action: "NOTIFICATION_OPEN_GROUP", payload: { from } }, "*");
|
window.postMessage({ action: "NOTIFICATION_OPEN_GROUP", payload: { from } }, targetOrigin);
|
||||||
} else if (type === 'group-announcement') {
|
} else if (type === 'group-announcement') {
|
||||||
window.postMessage({ action: "NOTIFICATION_OPEN_ANNOUNCEMENT_GROUP", payload: { from } }, "*");
|
window.postMessage({ action: "NOTIFICATION_OPEN_ANNOUNCEMENT_GROUP", payload: { from } }, targetOrigin);
|
||||||
} else if (type === 'thread-post') {
|
} else if (type === 'thread-post') {
|
||||||
window.postMessage({ action: "NOTIFICATION_OPEN_THREAD_NEW_POST", payload: { data: extraData?.data } }, "*");
|
window.postMessage({ action: "NOTIFICATION_OPEN_THREAD_NEW_POST", payload: { data: extraData?.data } }, targetOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear all notifications
|
// Clear all notifications
|
||||||
|
@ -49,10 +49,10 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
|||||||
// Calculate the previous index and path
|
// Calculate the previous index and path
|
||||||
const previousPageIndex = history.currentIndex - 1;
|
const previousPageIndex = history.currentIndex - 1;
|
||||||
const previousPath = history.customQDNHistoryPaths[previousPageIndex];
|
const previousPath = history.customQDNHistoryPaths[previousPageIndex];
|
||||||
|
const targetOrigin = iframeRef.current ? new URL(iframeRef.current.src).origin : "*";
|
||||||
// Signal non-manual navigation
|
// Signal non-manual navigation
|
||||||
iframeRef.current.contentWindow.postMessage(
|
iframeRef.current.contentWindow.postMessage(
|
||||||
{ action: 'PERFORMING_NON_MANUAL', currentIndex: previousPageIndex }, '*'
|
{ action: 'PERFORMING_NON_MANUAL', currentIndex: previousPageIndex }, targetOrigin
|
||||||
);
|
);
|
||||||
// Update the current index locally
|
// Update the current index locally
|
||||||
changeCurrentIndex(previousPageIndex);
|
changeCurrentIndex(previousPageIndex);
|
||||||
@ -73,10 +73,10 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
|||||||
window.removeEventListener('message', handleNavigationSuccess);
|
window.removeEventListener('message', handleNavigationSuccess);
|
||||||
reject(new Error("Navigation timeout"));
|
reject(new Error("Navigation timeout"));
|
||||||
}, 200);
|
}, 200);
|
||||||
|
const targetOrigin = iframeRef.current ? new URL(iframeRef.current.src).origin : "*";
|
||||||
// Send the navigation command after setting up the listener and timeout
|
// Send the navigation command after setting up the listener and timeout
|
||||||
iframeRef.current.contentWindow.postMessage(
|
iframeRef.current.contentWindow.postMessage(
|
||||||
{ action: 'NAVIGATE_TO_PATH', path: previousPath, requestedHandler: 'UI' }, '*'
|
{ action: 'NAVIGATE_TO_PATH', path: previousPath, requestedHandler: 'UI' }, targetOrigin
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -111,11 +111,11 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
|||||||
// Function to navigate back in iframe
|
// Function to navigate back in iframe
|
||||||
const navigateForwardInIframe = async () => {
|
const navigateForwardInIframe = async () => {
|
||||||
|
|
||||||
|
const targetOrigin = iframeRef.current ? new URL(iframeRef.current.src).origin : "*";
|
||||||
if (iframeRef.current && iframeRef.current.contentWindow) {
|
if (iframeRef.current && iframeRef.current.contentWindow) {
|
||||||
iframeRef.current.contentWindow.postMessage(
|
iframeRef.current.contentWindow.postMessage(
|
||||||
{ action: 'NAVIGATE_FORWARD'},
|
{ action: 'NAVIGATE_FORWARD'},
|
||||||
'*'
|
targetOrigin
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log('Iframe not accessible or does not have a content window.');
|
console.log('Iframe not accessible or does not have a content window.');
|
||||||
|
@ -531,10 +531,11 @@ isDOMContentLoaded: false
|
|||||||
executeEvent("addTab", {
|
executeEvent("addTab", {
|
||||||
data: event?.data?.payload
|
data: event?.data?.payload
|
||||||
})
|
})
|
||||||
|
const targetOrigin = iframeRef.current ? new URL(iframeRef.current.src).origin : "*";
|
||||||
iframeRef.current.contentWindow.postMessage(
|
iframeRef.current.contentWindow.postMessage(
|
||||||
{ action: 'SET_TAB_SUCCESS', requestedHandler: 'UI',payload: {
|
{ action: 'SET_TAB_SUCCESS', requestedHandler: 'UI',payload: {
|
||||||
name: event?.data?.payload?.name
|
name: event?.data?.payload?.name
|
||||||
} }, '*'
|
} }, targetOrigin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,9 +28,10 @@ export const sendMessageBackground = (action, data = {}, timeout = 60000, isExte
|
|||||||
return new Promise((resolve, reject) => {
|
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, reject }); // Store both resolve and reject callbacks
|
callbackMap.set(requestId, { resolve, reject }); // Store both resolve and reject callbacks
|
||||||
|
const targetOrigin = window.location.origin
|
||||||
|
|
||||||
// Send the message with `backgroundMessage` type
|
// Send the message with `backgroundMessage` type
|
||||||
window.postMessage({ type: "backgroundMessage", action, requestId, payload: data, isExtension }, "*");
|
window.postMessage({ type: "backgroundMessage", action, requestId, payload: data, isExtension }, targetOrigin);
|
||||||
|
|
||||||
// Set up a timeout to automatically reject if no response is received
|
// Set up a timeout to automatically reject if no response is received
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
|
@ -208,9 +208,11 @@ function getFileFromContentScript(fileId) {
|
|||||||
fileRequestResolvers.set(requestId, { resolve, reject }); // Store resolvers by requestId
|
fileRequestResolvers.set(requestId, { resolve, reject }); // Store resolvers by requestId
|
||||||
|
|
||||||
// Send the request message
|
// Send the request message
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
window.postMessage(
|
window.postMessage(
|
||||||
{ action: "getFileFromIndexedDB", fileId, requestId },
|
{ action: "getFileFromIndexedDB", fileId, requestId },
|
||||||
"*"
|
targetOrigin
|
||||||
);
|
);
|
||||||
|
|
||||||
// Timeout to handle no response scenario
|
// Timeout to handle no response scenario
|
||||||
@ -224,12 +226,6 @@ function getFileFromContentScript(fileId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// function sendToSaveFilePicker(data) {
|
|
||||||
// window.postMessage({
|
|
||||||
// action: "SHOW_SAVE_FILE_PICKER",
|
|
||||||
// payload: data,
|
|
||||||
// }, "*");
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
const responseResolvers = new Map();
|
const responseResolvers = new Map();
|
||||||
@ -253,11 +249,12 @@ async function getUserPermission(payload, isFromExtension) {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const requestId = `qortalRequest_${Date.now()}`;
|
const requestId = `qortalRequest_${Date.now()}`;
|
||||||
responseResolvers.set(requestId, resolve); // Store resolver by requestId
|
responseResolvers.set(requestId, resolve); // Store resolver by requestId
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
// Send the request message
|
// Send the request message
|
||||||
window.postMessage(
|
window.postMessage(
|
||||||
{ action: "QORTAL_REQUEST_PERMISSION", payload, requestId, isFromExtension },
|
{ action: "QORTAL_REQUEST_PERMISSION", payload, requestId, isFromExtension },
|
||||||
"*"
|
targetOrigin
|
||||||
);
|
);
|
||||||
|
|
||||||
// Optional timeout to handle no response scenario
|
// Optional timeout to handle no response scenario
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import { openIndexedDB } from "../components/Apps/useQortalMessageListener";
|
||||||
|
import { fileToBase64 } from "./fileReading";
|
||||||
|
|
||||||
export async function handleGetFileFromIndexedDB(event) {
|
export async function handleGetFileFromIndexedDB(event) {
|
||||||
try {
|
try {
|
||||||
const { fileId, requestId } = event.data;
|
const { fileId, requestId } = event.data;
|
||||||
@ -21,10 +24,11 @@ export async function handleGetFileFromIndexedDB(event) {
|
|||||||
|
|
||||||
deleteRequest.onsuccess = function () {
|
deleteRequest.onsuccess = function () {
|
||||||
try {
|
try {
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
window.postMessage(
|
window.postMessage(
|
||||||
{ action: "getFileFromIndexedDBResponse", requestId, result: base64String },
|
{ action: "getFileFromIndexedDBResponse", requestId, result: base64String },
|
||||||
"*"
|
targetOrigin
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error', error)
|
console.log('error', error)
|
||||||
@ -41,21 +45,24 @@ export async function handleGetFileFromIndexedDB(event) {
|
|||||||
result: null,
|
result: null,
|
||||||
error: "Failed to convert file to Base64",
|
error: "Failed to convert file to Base64",
|
||||||
});
|
});
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
window.postMessage(
|
window.postMessage(
|
||||||
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
||||||
error: "Failed to convert file to Base64"
|
error: "Failed to convert file to Base64"
|
||||||
},
|
},
|
||||||
"*"
|
targetOrigin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error(`File with ID ${fileId} not found in IndexedDB`);
|
console.error(`File with ID ${fileId} not found in IndexedDB`);
|
||||||
|
const targetOrigin = window.location.origin;
|
||||||
|
|
||||||
window.postMessage(
|
window.postMessage(
|
||||||
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
{ action: "getFileFromIndexedDBResponse", requestId, result: null,
|
||||||
error: 'File not found in IndexedDB'
|
error: 'File not found in IndexedDB'
|
||||||
},
|
},
|
||||||
"*"
|
targetOrigin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user