feat: burrow:// links sign the account page in

The account page's "Sign in with the Burrow client" opens
burrow://account?n=<nonce>. The copy already running takes the link (a
copy started with one gives way at once); it uses the account being
played, or the one remembered for its server (a choice when there are
several), gets a ticket from the server and opens it in the browser.
Installed copies register the protocol when they start; the Windows
installer, the Linux packages and the macOS app declare it too.
This commit is contained in:
Burrowdev committed 2026-10-23 07:04:45 +03:00
1 parent b1dd733a9d
commit b52c9194f5
6 files changed
+154 -11

No files matched your search

+77 -10
View File
@@ -168,11 +168,11 @@
a { color: inherit; text-underline-offset: 3px; } a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--text); } 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); } #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 { width: 100%; max-width: 400px; padding: 28px 28px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; } #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 { margin: 0 0 16px; font-size: 22px; font-weight: 700; } #rename-box h2, #link-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, #link-box .buttons { display: flex; gap: 10px; margin-top: 6px; }
#rename-box .buttons button { flex: 1; margin: 0; padding: 10px 16px 11px; font-size: 16px; } #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-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 { display: flex; align-items: center; gap: 14px; }
#ban-head img { flex: none; width: 48px; height: 48px; } #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; } #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 { margin: 0 0 16px; padding: 0; list-style: none; }
#saved li { display: flex; gap: 6px; margin: 0 0 6px; } #saved li, #link-accounts li { display: flex; gap: 6px; margin: 0 0 6px; }
#saved .account { #link-accounts { margin: 0 0 16px; padding: 0; list-style: none; }
#saved .account, #link-accounts .account {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
display: flex; display: flex;
@@ -204,10 +205,10 @@
text-align: left; text-align: left;
font-weight: 700; font-weight: 700;
} }
#saved .account::after { content: "→"; margin-left: auto; color: var(--muted); font-weight: 400; } #saved .account::after, #link-accounts .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: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 .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 .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 { 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); } #saved .forget:hover { color: var(--text); border-color: var(--line); }
@@ -440,6 +441,16 @@
</form> </form>
</div> </div>
<div id="link-popup" role="dialog" aria-modal="true" aria-labelledby="link-title" hidden>
<div id="link-box">
<h2 id="link-title">Sign in to the account page as</h2>
<ul id="link-accounts"></ul>
<div class="buttons">
<button id="link-cancel" type="button">Cancel</button>
</div>
</div>
</div>
<div id="game" hidden> <div id="game" hidden>
<div id="bar"> <div id="bar">
<span id="who"></span> <span id="who"></span>
@@ -1341,6 +1352,62 @@
setStatus(""); 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. // another name is another account: its code is not this one's.
$("username").addEventListener("input", () => showCodePart(false)); $("username").addEventListener("input", () => showCodePart(false));
+59 -1
View File
@@ -24,6 +24,19 @@ if (!app.commandLine.hasSwitch("user-data-dir")) {
app.setPath("userData", path.join(app.getPath("appData"), "AJ Private Client")); 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=<nonce>; 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 // 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. // (boot.js), kept elsewhere; the plugin and build.json stay beside that one.
const SHIPPED = global.burrow ? global.burrow.shipped : __dirname; 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 // 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 // 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. // 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 apiRequest = (serverUrl, call, body) => new Promise(resolve => {
const [method, apiPath] = API_CALLS[call]; const [method, apiPath] = API_CALLS[call];
const started = Date.now(); 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 // Discord rich presence (discord.js): {appId, state, start, url} while the
// game is open, null when it is not. // game is open, null when it is not.
ipcMain.on("presence", (event, info) => { ipcMain.on("presence", (event, info) => {
@@ -649,7 +700,14 @@ app.whenReady().then(() => {
}, },
}); });
win.setMenu(null); win.setMenu(null);
win.webContents.on("did-finish-load", takeLink);
win.loadFile(path.join(__dirname, "index.html")); 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) { if (builtFor() && global.burrow) {
updates = updater.start({ updates = updater.start({
server: builtFor(), server: builtFor(),
+2
View File
@@ -32,4 +32,6 @@ contextBridge.exposeInMainWorld("client", {
presence: info => ipcRenderer.send("presence", info), presence: info => ipcRenderer.send("presence", info),
onFullscreen: listener => ipcRenderer.on("fullscreen", (event, on) => listener(on)), onFullscreen: listener => ipcRenderer.on("fullscreen", (event, on) => listener(on)),
onShortcut: listener => ipcRenderer.on("shortcut", (event, key) => listener(key)), 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))),
}); });
+4
View File
@@ -30,6 +30,10 @@ module.exports = {
desktopName: "burrow.desktop", 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: { linux: {
target: [{target: "AppImage", arch: ["x64"]}, {target: "deb", arch: ["x64"]}, {target: "rpm", arch: ["x64"]}], target: [{target: "AppImage", arch: ["x64"]}, {target: "deb", arch: ["x64"]}, {target: "rpm", arch: ["x64"]}],
icon: path.join(root, "app", "icon.png"), icon: path.join(root, "app", "icon.png"),
+7
View File
@@ -53,6 +53,12 @@ Section "Burrow"
WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Burrow.exe"' WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Burrow.exe"'
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1 WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 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 SectionEnd
; only what was installed goes: the folder may be one the player chose, with ; only what was installed goes: the folder may be one the player chose, with
@@ -66,4 +72,5 @@ Section "Uninstall"
Delete "$DESKTOP\Burrow.lnk" Delete "$DESKTOP\Burrow.lnk"
DeleteRegKey HKCU "${UNINSTALL_KEY}" DeleteRegKey HKCU "${UNINSTALL_KEY}"
DeleteRegKey HKCU "Software\Burrow" DeleteRegKey HKCU "Software\Burrow"
DeleteRegKey HKCU "Software\Classes\burrow"
SectionEnd SectionEnd
+5
View File
@@ -53,6 +53,11 @@ fi
plist=Burrow.app/Contents/Info.plist plist=Burrow.app/Contents/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleName Burrow" -c "Set :CFBundleDisplayName Burrow" -c "Set :CFBundleIdentifier software.burrow.client" "$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 mkdir icon.iconset
for size in 16 32 128 256; do for size in 16 32 128 256; do