pass isMobile value to service worker

This commit is contained in:
ivan grachev 2023-12-13 15:21:05 +03:00
parent 4a429e01c0
commit 03f6e93f23
5 changed files with 13 additions and 15 deletions

View File

@ -61,7 +61,7 @@ if (shouldInjectProvider()) {
}
function getLatestConfiguration() {
const request = {subject: "getLatestConfiguration", host: window.location.host};
const request = {subject: "getLatestConfiguration", host: window.location.host, isMobile: isMobile};
browser.runtime.sendMessage(request).then((response) => {
if (typeof response === "undefined") { return; }
const id = genId();
@ -81,7 +81,7 @@ function sendMessageToNativeApp(message) {
message.favicon = getFavicon();
message.host = window.location.host;
document.pendingRequestsIds.add(message.id);
browser.runtime.sendMessage({ subject: "message-to-wallet", message: message, host: window.location.host }).then((response) => {
browser.runtime.sendMessage({ subject: "message-to-wallet", message: message, host: window.location.host, isMobile: isMobile }).then((response) => {
if (typeof response === "undefined") { return; }
sendToInpage(response, message.id);
});
@ -107,6 +107,7 @@ window.addEventListener("message", event => {
} else if (event.data.subject == "disconnect") {
const disconnectRequest = event.data;
disconnectRequest.host = window.location.host;
disconnectRequest.isMobile = isMobile;
browser.runtime.sendMessage(disconnectRequest);
}
}
@ -138,7 +139,7 @@ function genId() {
function didChangeVisibility() {
if (document.pendingRequestsIds.size != 0 && document.visibilityState === 'visible') {
document.pendingRequestsIds.forEach(id => {
const request = {id: id, subject: "getResponse", host: window.location.host};
const request = {id: id, subject: "getResponse", host: window.location.host, isMobile: isMobile};
browser.runtime.sendMessage(request).then(response => {
if (typeof response !== "undefined") {
sendToInpage(response, id);

View File

@ -1,15 +1,12 @@
// Copyright © 2022 Tokenary. All rights reserved.
const isMobile = true; // TODO: setup from platform-specific content script
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.subject === "POPUP_PING") {
} else if (request.subject === "POPUP_DID_PROCEED") {
if (request.subject === "POPUP_DID_PROCEED") {
popupDidProceed(request.id);
} else if (request.subject === "POPUP_APPEARED") {
didAppearPopup(request.tab, sendResponse);
} else if (request.subject === "message-to-wallet") {
if (isMobile) {
if (request.isMobile) {
const name = request.message.name;
if (name != "switchEthereumChain" && name != "addEthereumChain" && name != "switchAccount") {
addToPopupQueue(request.message);
@ -21,7 +18,7 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (typeof response !== "undefined") {
sendResponse(response);
storeConfigurationIfNeeded(request.host, response);
waitAndShowNextPopupIfNeeded(isMobile);
waitAndShowNextPopupIfNeeded(request.isMobile);
}
}).catch(() => {});
} else if (request.subject === "getLatestConfiguration") {
@ -57,7 +54,7 @@ function sendNativeMessage(request, sender, sendResponse) {
if (typeof response !== "undefined") {
sendResponse(response);
storeConfigurationIfNeeded(request.host, response);
waitAndShowNextPopupIfNeeded(isMobile);
waitAndShowNextPopupIfNeeded(request.isMobile);
}
}).catch(() => {});
}
@ -150,7 +147,7 @@ function genId() {
function waitAndShowNextPopupIfNeeded(isMobile) {
if (isMobile) {
setTimeout(processPopupQueue, 420);
setTimeout(processPopupQueue, 420); // TODO: hmmm
}
}

View File

@ -22,7 +22,7 @@
"matches": [ "file://*/*", "http://*/*", "https://*/*" ],
"run_at": "document_start",
"all_frames": false,
"js": [ "content.js", "ios_specific_content.js" ]
"js": [ "ios_specific_content.js", "content.js" ]
}],
"action": {

View File

@ -4,7 +4,7 @@ const button = document.getElementById('tokenary-button');
var message = {};
browser.tabs.getCurrent(tab => {
browser.runtime.sendMessage({subject: 'POPUP_APPEARED', tab: tab}).then((response) => {
browser.runtime.sendMessage({subject: 'POPUP_APPEARED', tab: tab, isMobile: true}).then((response) => {
message = response;
setupButton();
});
@ -21,7 +21,7 @@ button.addEventListener('click', () => {
});
}
});
browser.runtime.sendMessage({subject: 'POPUP_DID_PROCEED', id: message.id});
browser.runtime.sendMessage({subject: 'POPUP_DID_PROCEED', id: message.id, isMobile: true});
setTimeout(window.close, 437);
return true;
});

View File

@ -22,7 +22,7 @@
"matches": [ "file://*/*", "http://*/*", "https://*/*" ],
"run_at": "document_start",
"all_frames": false,
"js": [ "content.js", "macos_specific_content.js" ]
"js": [ "macos_specific_content.js", "content.js" ]
}],
"action": {