From dbe7512750060f1d1c361a6073a0a727980bc74e Mon Sep 17 00:00:00 2001 From: Ivan Grachev Date: Thu, 18 Aug 2022 18:06:30 +0300 Subject: [PATCH] Just show app when content script is not there --- Safari Shared/Resources/background.js | 17 +++++++++++++---- Safari Shared/Resources/content.js | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Safari Shared/Resources/background.js b/Safari Shared/Resources/background.js index 9e421bc9..2c61bb97 100644 --- a/Safari Shared/Resources/background.js +++ b/Safari Shared/Resources/background.js @@ -108,13 +108,22 @@ function storeConfigurationIfNeeded(host, response) { } } +function justShowApp() { + const id = genId(); + const showAppMessage = {name: "justShowApp", id: id, provider: "unknown", body: {}, host: ""}; + browser.runtime.sendNativeMessage("mac.tokenary.io", showAppMessage); +} + browser.browserAction.onClicked.addListener(function(tab) { const message = {didTapExtensionButton: true}; - browser.tabs.sendMessage(tab.id, message); + browser.tabs.sendMessage(tab.id, message, function(pong) { + if (pong != true) { + justShowApp(); + } + }); + if (tab.url == "" && tab.pendingUrl == "") { - const id = genId(); - const showAppMessage = {name: "justShowApp", id: id, provider: "unknown", body: {}, host: ""}; - browser.runtime.sendNativeMessage("mac.tokenary.io", showAppMessage); + justShowApp(); } }); diff --git a/Safari Shared/Resources/content.js b/Safari Shared/Resources/content.js index 191f7b4b..3d50127a 100644 --- a/Safari Shared/Resources/content.js +++ b/Safari Shared/Resources/content.js @@ -119,6 +119,7 @@ function didTapExtensionButton() { // Receive from background browser.runtime.onMessage.addListener((request, sender, sendResponse) => { if ("didTapExtensionButton" in request) { + sendResponse(true); didTapExtensionButton(); } });