Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
8cb8c5c
feat: save the plugin order, switched-off plugins and the open plugin
CodySimonds65 Oct 3, 2026
9097e58
feat: leave a switched-off plugin's shortcuts unregistered
CodySimonds65 Oct 3, 2026
1f7f2c7
refactor: share shortcut key capture and move the Timer keys out of S…
CodySimonds65 Oct 3, 2026
257bc13
feat: add the plugin contract, the built-in plugins and the Timer set…
CodySimonds65 Oct 3, 2026
0187094
feat: show plugins in a RuneLite-style strip with a plugin list and T…
CodySimonds65 Oct 3, 2026
0f9c35e
fix: size the tools window for the strip, align the plugin card tops …
CodySimonds65 Oct 3, 2026
db536b4
fix: name the strip toggle for screen readers and never resolve a swi…
CodySimonds65 Oct 3, 2026
5ac7cb1
Merge remote-tracking branch 'origin/main' into feature/runelite-plugins
CodySimonds65 Oct 3, 2026
11eb882
feat: read and validate community plugin manifests
CodySimonds65 Oct 3, 2026
834acd1
fix: reject trailing-dot hosts and wrong-typed manifest values, and t…
CodySimonds65 Oct 3, 2026
890999f
feat: add the plugin sandbox rules for sites, the local network and f…
CodySimonds65 Oct 3, 2026
4ca9cf8
fix: give each plugin its own origin domain, close the plugin namespa…
CodySimonds65 Oct 3, 2026
2567112
test: cover scoped and embedded IPv6 addresses, and keep plugin ids t…
CodySimonds65 Oct 3, 2026
3feb586
feat: add private key-value storage for community plugins
CodySimonds65 Oct 3, 2026
9296d0b
fix: cap plugin storage by the bytes written, and never treat a locke…
CodySimonds65 Oct 3, 2026
19118bb
test: prove the plugin storage cap bounds the bytes on disk
CodySimonds65 Oct 3, 2026
ea9b125
feat: add the FourFold-run fetch for community plugins
CodySimonds65 Oct 3, 2026
c43b268
fix: refuse header injection in plugin fetches and report every failu…
CodySimonds65 Oct 3, 2026
a7665fb
fix: never resend plugin headers after a redirect leaves the host, an…
CodySimonds65 Oct 3, 2026
949ee0b
fix: keep plugin headers off another port of the same host, and write…
CodySimonds65 Oct 3, 2026
d5d8d7f
feat: save plugin cards and developer mode, and keep a missing plugin…
CodySimonds65 Oct 3, 2026
de7b03f
test: prove two cards from one plugin survive a settings load
CodySimonds65 Oct 3, 2026
0b127da
feat: host community plugins as sandboxed web pages with a message API
CodySimonds65 Oct 3, 2026
600c11e
fix: close the worker escape, bound plugin floods, and add the missin…
CodySimonds65 Oct 3, 2026
26d29da
fix: keep WebRTC out of plugin pages as far as the browser allows
CodySimonds65 Oct 3, 2026
d93f0e9
fix: count every page request toward the flood stop, and budget the b…
CodySimonds65 Oct 3, 2026
0a1d0b5
feat: load community plugins from the dev folder in developer mode
CodySimonds65 Oct 3, 2026
0e6f0ec
fix: keep login names from plugins, and make the plugin manager survi…
CodySimonds65 Oct 3, 2026
097e8b2
fix: stop a plugin that was switched off while it was starting
CodySimonds65 Oct 3, 2026
6e1789e
feat: draw community plugin cards over the game, floating and in the …
CodySimonds65 Oct 3, 2026
2469725
docs: add the plugin author guide and two sample plugins
CodySimonds65 Oct 3, 2026
07985ef
fix: keep plugin cards from disturbing the overlay panel, and tighten…
CodySimonds65 Oct 3, 2026
9aa1e28
docs: correct the plugin guide and samples against the code, and send…
CodySimonds65 Oct 3, 2026
b0d9cf3
fix: stop a plugin page closing FourFold, and cap its icon and browse…
CodySimonds65 Oct 3, 2026
f65b28e
fix: let the sandbox check probe the host's close lock, and allow the…
CodySimonds65 Oct 3, 2026
e74a334
feat: read the plugin hub's catalog and download from it with a size cap
CodySimonds65 Oct 3, 2026
93e0719
feat: build, verify and safely unpack plugin packages
CodySimonds65 Oct 3, 2026
8cf4d27
feat: decide which hub plugins may run, and install, update and remov…
CodySimonds65 Oct 3, 2026
2b24a92
feat: add the hub tool that checks a submission and builds the catalog
CodySimonds65 Oct 3, 2026
c028c8a
fix: read a hostile hub catalog quickly and strictly, and check hub a…
CodySimonds65 Oct 3, 2026
51c1bfd
feat: open links only on a plugin's declared sites, and mark communit…
CodySimonds65 Oct 3, 2026
554158d
feat: run installed hub plugins beside dev plugins, each starting on …
CodySimonds65 Oct 3, 2026
6a0c6f7
fix: keep hub installs and their record safe from corrupt files, race…
CodySimonds65 Oct 3, 2026
eb55bcd
fix: bound how deep a package can nest, and keep packages to files ev…
CodySimonds65 Oct 3, 2026
a8d9646
fix: make the hub tool refuse bad input loudly and tell the reviewer …
CodySimonds65 Oct 3, 2026
f28bd77
fix: keep the author visible in the community bar, and open exactly t…
CodySimonds65 Oct 3, 2026
d95264f
fix: never start a hub plugin before the user's settings are known, a…
CodySimonds65 Oct 3, 2026
dafebb5
feat: add the plugin hub page to the plugin panel
CodySimonds65 Oct 3, 2026
b8a9097
feat: check the plugin hub, and install, update and uninstall its plu…
CodySimonds65 Oct 3, 2026
8129318
fix: refuse site names that aren't plain host names, and keep every s…
CodySimonds65 Oct 3, 2026
cfc5a29
fix: show any-website access before install, keep the hub page quick,…
CodySimonds65 Oct 3, 2026
8df3086
docs: explain the plugin hub to users and plugin authors
CodySimonds65 Oct 3, 2026
a154b4f
fix: give hub downloads a time limit, and ask before uninstalling a p…
CodySimonds65 Oct 3, 2026
48a7dae
docs: correct the hub rules an author meets on a first submission
CodySimonds65 Oct 3, 2026
d435001
fix: tell the truth about a plugin that needs a newer FourFold, and c…
CodySimonds65 Oct 3, 2026
39b4a0f
docs: name two submission rules the guide left out
CodySimonds65 Oct 3, 2026
5ffa5d3
feat: add a Refresh button to the plugin hub page
CodySimonds65 Oct 3, 2026
0529a73
Merge pull request #34 from CodySimonds65/feature/plugin-hub
CodySimonds65 Oct 3, 2026
38b0658
Merge pull request #33 from CodySimonds65/feature/web-plugins
CodySimonds65 Oct 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions FourFoldAccountManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FourFoldAccountManager.Lead
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FourFoldAccountManager.Desktop.Tests", "src\FourFoldAccountManager.Desktop.Tests\FourFoldAccountManager.Desktop.Tests.csproj", "{B1001A02-C503-4CC9-9BF3-473EE45297D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FourFoldAccountManager.HubTool", "src\FourFoldAccountManager.HubTool\FourFoldAccountManager.HubTool.csproj", "{4C1F820F-039F-4288-9458-F78626241946}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -99,6 +101,18 @@ Global
{B1001A02-C503-4CC9-9BF3-473EE45297D0}.Release|x64.Build.0 = Release|Any CPU
{B1001A02-C503-4CC9-9BF3-473EE45297D0}.Release|x86.ActiveCfg = Release|Any CPU
{B1001A02-C503-4CC9-9BF3-473EE45297D0}.Release|x86.Build.0 = Release|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Debug|x64.ActiveCfg = Debug|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Debug|x64.Build.0 = Debug|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Debug|x86.ActiveCfg = Debug|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Debug|x86.Build.0 = Debug|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Release|Any CPU.Build.0 = Release|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Release|x64.ActiveCfg = Release|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Release|x64.Build.0 = Release|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Release|x86.ActiveCfg = Release|Any CPU
{4C1F820F-039F-4288-9458-F78626241946}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -110,5 +124,6 @@ Global
{8DC5AD11-A59F-445F-84AC-D10C5F7A9C17} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{B3971592-86AD-488E-85E2-8C9F87A41670} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{B1001A02-C503-4CC9-9BF3-473EE45297D0} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{4C1F820F-039F-4288-9458-F78626241946} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
EndGlobalSection
EndGlobal
462 changes: 462 additions & 0 deletions PLUGIN_AUTHORS.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ A Windows client for running several FourFold accounts side by side, each in its
- **Accounts**: saved logins (stored in Windows Credential Manager), favorites and custom order.
- **Layouts**: run up to five games in a grid, or give each account its own tab.
- **Theatre mode and full screen**: hide everything but the games.
- **Plugins**: XP tracker, class comparison, XP calculator and a speedrun timer.
- **Plugins**: XP tracker, stats, XP calculator and a speedrun timer in a RuneLite-style strip. Click an icon to open its panel, drag icons to reorder them, and use the wrench to switch plugins off or change the Timer's keys. The button at the right of the toolbar hides or shows the strip.
- **Community plugins**: open the plugin list (the wrench) and choose **Plugin hub** to search and install plugins made by the community. Every plugin is reviewed before it is listed, runs in a sandbox, and updates itself. To make one, see [PLUGIN_AUTHORS.md](PLUGIN_AUTHORS.md).
- **Overlays**: drag XP/hr, stats, XP calc and timer cards anywhere over the game.
- **Second monitor**: pop the tools panel into its own window, or float individual cards on any screen.
- **Shared XP leaderboard**: daily, weekly and monthly XP gains across opted-in players.
- **Store blocking**: optionally stop the in-game store and gold buttons from opening (Settings → Display).

## Shortcuts

All shortcuts can be changed on the **Shortcuts** tab in Settings.
App shortcuts can be changed on the **Shortcuts** tab in Settings; the Timer's keys are in its plugin settings (wrench → Timer cog).

| Action | Default |
|---|---|
Expand Down
80 changes: 80 additions & 0 deletions samples/goal-tracker/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Goal tracker: a level goal per account, kept in plugin storage and shown on a card.
const container = document.getElementById('accounts');
let goals = {};

function progressTo(goal, xp) {
if (!goal || xp.level === null) return null;
if (xp.level >= goal) return 1;
const withinLevel = xp.nextLevelXp ? xp.currentXp / xp.nextLevelXp : 0;
return Math.min(1, (xp.level + withinLevel) / goal);
}

// Events arrive in bursts (xp.onUpdated fires once per account), so redraws run one after another, never overlapping.
let queue = Promise.resolve();
const render = () => (queue = queue.then(draw).catch(error => console.warn(error.code ?? error.message)));

async function draw() {
// Leave the list alone while the user is typing a goal.
if (container.contains(document.activeElement) && document.activeElement.tagName === 'INPUT') return;
const accounts = await fourfold.accounts.list();
const panels = [];
if (accounts.length === 0) {
const none = document.createElement('p');
none.className = 'muted';
none.textContent = 'No accounts yet. Add one in FourFold.';
panels.push(none);
}
for (const account of accounts) {
const xp = await fourfold.xp.get(account.id);
const goal = goals[account.id] ?? null;
const progress = progressTo(goal, xp);

const card = document.createElement('div');
card.className = 'account';
const title = document.createElement('h2');
title.textContent = `${account.label}: ${xp.className ?? 'no class yet'} ${xp.level ?? ''}`;
const label = document.createElement('label');
label.textContent = 'Goal level';
const input = document.createElement('input');
input.type = 'number';
input.min = '1';
input.value = goal ?? '';
input.addEventListener('change', async () => {
const value = Number.parseInt(input.value, 10);
if (Number.isFinite(value) && value > 0) goals[account.id] = value;
else delete goals[account.id];
await fourfold.storage.set('goals', goals);
input.blur();
await render();
});
const bar = document.createElement('div');
bar.className = 'bar';
const fill = document.createElement('div');
fill.style.width = `${Math.round((progress ?? 0) * 100)}%`;
bar.append(fill);
card.append(title, label, input, bar);
panels.push(card);

if (goal && progress !== null) {
await fourfold.cards.set('goal', account.id, {
summary: `Level ${xp.level} of ${goal}`,
rows: [
{ label: 'Level', value: `${xp.level} / ${goal}`, progress },
{ label: 'XP/hr', value: xp.xpPerHour ? Math.round(xp.xpPerHour).toLocaleString() : '—' }
]
});
} else {
await fourfold.cards.clear('goal', account.id);
}
}
container.replaceChildren(...panels);
}

async function start() {
goals = (await fourfold.storage.get('goals')) ?? {};
fourfold.accounts.onChanged(render);
fourfold.xp.onUpdated(render);
await render();
}

start().catch(error => { container.textContent = `Goal tracker failed: ${error.message}`; });
14 changes: 14 additions & 0 deletions samples/goal-tracker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Goal tracker</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Goal tracker</h1>
<p class="muted">Set a level goal for each account.</p>
<div id="accounts"></div>
<script src="app.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions samples/goal-tracker/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "fourfold.goal-tracker",
"name": "Goal tracker",
"shortLabel": "Goals",
"version": "1.0.0",
"author": "FourFold",
"description": "Tracks a level goal per account and shows progress on a card.",
"apiVersion": 1,
"panel": "index.html",
"cards": [{ "id": "goal", "name": "Goal", "scope": "account" }]
}
9 changes: 9 additions & 0 deletions samples/goal-tracker/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body { margin: 0; padding: 14px; background: var(--ff-surface); color: var(--ff-text); font: 13px "Segoe UI", sans-serif; }
h1 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.muted { color: var(--ff-text-muted); margin: 0 0 12px; }
.account { background: var(--ff-surface-raised); border: 1px solid var(--ff-border); border-radius: 6px; padding: 10px; margin-bottom: 8px; }
.account h2 { margin: 0 0 6px; font-size: 13px; }
.account label { color: var(--ff-text-muted); margin-right: 6px; }
.account input { width: 64px; background: var(--ff-background); color: var(--ff-text); border: 1px solid var(--ff-border); border-radius: 4px; padding: 3px 6px; }
.bar { height: 4px; border-radius: 2px; background: var(--ff-border); margin-top: 8px; }
.bar > div { height: 100%; border-radius: 2px; background: var(--ff-accent); }
118 changes: 118 additions & 0 deletions samples/sandbox-check/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Each check tries something a plugin must not be able to do. PASS means FourFold stopped it.
const results = document.getElementById('results');
const violations = [];
document.addEventListener('securitypolicyviolation', event =>
violations.push({ directive: event.effectiveDirective, blocked: event.blockedURI }));
const settle = () => new Promise(resolve => setTimeout(resolve, 1000));
const violated = (directive, blocked = '') =>
violations.filter(found => found.directive.startsWith(directive) && found.blocked.startsWith(blocked)).length;

function report(name, passed, detail = '') {
const item = document.createElement('li');
item.textContent = `${passed ? 'PASS' : 'FAIL'}: ${name}${detail ? ` (${detail})` : ''}`;
item.style.color = passed ? 'var(--ff-accent)' : 'var(--ff-danger)';
results.append(item);
}

async function rejects(name, action, expectedCode) {
try {
await action();
report(name, false, 'it was allowed');
} catch (error) {
report(name, !expectedCode || error.code === expectedCode, error.code ?? error.message);
}
}

async function run() {
report('Inline script is blocked', window.inlineScriptRan !== true);

let evalRan = false;
try { evalRan = new Function('return true')(); } catch { /* blocked */ }
report('eval is blocked', evalRan !== true);

// These are stopped by the content security policy, which reports each one as a violation.
const remote = document.createElement('script');
remote.src = 'https://example.com/remote.js';
document.head.append(remote);
fetch('https://example.org/').catch(() => {});
try { new WebSocket('wss://example.org/').onerror = () => {}; } catch { /* also blocked */ }
const frame = document.createElement('iframe');
frame.src = 'https://example.com/';
frame.hidden = true;
document.body.append(frame);
const popup = window.open('https://example.com/');
let workerMade = false;
try { new Worker('check.js'); workerMade = true; } catch { /* blocked */ }
let serviceWorkerRegistered = false;
try {
await navigator.serviceWorker.register('check.js');
serviceWorkerRegistered = true;
} catch { /* blocked */ }
await settle();
report('A script from another site is blocked, even a declared one',
violated('script-src-elem', 'https://example.com') > 0);
report('Page fetch and WebSocket to an undeclared site are blocked', violated('connect-src') >= 2);
report('Frames are blocked', violated('frame-src') > 0);
report('Web Workers are blocked', !workerMade || violated('worker-src') > 0);
report('Service workers are blocked', !serviceWorkerRegistered);
report('WebRTC is removed', typeof RTCPeerConnection === 'undefined');
report('alert() shows nothing (check by eye)', alert('This should not appear') === undefined);

// If window.close() worked, FourFold would be closing instead of getting here.
let stillRunning = false;
window.close();
stillRunning = true;
report('window.close() does nothing', stillRunning);

// A sandboxed frame's window has a close() the injected library doesn't replace. FourFold itself must ignore it.
let stillRunningAfterFrame = false;
try {
const sandboxed = document.createElement('iframe');
sandboxed.sandbox = '';
sandboxed.hidden = true;
document.body.append(sandboxed);
sandboxed.contentWindow.close.call(window);
} catch { /* refused, which is fine too */ }
stillRunningAfterFrame = true;
report('window.close() through a sandboxed frame does nothing', stillRunningAfterFrame);

report('New windows are blocked', popup === null || popup.closed);

await rejects('FourFold-run fetch to an undeclared site is refused',
() => fourfold.http.fetch('https://example.org/'), 'site-not-allowed');
await rejects('FourFold-run fetch to the local network is refused',
() => fourfold.http.fetch('https://localhost/'), 'site-not-allowed');
await rejects('Only GET and POST are accepted',
() => fourfold.http.fetch('https://example.com/', { method: 'DELETE' }), 'invalid-argument');

try {
const response = await fourfold.http.fetch('https://example.com/');
report('FourFold-run fetch to a declared site works', response.status === 200, `status ${response.status}`);
} catch (error) {
report('FourFold-run fetch to a declared site works', false, error.code ?? error.message);
}

await rejects('An undeclared card is refused',
() => fourfold.cards.set('nope', null, { rows: [] }), 'not-declared');
await rejects('openExternal is refused while the checks run', () => fourfold.openExternal('https://example.com/'));

await fourfold.storage.set('probe', { at: Date.now() });
report('Storage round-trips', (await fourfold.storage.get('probe')) !== null);
await rejects('Storage over 256 KB is refused',
() => fourfold.storage.set('big', 'x'.repeat(300 * 1024)), 'limit-exceeded');

// FourFold answers a read at once, so these may never overlap: each is answered, or refused past 32 at a time.
const many = await Promise.allSettled(Array.from({ length: 40 }, () => fourfold.storage.get('probe')));
report('More than 32 calls at once are refused or answered',
many.every(result => result.status === 'fulfilled' || result.reason.code === 'limit-exceeded'));
}

document.getElementById('open').addEventListener('click', () => fourfold.openExternal('https://example.com/'));
document.getElementById('leave').addEventListener('click', () => { location.href = 'https://example.com/'; });
document.getElementById('flood').addEventListener('click', () => {
// Large messages first, so the budget for message text trips whatever the machine's speed.
const pad = 'x'.repeat(500000);
for (let i = 0; i < 20; i++) window.chrome.webview.postMessage({ id: -1 - i, method: 'timer.get', pad });
for (let i = 0; i < 20000; i++) window.chrome.webview.postMessage({ id: -100 - i, method: 'timer.get' });
});
run().catch(error => report('The check itself ran', false, error.message));
18 changes: 18 additions & 0 deletions samples/sandbox-check/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sandbox check</title>
</head>
<body style="margin:0;padding:14px;background:var(--ff-surface);color:var(--ff-text);font:12px 'Segoe UI',sans-serif">
<h1 style="font-size:16px;margin:0 0 8px">Sandbox check</h1>
<p style="color:var(--ff-text-muted)">Every line should say PASS.</p>
<p style="color:var(--ff-text-muted)">Don't click or type in this panel until the list is complete.</p>
<ul id="results" style="padding-left:16px;line-height:1.7"></ul>
<button id="open">Open example.com (should open your browser)</button>
<button id="leave">Navigate away (should do nothing)</button>
<button id="flood">Flood FourFold (should stop this plugin)</button>
<script>window.inlineScriptRan = true;</script>
<script src="check.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions samples/sandbox-check/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "fourfold.sandbox-check",
"name": "Sandbox check",
"shortLabel": "Sandbox",
"version": "1.0.0",
"author": "FourFold",
"description": "Tries everything a plugin must not be able to do, and reports PASS or FAIL.",
"apiVersion": 1,
"panel": "index.html",
"sites": ["https://example.com"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Text.Json.Nodes;
using FourFoldAccountManager.Core.Data;
using FourFoldAccountManager.Core.Models;
using Xunit;

namespace FourFoldAccountManager.Core.Tests.Data;

public sealed class SettingsStorePluginCardTests : IDisposable
{
private readonly string _root = Path.Combine(Path.GetTempPath(), $"fourfold-settings-{Guid.NewGuid():N}");
private readonly SettingsStore _store;

public SettingsStorePluginCardTests()
{
Directory.CreateDirectory(_root);
_store = new SettingsStore(new LocalDataPaths(_root));
}

private string SettingsPath => Path.Combine(_root, "settings.json");

public void Dispose() => Directory.Delete(_root, recursive: true);

[Fact]
public async Task PluginCardsAndDeveloperModeRoundTripThroughSaveAndLoad()
{
var accountId = Guid.NewGuid();
var cards = new[]
{
new OverlayCardPlacement(OverlayAddOnKind.Plugin, accountId, true, new OverlayBounds(0.1, 0.2, 0.3, 0.1))
{
PluginCard = "cody.goal-tracker/goal"
},
new OverlayCardPlacement(OverlayAddOnKind.Plugin, null, false, null)
{
PluginCard = "cody.goal-tracker/summary"
}
};

await _store.SaveAsync(PanelSettings.Default with { PluginDeveloperMode = true, OverlayCards = cards });
var loaded = await _store.LoadAsync();

Assert.True(loaded.PluginDeveloperMode);
Assert.Equal(cards, loaded.OverlayCards);
}

[Fact]
public async Task MalformedPluginCardsAreDroppedWithoutLosingOtherSettings()
{
var accountId = Guid.NewGuid();
await _store.SaveAsync(PanelSettings.Default with { ShowOverlaysInTheatreMode = false });
var json = JsonNode.Parse(await File.ReadAllTextAsync(SettingsPath))!.AsObject();
json["overlayCards"] = new JsonArray
{
new JsonObject { ["kind"] = 4, ["accountId"] = null, ["enabled"] = true },
new JsonObject { ["kind"] = 4, ["accountId"] = null, ["enabled"] = true, ["pluginCard"] = "" },
new JsonObject { ["kind"] = 4, ["accountId"] = null, ["enabled"] = true, ["pluginCard"] = "Not Valid" },
new JsonObject { ["kind"] = 4, ["accountId"] = null, ["enabled"] = true, ["pluginCard"] = 7 },
new JsonObject
{
["kind"] = 0, ["accountId"] = accountId.ToString(), ["enabled"] = true,
["pluginCard"] = "cody.goal-tracker/goal"
},
new JsonObject
{
["kind"] = 4, ["accountId"] = null, ["enabled"] = true, ["pluginCard"] = "cody.goal-tracker/summary"
}
};
await File.WriteAllTextAsync(SettingsPath, json.ToJsonString());

var loaded = await _store.LoadAsync();

Assert.False(loaded.ShowOverlaysInTheatreMode);
var kept = Assert.Single(loaded.OverlayCards);
Assert.Equal("cody.goal-tracker/summary", kept.PluginCard);
}
}
Loading
Loading