Skip to content

Linux + iPhone Continuity / iMessage / SMS

on message arrived not opened, poll for new OTPs

Zack Bartel58086d06ab51
diff --git a/extension/src/content/autofill.js b/extension/src/content/autofill.js
index 894e2cd..29c40dd 100644
--- a/extension/src/content/autofill.js
+++ b/extension/src/content/autofill.js
@@ -17,29 +17,48 @@ function findOtpFields() {
return otpFields;
}
-// Request OTP from daemon when we detect OTP fields
-const fields = findOtpFields();
-if (fields.length > 0) {
- console.log("Found potential OTP fields on page, requesting OTP from Tether");
-
+let otpInterval = null;
+
+function requestOtp() {
chrome.runtime.sendMessage({
action: "request_otp_for_site",
url: window.location.hostname
});
}
+// Check every 2 seconds for up to 2 minutes
+const fields = findOtpFields();
+if (fields.length > 0) {
+ console.log("Found potential OTP fields on page, requesting OTP from Tether");
+ requestOtp();
+
+ let attempts = 0;
+ otpInterval = setInterval(() => {
+ attempts++;
+ // Stop trying after 2 minutes or if the user manually filled the field
+ if (attempts > 60 || (fields[0] && fields[0].value.length > 4)) {
+ clearInterval(otpInterval);
+ return;
+ }
+ requestOtp();
+ }, 2000);
+}
+
// Listen for OTPs sent from the daemon
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "fill_otp" && request.otp) {
const fields = findOtpFields();
- if (fields.length > 0) {
+ if (fields.length > 0 && fields[0].value === "") {
console.log("Autofilling OTP:", request.otp);
// Basic autofill logic
fields[0].value = request.otp;
-
+
// Dispatch events so React/Vue/Angular pick up the change
fields[0].dispatchEvent(new Event('input', { bubbles: true }));
fields[0].dispatchEvent(new Event('change', { bubbles: true }));
+
+ // Clean up the interval
+ if (otpInterval) clearInterval(otpInterval);
}
}
});
diff --git a/extension/src/mail/extractor.js b/extension/src/mail/extractor.js
index 336d8cf..87f777e 100644
--- a/extension/src/mail/extractor.js
+++ b/extension/src/mail/extractor.js
@@ -7,8 +7,22 @@
if (typeof messenger !== 'undefined') {
console.log("Tether Mail Extractor loaded in Thunderbird/Betterbird");
- // Listen for new messages being displayed
+ // Listen for new messages arriving in the background completely silently
+ if (messenger.messages.onNewMailReceived) {
+ messenger.messages.onNewMailReceived.addListener(async (folder, messages) => {
+ // messages is a MessageList, we need to iterate its messages array
+ for (const message of messages.messages) {
+ processMessage(message);
+ }
+ });
+ }
+
+ // Also process manually opened messages just in case it missed it
messenger.messageDisplay.onMessageDisplayed.addListener(async (tabId, message) => {
+ processMessage(message);
+ });
+
+ async function processMessage(message) {
// Get the full message body
const full = await messenger.messages.getFull(message.id);
const bodyText = extractTextFromParts(full.parts);
@@ -28,7 +42,7 @@ if (typeof messenger !== 'undefined') {
source: message.subject
});
}
- });
+ }
function extractTextFromParts(parts) {
let text = "";