|
9 | 9 | } from "./coinpay-auth.js"; |
10 | 10 | import { pushSettings, pullSettings } from "./settings-store.js"; |
11 | 11 | import { encryptVault, decryptVault } from "./vault.js"; |
| 12 | +import { DEFAULT_PUSH_SERVICE, pushServiceFrom } from "./push-client.js"; |
12 | 13 | import { |
13 | 14 | connect as btrConnect, |
14 | 15 | disconnect as btrDisconnect, |
@@ -391,6 +392,42 @@ function flash(id, msg) { |
391 | 392 | el(id).textContent = msg; |
392 | 393 | setTimeout(() => (el(id).textContent = ""), 1600); |
393 | 394 | } |
| 395 | + |
| 396 | +/* ---------- Push service (push-client.js reads `pushService`) ---------- */ |
| 397 | +async function mountPush() { |
| 398 | + const { pushService } = await chrome.storage.local.get("pushService"); |
| 399 | + const mode = pushService === "off" ? "off" : pushService && pushService !== DEFAULT_PUSH_SERVICE ? "custom" : "default"; |
| 400 | + el("pushMode").value = mode; |
| 401 | + el("pushUrl").value = mode === "custom" ? pushService : ""; |
| 402 | + el("pushCustomRow").hidden = mode !== "custom"; |
| 403 | + el("pushMode").addEventListener("change", () => { |
| 404 | + el("pushCustomRow").hidden = el("pushMode").value !== "custom"; |
| 405 | + }); |
| 406 | + el("savePush").addEventListener("click", async () => { |
| 407 | + const choice = el("pushMode").value; |
| 408 | + if (choice === "off") { |
| 409 | + await chrome.storage.local.set({ pushService: "off" }); |
| 410 | + return flash("savedPush", "push off ✓"); |
| 411 | + } |
| 412 | + if (choice === "default") { |
| 413 | + await chrome.storage.local.remove("pushService"); |
| 414 | + return flash("savedPush", "saved ✓"); |
| 415 | + } |
| 416 | + const url = pushServiceFrom(el("pushUrl").value); |
| 417 | + if (!url || url === DEFAULT_PUSH_SERVICE) return flash("savedPush", "enter an https:// URL"); |
| 418 | + // Check it speaks our protocol before switching every site over to it. |
| 419 | + try { |
| 420 | + const info = await (await fetch(url)).json(); |
| 421 | + if (info.service !== "tronbrowser-push") throw new Error("not a compatible push service"); |
| 422 | + } catch (e) { |
| 423 | + return flash("savedPush", `can't use that URL: ${e.message}`); |
| 424 | + } |
| 425 | + await chrome.storage.local.set({ pushService: url }); |
| 426 | + flash("savedPush", "saved ✓"); |
| 427 | + }); |
| 428 | +} |
| 429 | +mountPush(); |
| 430 | + |
394 | 431 | function escape(s) { |
395 | 432 | const d = document.createElement("div"); |
396 | 433 | d.textContent = s || ""; |
|
0 commit comments