diff --git a/packages/amp-usage/package.json b/packages/amp-usage/package.json index f9d4061..eec723b 100644 --- a/packages/amp-usage/package.json +++ b/packages/amp-usage/package.json @@ -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", diff --git a/packages/amp-usage/page/boot.js b/packages/amp-usage/page/boot.js index 51cd4f2..4533f51 100644 --- a/packages/amp-usage/page/boot.js +++ b/packages/amp-usage/page/boot.js @@ -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");