Deliver current latest configurations to app on iOS as well

This commit is contained in:
Ivan Grachev 2022-08-24 18:25:45 +03:00
parent f6ae749f73
commit 9281973d16
2 changed files with 11 additions and 18 deletions

View File

@ -2,14 +2,7 @@
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.subject === "message-to-wallet") {
if ("name" in request.message, request.message.name == "switchAccount") {
getLatestConfiguration(request.host, function(currentConfiguration) {
request.message.body = currentConfiguration;
sendNativeMessage(request, sender, sendResponse);
});
} else {
sendNativeMessage(request, sender, sendResponse);
}
sendNativeMessage(request, sender, sendResponse);
} else if (request.subject === "getResponse") {
browser.runtime.sendNativeMessage("mac.tokenary.io", request, function(response) {
sendResponse(response);
@ -119,8 +112,13 @@ function justShowApp() {
browser.browserAction.onClicked.addListener(function(tab) {
const message = {didTapExtensionButton: true};
browser.tabs.sendMessage(tab.id, message, function(pong) {
if (pong != true) {
browser.tabs.sendMessage(tab.id, message, function(host) {
if (typeof host !== "undefined") {
getLatestConfiguration(host, function(currentConfiguration) {
const switchAccountMessage = {name: "switchAccount", id: genId(), provider: "unknown", body: currentConfiguration};
browser.tabs.sendMessage(tab.id, switchAccountMessage);
});
} else {
justShowApp();
}
});

View File

@ -110,17 +110,12 @@ function sendMessageToNativeApp(message) {
platformSpecificProcessMessage(message); // iOS opens app here
}
function didTapExtensionButton() {
const id = genId();
const message = {name: "switchAccount", id: id, provider: "unknown", body: {}};
sendMessageToNativeApp(message);
}
// Receive from background
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if ("didTapExtensionButton" in request) {
sendResponse(true);
didTapExtensionButton();
sendResponse(window.location.host);
} else if ("name" in request && request.name == "switchAccount") {
sendMessageToNativeApp(request);
}
});