amp-usage 0.1.1: the Windows window is this computer, not a remote browser (#1025)
On Windows magpie's window is http://wails.localhost (WebView2). page/boot.js counted only localhost, 127.0.0.1 and an empty host as this computer, so the Windows window got the "remote browser" message (#1024). It now counts *.localhost, ::1 and 127.* too, the same rule as chat, fingerprint, kimi-desktop, page-model-quota and window-warmup. magpie.service still wins. What was run at 84a6a812739b96191e9d63805cd408e0abef717a (mote, macOS): - boot.js in a node vm with a mocked location and magpie bridge, new and old side by side. wails.localhost, WAILS.LOCALHOST, 127.0.0.2 and [::1]: old shows the remote message, new opens http://127.0.0.1:3497/. localhost, 127.0.0.1 and an empty host open it in both. 192.168.1.5, evil.com and localhost.evil.com show the remote message in both. A magpie.service is used in both. - packages/amp-usage: node --test test/*.test.mjs, 48 pass, 0 fail. bun scripts/check.mjs amp-usage passed. Not tried: a real magpie window on Windows. No test of boot.js in the package yet. Co-authored-by: overstarry <overstarry@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/page-amp-usage",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"description": "An Amp usage board in Magpie's window, with a local background service that can sync Amp usage into Magpie's usage ledger.",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
@@ -41,11 +41,17 @@
|
||||
const port = Number(options?.port ?? 3497);
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
||||
throw new Error("port");
|
||||
// This computer's window: wails://localhost on macOS and Linux,
|
||||
// http://wails.localhost on Windows (Wails v3, WebView2).
|
||||
const host = location.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
||||
const local =
|
||||
host === "" ||
|
||||
host === "localhost" ||
|
||||
host.endsWith(".localhost") ||
|
||||
host === "::1" ||
|
||||
/^127\./.test(host);
|
||||
const target =
|
||||
magpie.service ||
|
||||
(["localhost", "127.0.0.1", ""].includes(location.hostname)
|
||||
? `http://127.0.0.1:${port}/`
|
||||
: "");
|
||||
magpie.service || (local ? `http://127.0.0.1:${port}/` : "");
|
||||
if (!target) throw new Error("remote");
|
||||
const url = new URL(target);
|
||||
url.searchParams.set("theme", theme.dark ? "dark" : "light");
|
||||
|
||||
Reference in New Issue
Block a user