diff --git a/Safari Shared/Resources/background.js b/Safari Shared/Resources/background.js index 23ee1645..809e94a7 100644 --- a/Safari Shared/Resources/background.js +++ b/Safari Shared/Resources/background.js @@ -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(); } }); diff --git a/Safari Shared/Resources/content.js b/Safari Shared/Resources/content.js index 3d50127a..f1713c42 100644 --- a/Safari Shared/Resources/content.js +++ b/Safari Shared/Resources/content.js @@ -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); } });