From f1866a03ed1a65876e07416adda7d15114f56f7e Mon Sep 17 00:00:00 2001 From: Gerrit Niezen Date: Tue, 5 Mar 2024 11:17:30 +0000 Subject: [PATCH] add extension --- extension/background.js | 51 +++++++ extension/icon-128.png | Bin 0 -> 1712 bytes extension/manifest.json | 19 +++ extension/verio-helper/helper.reg | 3 + extension/verio-helper/helper.zig | 193 +++++++++++++++++++++++++++ extension/verio-helper/manifest.json | 9 ++ 6 files changed, 275 insertions(+) create mode 100644 extension/background.js create mode 100644 extension/icon-128.png create mode 100644 extension/manifest.json create mode 100644 extension/verio-helper/helper.reg create mode 100644 extension/verio-helper/helper.zig create mode 100644 extension/verio-helper/manifest.json diff --git a/extension/background.js b/extension/background.js new file mode 100644 index 0000000000..84eb53bb80 --- /dev/null +++ b/extension/background.js @@ -0,0 +1,51 @@ + +let reply; +let port; + +function connect() { + const hostName = 'org.tidepool.uploader'; + console.log('Connecting to native messaging host', hostName); + port = chrome.runtime.connectNative(hostName); + port.onMessage.addListener(onNativeMessage); + port.onDisconnect.addListener(onDisconnected); +} + +function sendNativeMessage(message) { + port.postMessage(message); + //port.postMessage('\n'); + console.log('Sent message:', JSON.stringify(message)); +} + +function onNativeMessage(message) { + if (message.msgType == 'info') { + console.log(message.details); + } else { + reply(message); + } +} + +function onDisconnected() { + console.log('Disconnected: ' + chrome.runtime.lastError.message); + port = null; + reply({ msgType: 'error', details: 'Disconnected: ' + chrome.runtime.lastError.message }); +} + +chrome.runtime.onMessageExternal.addListener( + function(request, sender, sendResponse) { + console.log("Received message from the web page:", request); + + if (request.command == "openDevice") { + connect(); + } + + // Process the request here + if (port) { + sendNativeMessage(request); + + reply = sendResponse; + return true; // indicates you will asynchronously use sendResponse + } else { + sendResponse({ msgType: 'error', details: 'Not connected.'}); + } + } +); diff --git a/extension/icon-128.png b/extension/icon-128.png new file mode 100644 index 0000000000000000000000000000000000000000..dd2cf75b40a5b55ddfd9089ea074edc3ddf1fed9 GIT binary patch literal 1712 zcmV;h22c5kP)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