diff --git a/app/index.html b/app/index.html
index 672a061..81ca874 100644
--- a/app/index.html
+++ b/app/index.html
@@ -168,11 +168,11 @@
a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--text); }
- #ban-popup, #rename-popup { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, 0.85); }
- #rename-box { width: 100%; max-width: 400px; padding: 28px 28px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; }
- #rename-box h2 { margin: 0 0 16px; font-size: 22px; font-weight: 700; }
- #rename-box .buttons { display: flex; gap: 10px; margin-top: 6px; }
- #rename-box .buttons button { flex: 1; margin: 0; padding: 10px 16px 11px; font-size: 16px; }
+ #ban-popup, #rename-popup, #link-popup { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, 0.85); }
+ #rename-box, #link-box { width: 100%; max-width: 400px; padding: 28px 28px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; }
+ #rename-box h2, #link-box h2 { margin: 0 0 16px; font-size: 22px; font-weight: 700; }
+ #rename-box .buttons, #link-box .buttons { display: flex; gap: 10px; margin-top: 6px; }
+ #rename-box .buttons button, #link-box .buttons button { flex: 1; margin: 0; padding: 10px 16px 11px; font-size: 16px; }
#ban-box { width: 100%; max-width: 480px; max-height: 100%; overflow-y: auto; padding: 30px 30px 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; }
#ban-head { display: flex; align-items: center; gap: 14px; }
#ban-head img { flex: none; width: 48px; height: 48px; }
@@ -193,8 +193,9 @@
#ban-buttons button { flex: 1; margin: 0; padding: 10px 16px 11px; font-size: 16px; }
#saved { margin: 0 0 16px; padding: 0; list-style: none; }
- #saved li { display: flex; gap: 6px; margin: 0 0 6px; }
- #saved .account {
+ #saved li, #link-accounts li { display: flex; gap: 6px; margin: 0 0 6px; }
+ #link-accounts { margin: 0 0 16px; padding: 0; list-style: none; }
+ #saved .account, #link-accounts .account {
flex: 1;
min-width: 0;
display: flex;
@@ -204,10 +205,10 @@
text-align: left;
font-weight: 700;
}
- #saved .account::after { content: "→"; margin-left: auto; color: var(--muted); font-weight: 400; }
- #saved .account:hover { background: var(--text); border-color: var(--text); color: #000; }
+ #saved .account::after, #link-accounts .account::after { content: "→"; margin-left: auto; color: var(--muted); font-weight: 400; }
+ #saved .account:hover, #link-accounts .account:hover { background: var(--text); border-color: var(--text); color: #000; }
#saved .account:hover::after, #saved .account:hover .where { color: #000; }
- #saved .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+ #saved .name, #link-accounts .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#saved .where { font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }
#saved .forget { flex: none; width: 40px; padding: 0; border-color: transparent; color: var(--muted); font-size: 18px; }
#saved .forget:hover { color: var(--text); border-color: var(--line); }
@@ -440,6 +441,16 @@
+
+
@@ -1341,6 +1352,62 @@
setStatus("");
});
+ // "Sign in with the Burrow client" on the server's account page (its
+ // lib/manage.js; the link comes through main.js): the account played
+ // now, or one remembered here, gets a ticket from the server that
+ // opens the page signed in, in the browser that asked. the browser
+ // already asked whether to open Burrow, so with one account there is
+ // nothing more to ask.
+ const tellAccountPage = (text, bad) => (session ? note(text) : setStatus(text, bad));
+ const pickAccount = choices => new Promise(resolve => {
+ const list = $("link-accounts");
+ list.textContent = "";
+ const done = choice => {
+ $("link-popup").hidden = true;
+ $("link-cancel").onclick = null;
+ resolve(choice);
+ };
+ for (const choice of choices) {
+ const row = document.createElement("li");
+ const button = document.createElement("button");
+ button.type = "button";
+ button.className = "account";
+ const name = document.createElement("span");
+ name.className = "name";
+ name.textContent = choice.username;
+ button.append(name);
+ button.addEventListener("click", () => done(choice));
+ row.append(button);
+ list.append(row);
+ }
+ $("link-cancel").onclick = () => done(null);
+ $("link-popup").hidden = false;
+ list.querySelector("button").focus();
+ });
+ window.client.onAccountLink(async nonce => {
+ if (!$("link-popup").hidden) {
+ return;
+ }
+ const choices = session
+ ? [{server: session.server, username: session.flashVars.username, token: session.flashVars.auth_token}]
+ : remembered().filter(entry => entry.server === serverUrl());
+ if (choices.length === 0) {
+ tellAccountPage("Log in here first, then try the account page again.", true);
+ return;
+ }
+ const choice = choices.length === 1 ? choices[0] : await pickAccount(choices);
+ if (!choice) {
+ return;
+ }
+ const answer = await window.client.api(choice.server, "accountTicket", {token: choice.token, nonce});
+ if (answer.status !== 200 || !/^https?:\/\//.test(String(answer.body.url))) {
+ tellAccountPage(answer.body.error || "The account page could not be signed in.", true);
+ return;
+ }
+ window.client.openPage(answer.body.url);
+ tellAccountPage(`Account page signed in as ${answer.body.username}.`, false);
+ });
+
// another name is another account: its code is not this one's.
$("username").addEventListener("input", () => showCodePart(false));
diff --git a/app/main.js b/app/main.js
index 40a2bfd..35ad8ff 100644
--- a/app/main.js
+++ b/app/main.js
@@ -24,6 +24,19 @@ if (!app.commandLine.hasSwitch("user-data-dir")) {
app.setPath("userData", path.join(app.getPath("appData"), "AJ Private Client"));
}
+// burrow:// links: the server's account page asks the client to sign it in
+// ("Sign in with the Burrow client", burrow://account?n=; index.html
+// does the rest). windows and linux start a new copy with the link: the copy
+// already running takes it, and the new one goes at once. a copy started to
+// play beside the first still plays; only one that came with a link gives way.
+// macOS hands the link to the running app (open-url) instead.
+const LINK_PROTOCOL = "burrow";
+const linkIn = argv => argv.find(arg => String(arg).toLowerCase().startsWith(`${LINK_PROTOCOL}://`)) || null;
+let pendingLink = linkIn(process.argv);
+if (!app.requestSingleInstanceLock() && pendingLink) {
+ process.exit(0);
+}
+
// the folder the client was installed with. this one may be an update
// (boot.js), kept elsewhere; the plugin and build.json stay beside that one.
const SHIPPED = global.burrow ? global.burrow.shipped : __dirname;
@@ -307,7 +320,8 @@ ipcMain.handle("ownVideo", (event, link) => {
// the server's /api only answers its own pages (it checks the Origin
// header), and this client's page is a file. so the calls the page
// needs are made from here, where a request carries no origin.
-const API_CALLS = {status: ["GET", "/api/status"], register: ["POST", "/api/register"], ban: ["POST", "/api/ban"]};
+const API_CALLS = {status: ["GET", "/api/status"], register: ["POST", "/api/register"], ban: ["POST", "/api/ban"],
+ accountTicket: ["POST", "/account/api/client-ticket"]};
const apiRequest = (serverUrl, call, body) => new Promise(resolve => {
const [method, apiPath] = API_CALLS[call];
const started = Date.now();
@@ -499,6 +513,43 @@ ipcMain.on("openPage", (event, url) => {
}
});
+// a burrow:// link (above), once the login page is there to take it: only
+// the account page's nonce goes on, and the window comes to the front.
+const accountNonce = link => {
+ try {
+ const url = new URL(link);
+ const nonce = url.searchParams.get("n") || "";
+ return url.protocol === `${LINK_PROTOCOL}:` && url.hostname === "account" && /^[0-9a-f]{48}$/.test(nonce) ? nonce : null;
+ }
+ catch (err) {
+ return null;
+ }
+};
+const takeLink = () => {
+ if (!pendingLink || !win || win.webContents.isLoading()) {
+ return;
+ }
+ const nonce = accountNonce(pendingLink);
+ pendingLink = null;
+ if (nonce) {
+ if (win.isMinimized()) {
+ win.restore();
+ }
+ win.show();
+ win.focus();
+ win.webContents.send("accountLink", nonce);
+ }
+};
+app.on("second-instance", (event, argv) => {
+ pendingLink = linkIn(argv) || pendingLink;
+ takeLink();
+});
+app.on("open-url", (event, link) => {
+ event.preventDefault();
+ pendingLink = link;
+ takeLink();
+});
+
// Discord rich presence (discord.js): {appId, state, start, url} while the
// game is open, null when it is not.
ipcMain.on("presence", (event, info) => {
@@ -649,7 +700,14 @@ app.whenReady().then(() => {
},
});
win.setMenu(null);
+ win.webContents.on("did-finish-load", takeLink);
win.loadFile(path.join(__dirname, "index.html"));
+ // an installed copy answers burrow:// links (the installers say so too;
+ // this keeps it so after an update or a move). a copy run from the
+ // repository leaves them to the installed one.
+ if (builtFor() && !app.isDefaultProtocolClient(LINK_PROTOCOL)) {
+ app.setAsDefaultProtocolClient(LINK_PROTOCOL);
+ }
if (builtFor() && global.burrow) {
updates = updater.start({
server: builtFor(),
diff --git a/app/preload.js b/app/preload.js
index 352225e..b346411 100644
--- a/app/preload.js
+++ b/app/preload.js
@@ -32,4 +32,6 @@ contextBridge.exposeInMainWorld("client", {
presence: info => ipcRenderer.send("presence", info),
onFullscreen: listener => ipcRenderer.on("fullscreen", (event, on) => listener(on)),
onShortcut: listener => ipcRenderer.on("shortcut", (event, key) => listener(key)),
+ // the server's account page asking to be signed in (main.js): its nonce.
+ onAccountLink: listener => ipcRenderer.on("accountLink", (event, nonce) => listener(String(nonce))),
});
diff --git a/installer/builder.config.js b/installer/builder.config.js
index db991ff..c50a616 100644
--- a/installer/builder.config.js
+++ b/installer/builder.config.js
@@ -30,6 +30,10 @@ module.exports = {
desktopName: "burrow.desktop",
},
+ // burrow:// links, from the account page's "Sign in with the Burrow
+ // client" (the .desktop file's MimeType; app/main.js asks for them too)
+ protocols: [{name: "Burrow", schemes: ["burrow"]}],
+
linux: {
target: [{target: "AppImage", arch: ["x64"]}, {target: "deb", arch: ["x64"]}, {target: "rpm", arch: ["x64"]}],
icon: path.join(root, "app", "icon.png"),
diff --git a/installer/burrow.nsi b/installer/burrow.nsi
index b123b10..3a64234 100644
--- a/installer/burrow.nsi
+++ b/installer/burrow.nsi
@@ -53,6 +53,12 @@ Section "Burrow"
WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Burrow.exe"'
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1
+
+ ; burrow:// links, from the account page's "Sign in with the Burrow client"
+ ; (app/main.js writes the same when it starts)
+ WriteRegStr HKCU "Software\Classes\burrow" "" "URL:burrow"
+ WriteRegStr HKCU "Software\Classes\burrow" "URL Protocol" ""
+ WriteRegStr HKCU "Software\Classes\burrow\shell\open\command" "" '"$INSTDIR\Burrow.exe" "%1"'
SectionEnd
; only what was installed goes: the folder may be one the player chose, with
@@ -66,4 +72,5 @@ Section "Uninstall"
Delete "$DESKTOP\Burrow.lnk"
DeleteRegKey HKCU "${UNINSTALL_KEY}"
DeleteRegKey HKCU "Software\Burrow"
+ DeleteRegKey HKCU "Software\Classes\burrow"
SectionEnd
diff --git a/tools/build-mac.sh b/tools/build-mac.sh
index 2e0248c..b6fd561 100644
--- a/tools/build-mac.sh
+++ b/tools/build-mac.sh
@@ -53,6 +53,11 @@ fi
plist=Burrow.app/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleName Burrow" -c "Set :CFBundleDisplayName Burrow" -c "Set :CFBundleIdentifier software.burrow.client" "$plist"
+# burrow:// links (the account page's "Sign in with the Burrow client"):
+# macOS takes only those the app names here.
+/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" -c "Add :CFBundleURLTypes:0 dict" \
+ -c "Add :CFBundleURLTypes:0:CFBundleURLName string Burrow" -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" \
+ -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string burrow" "$plist"
mkdir icon.iconset
for size in 16 32 128 256; do