converted sendmessage

This commit is contained in:
PhilReact 2024-10-29 18:50:03 +02:00
parent c9306493f0
commit 4f91924947
35 changed files with 163 additions and 225 deletions

View File

@ -5,7 +5,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
<background android:drawable="@mipmap/ic_launcher_adaptive_back"/>
<foreground android:drawable="@mipmap/ic_launcher_adaptive_fore"/>
</adaptive-icon>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -645,46 +645,16 @@ function App() {
};
useEffect(() => {
// Listen for messages from the background script
const messageListener = (message, sender, sendResponse) => {
// Handle various actions
if (
message.action === "UPDATE_STATE_CONFIRM_SEND_QORT" &&
!isMainWindow
) {
setSendqortState(message.payload);
setExtstate("web-app-request-payment");
} else if (message.action === "closePopup" && !isMainWindow) {
window.close();
// Handler function for incoming messages
const messageHandler = (event) => {
const message = event.data;
if (message?.action === "CHECK_FOCUS") {
event.source.postMessage({ action: "CHECK_FOCUS_RESPONSE", isFocused: isFocusedRef.current }, event.origin);
} else if (
message.action === "UPDATE_STATE_REQUEST_CONNECTION" &&
!isMainWindow
) {
setRequestConnection(message.payload);
setExtstate("web-app-request-connection");
} else if (
message.action === "UPDATE_STATE_REQUEST_BUY_ORDER" &&
!isMainWindow
) {
setRequestBuyOrder(message.payload);
setExtstate("web-app-request-buy-order");
} else if (
message.action === "UPDATE_STATE_REQUEST_AUTHENTICATION" &&
!isMainWindow
) {
setRequestAuthentication(message.payload);
setExtstate("web-app-request-authentication");
} else if (message.action === "SET_COUNTDOWN" && !isMainWindow) {
setCountdown(message.payload);
} else if (message.action === "INITIATE_MAIN") {
setIsMain(true);
isMainRef.current = true;
} else if (message.action === "CHECK_FOCUS" && isMainWindow) {
sendResponse(isFocusedRef.current); // Synchronous response
return true; // Return true if you plan to send a response asynchronously
} else if (
message.action === "NOTIFICATION_OPEN_DIRECT" &&
isMainWindow
message.action === "NOTIFICATION_OPEN_DIRECT"
) {
executeEvent("openDirectMessage", {
from: message.payload.from,
@ -709,30 +679,20 @@ function App() {
});
}
// Call the permission request handler for "QORTAL_REQUEST_PERMISSION"
qortalRequestPermisson(message, sender, sendResponse);
if (message.action === "QORTAL_REQUEST_PERMISSION" && !isMainWindow) {
return true; // Return true to indicate an async response is coming
}
if (message.action === "QORTAL_REQUEST_PERMISSION" && isMainWindow && message?.isFromExtension) {
qortalRequestPermissonFromExtension(message, sender, sendResponse);
return true;
}
if (message.action === "QORTAL_REQUEST_PERMISSION" && isMainWindow) {
return;
}
};
// Add message listener
chrome.runtime?.onMessage.addListener(messageListener);
// Attach the event listener
window.addEventListener("message", messageHandler);
// Clean up the listener on component unmount
// Clean up the event listener on component unmount
return () => {
chrome.runtime?.onMessage.removeListener(messageListener);
window.removeEventListener("message", messageHandler);
};
}, []);
//param = isDecline
const confirmPayment = (isDecline: boolean) => {
// REMOVED FOR MOBILE APP
@ -1396,7 +1356,7 @@ function App() {
textDecoration: "underline",
}}
onClick={() => {
chrome.tabs.create({ url: "https://www.qort.trade" });
// TODO
}}
>
Get QORT at qort.trade

View File

@ -804,30 +804,27 @@ export async function notificationCase(request, event) {
try {
const notificationId = "chat_notification_" + Date.now(); // Create a unique ID
chrome.notifications.create(notificationId, {
type: "basic",
iconUrl: "qort.png", // Add an appropriate icon for chat notifications
title: "New Group Message!",
message: "You have received a new message from one of your groups",
priority: 2, // Use the maximum priority to ensure it's noticeable
// buttons: [
// { title: 'Go to group' }
// ]
});
// chrome.notifications.create(notificationId, {
// type: "basic",
// iconUrl: "qort.png", // Add an appropriate icon for chat notifications
// title: "New Group Message!",
// message: "You have received a new message from one of your groups",
// priority: 2, // Use the maximum priority to ensure it's
// });
// Set a timeout to clear the notification after 'timeout' milliseconds
setTimeout(() => {
chrome.notifications.clear(notificationId);
}, 3000);
// setTimeout(() => {
// chrome.notifications.clear(notificationId);
// }, 3000);
event.source.postMessage(
{
requestId: request.requestId,
action: "notification",
payload: true,
type: "backgroundMessageResponse",
},
event.origin
);
// event.source.postMessage(
// {
// requestId: request.requestId,
// action: "notification",
// payload: true,
// type: "backgroundMessageResponse",
// },
// event.origin
// );
} catch (error) {
event.source.postMessage(
{
@ -1399,7 +1396,7 @@ export async function publishGroupEncryptedResourceCase(request, event) {
export async function encryptSingleCase(request, event) {
try {
const { data, secretKeyObject, typeNumber} = request.payload;
const response = await encryptSingle({ data, secretKeyObject, typeNumber });
const response = await encryptSingle({ data64: data, secretKeyObject, typeNumber });
event.source.postMessage(
{
@ -1426,8 +1423,9 @@ export async function publishGroupEncryptedResourceCase(request, event) {
export async function decryptSingleCase(request, event) {
try {
const { data, secretKeyObject, skipDecodeBase64} = request.payload;
const response = await decryptSingleFunc({ data, secretKeyObject, skipDecodeBase64 });
console.log({data, secretKeyObject, skipDecodeBase64})
const response = await decryptSingleFunc({ messages: data, secretKeyObject, skipDecodeBase64 });
console.log('response', response)
event.source.postMessage(
{
requestId: request.requestId,

View File

@ -1,6 +1,6 @@
// @ts-nocheck
import "./qortalRequests";
// TODO
// import "./qortalRequests";
import { isArray } from "lodash";
import {
decryptGroupEncryption,
@ -311,24 +311,27 @@ export function isUpdateMsg(data) {
async function checkWebviewFocus() {
return new Promise((resolve) => {
// Set a timeout for 1 second
const timeout = setTimeout(() => {
resolve(false); // No response within 1 second, assume not focused
}, 1000);
// Send message to the content script to check focus
chrome.runtime.sendMessage({ action: "CHECK_FOCUS" }, (response) => {
clearTimeout(timeout); // Clear the timeout if we get a response
// Send a message to check focus
window.postMessage({ action: "CHECK_FOCUS" }, "*");
if (chrome.runtime.lastError) {
resolve(false); // Error occurred, assume not focused
} else {
resolve(response); // Resolve based on the response
// Listen for the response
const handleMessage = (event) => {
if (event.data?.action === "CHECK_FOCUS_RESPONSE") {
clearTimeout(timeout);
window.removeEventListener("message", handleMessage); // Clean up listener
resolve(event.data.isFocused); // Resolve with the response
}
});
};
window.addEventListener("message", handleMessage);
});
}
function playNotificationSound() {
// chrome.runtime.sendMessage({ action: "PLAY_NOTIFICATION_SOUND" });
}
@ -395,11 +398,11 @@ const handleNotificationDirect = async (directs) => {
// message: "You have received a new direct message",
// priority: 2, // Use the maximum priority to ensure it's noticeable
// });
if (!isMobile) {
setTimeout(() => {
chrome.notifications.clear(notificationId);
}, 7000);
}
// if (!isMobile) {
// setTimeout(() => {
// chrome.notifications.clear(notificationId);
// }, 7000);
// }
// chrome.runtime.sendMessage(
// {
@ -817,19 +820,19 @@ export const checkThreads = async (bringBack) => {
// priority: 2, // Use the maximum priority to ensure it's noticeable
// });
if (!isMobile) {
setTimeout(() => {
chrome.notifications.clear(notificationId);
}, 7000);
}
// if (!isMobile) {
// setTimeout(() => {
// chrome.notifications.clear(notificationId);
// }, 7000);
// }
playNotificationSound();
}
}
const savedtimestampAfter = await getTimestampGroupAnnouncement();
chrome.runtime.sendMessage({
window.postMessage({
action: "SET_GROUP_ANNOUNCEMENTS",
payload: savedtimestampAfter,
});
}, "*");
} catch (error) {
} finally {
}
@ -918,18 +921,19 @@ export const checkNewMessages = async () => {
// priority: 2, // Use the maximum priority to ensure it's noticeable
// });
if (!isMobile) {
setTimeout(() => {
chrome.notifications.clear(notificationId);
}, 7000);
}
// if (!isMobile) {
// setTimeout(() => {
// chrome.notifications.clear(notificationId);
// }, 7000);
// }
playNotificationSound();
}
const savedtimestampAfter = await getTimestampGroupAnnouncement();
chrome.runtime.sendMessage({
window.postMessage({
action: "SET_GROUP_ANNOUNCEMENTS",
payload: savedtimestampAfter,
});
}, "*");
} catch (error) {
} finally {
}
@ -1031,10 +1035,10 @@ export async function getSaveWallet() {
export async function clearAllNotifications() {
const notifications = await chrome.notifications.getAll();
for (const notificationId of Object.keys(notifications)) {
await chrome.notifications.clear(notificationId);
}
// const notifications = await chrome.notifications.getAll();
// for (const notificationId of Object.keys(notifications)) {
// await chrome.notifications.clear(notificationId);
// }
}
export async function getUserInfo() {
@ -1634,7 +1638,7 @@ async function sendChat({ qortAddress, recipientPublicKey, message }) {
reference,
};
}
const path = chrome.runtime.getURL("memory-pow.wasm.full");
const path = `${import.meta.env.BASE_URL}memory-pow.wasm.full`;
const { nonce, chatBytesArray } = await computePow({
chatBytes: tx.chatBytes,
@ -1696,7 +1700,7 @@ export async function sendChatGroup({
// if (!hasEnoughBalance) {
// throw new Error("Must have at least 4 QORT to send a chat message");
// }
const path = chrome.runtime.getURL("memory-pow.wasm.full");
const path = `${import.meta.env.BASE_URL}memory-pow.wasm.full`;
const { nonce, chatBytesArray } = await computePow({
chatBytes: tx.chatBytes,
@ -1776,7 +1780,7 @@ export async function sendChatDirect({
// if (!hasEnoughBalance) {
// throw new Error("Must have at least 4 QORT to send a chat message");
// }
const path = chrome.runtime.getURL("memory-pow.wasm.full");
const path = `${import.meta.env.BASE_URL}memory-pow.wasm.full`;
const { nonce, chatBytesArray } = await computePow({
chatBytes: tx.chatBytes,
@ -1923,16 +1927,16 @@ async function createBuyOrderTx({ crosschainAtInfo, useLocal }) {
};
}
setTimeout(() => {
chrome.tabs.query({}, function (tabs) {
tabs.forEach((tab) => {
chrome.tabs.sendMessage(tab.id, {
type: "RESPONSE_FOR_TRADES",
message: responseMessage,
});
});
});
}, 5000);
// setTimeout(() => {
// chrome.tabs.query({}, function (tabs) {
// tabs.forEach((tab) => {
// chrome.tabs.sendMessage(tab.id, {
// type: "RESPONSE_FOR_TRADES",
// message: responseMessage,
// });
// });
// });
// }, 5000);
return;
}
@ -2579,14 +2583,14 @@ async function listenForChatMessageForBuyOrder({
senderPublicKey
);
chrome.tabs.query({}, function (tabs) {
tabs.forEach((tab) => {
chrome.tabs.sendMessage(tab.id, {
type: "RESPONSE_FOR_TRADES",
message: parsedMessageObj,
});
});
});
// chrome.tabs.query({}, function (tabs) {
// tabs.forEach((tab) => {
// chrome.tabs.sendMessage(tab.id, {
// type: "RESPONSE_FOR_TRADES",
// message: parsedMessageObj,
// });
// });
// });
} catch (error) {
console.error(error);
throw new Error(error.message);
@ -2594,39 +2598,39 @@ async function listenForChatMessageForBuyOrder({
}
export function removeDuplicateWindow(popupUrl) {
chrome.windows.getAll(
{ populate: true, windowTypes: ["popup"] },
(windows) => {
// Filter to find popups matching the specific URL
const existingPopupsPending = windows.filter(
(w) =>
w.tabs &&
w.tabs.some(
(tab) => tab.pendingUrl && tab.pendingUrl.startsWith(popupUrl)
)
);
const existingPopups = windows.filter(
(w) =>
w.tabs &&
w.tabs.some((tab) => tab.url && tab.url.startsWith(popupUrl))
);
// chrome.windows.getAll(
// { populate: true, windowTypes: ["popup"] },
// (windows) => {
// // Filter to find popups matching the specific URL
// const existingPopupsPending = windows.filter(
// (w) =>
// w.tabs &&
// w.tabs.some(
// (tab) => tab.pendingUrl && tab.pendingUrl.startsWith(popupUrl)
// )
// );
// const existingPopups = windows.filter(
// (w) =>
// w.tabs &&
// w.tabs.some((tab) => tab.url && tab.url.startsWith(popupUrl))
// );
if (existingPopupsPending.length > 1) {
chrome.windows.remove(
existingPopupsPending?.[0]?.tabs?.[0]?.windowId,
() => {}
);
} else if (
existingPopupsPending.length > 0 &&
existingPopups.length > 0
) {
chrome.windows.remove(
existingPopupsPending?.[0]?.tabs?.[0]?.windowId,
() => {}
);
}
}
);
// if (existingPopupsPending.length > 1) {
// chrome.windows.remove(
// existingPopupsPending?.[0]?.tabs?.[0]?.windowId,
// () => {}
// );
// } else if (
// existingPopupsPending.length > 0 &&
// existingPopups.length > 0
// ) {
// chrome.windows.remove(
// existingPopupsPending?.[0]?.tabs?.[0]?.windowId,
// () => {}
// );
// }
// }
// );
}
export async function setChatHeads(data) {
@ -3143,29 +3147,7 @@ const checkGroupList = async () => {
}
};
const checkActiveChatsForNotifications = async () => {
try {
const popupUrl = chrome.runtime.getURL("index.html?main=true");
chrome.windows.getAll(
{ populate: true, windowTypes: ["popup"] },
(windows) => {
// Attempt to find an existing popup window that has a tab with the correct URL
const existingPopup = windows.find((w) => {
return (
w.tabs &&
w.tabs.some((tab) => tab.url && tab.url.startsWith(popupUrl))
);
});
if (existingPopup) {
} else {
checkGroupList();
}
}
);
} catch (error) {}
};
// Reconnect when service worker wakes up

View File

@ -471,16 +471,17 @@ isDOMContentLoaded: false
}, []); // Empty dependency array to run once when the component mounts
chrome.runtime?.onMessage.addListener( function (message, sender, sendResponse) {
if(message.action === "SHOW_SAVE_FILE_PICKER"){
showSaveFilePicker(message?.data)
}
// TODO
// chrome.runtime?.onMessage.addListener( function (message, sender, sendResponse) {
// if(message.action === "SHOW_SAVE_FILE_PICKER"){
// showSaveFilePicker(message?.data)
// }
else if (message.action === "getFileFromIndexedDB") {
handleGetFileFromIndexedDB(message.fileId, sendResponse);
return true; // Keep the message channel open for async response
}
});
// else if (message.action === "getFileFromIndexedDB") {
// handleGetFileFromIndexedDB(message.fileId, sendResponse);
// return true; // Keep the message channel open for async response
// }
// });
return {path, history, resetHistory, changeCurrentIndex}
};

View File

@ -130,6 +130,7 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
secretKeyObject: secretKey,
})
.then((response) => {
console.log('decryptSingle', response)
if (!response?.error) {
const filterUIMessages = encryptedMessages.filter((item) => !isExtMsg(item.data));
const decodedUIMessages = decodeBase64ForUIChatMessages(filterUIMessages);

View File

@ -35,18 +35,18 @@ export const MessageDisplay = ({ htmlContent , isReply}) => {
const target = e.target.closest('a');
if (target) {
const href = target.getAttribute('href');
if (chrome && chrome.tabs) {
chrome.tabs.create({ url: href }, (tab) => {
if (chrome.runtime.lastError) {
console.error('Error opening tab:', chrome.runtime.lastError);
} else {
console.log('Tab opened successfully:', tab);
}
});
} else {
console.error('chrome.tabs API is not available.');
}
// TODO
// if (chrome && chrome.tabs) {
// chrome.tabs.create({ url: href }, (tab) => {
// if (chrome.runtime.lastError) {
// console.error('Error opening tab:', chrome.runtime.lastError);
// } else {
// console.log('Tab opened successfully:', tab);
// }
// });
// } else {
// console.error('chrome.tabs API is not available.');
// }
} else {
console.error('No <a> tag found or href is null.');
}

View File

@ -184,7 +184,8 @@ export const MobileFooter = ({
/>
<BottomNavigationAction
onClick={() => {
chrome.tabs.create({ url: "https://www.qort.trade"});
// TODO
// chrome.tabs.create({ url: "https://www.qort.trade"});
}}
icon={
<IconWrapper label="Trading" color="rgba(250, 250, 250, 0.5)">