Spaces:
Running
Running
File size: 1,510 Bytes
40f8c9b 290f6a9 40f8c9b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // Demo mode: a pure view filter. Activating snapshots the session and group IDs
// that exist right now and hides them from the sidebar/overview, so the Space
// reads like a fresh install (empty workspace + welcome). Nothing is deleted —
// live sessions keep running, logins and secrets stay valid — and anything
// created *after* activation shows through (it isn't in the snapshot).
// Deactivating clears the snapshot and every real session reappears untouched.
import fs from 'fs';
import path from 'path';
import { DATA_DIR } from './config.js';
const FILE = path.join(DATA_DIR, 'demo.json');
let state = { active: false, sessions: [], groups: [] };
export function init() {
try {
const p = JSON.parse(fs.readFileSync(FILE, 'utf8'));
state = { active: !!p.active, sessions: p.sessions || [], groups: p.groups || [] };
} catch { /* no file yet → inactive */ }
}
function persist() {
try { fs.writeFileSync(FILE, JSON.stringify(state)); }
catch (e) { console.error('[demo.persist]', e && e.message); }
}
export const active = () => state.active;
export const hiddenSessions = () => new Set(state.sessions);
export const hiddenGroups = () => new Set(state.groups);
// Snapshot the currently-visible sessions/groups as the hidden set.
export function activate(sessionIds, groupIds) {
state = { active: true, sessions: [...sessionIds], groups: [...groupIds] };
persist();
}
export function deactivate() {
state = { active: false, sessions: [], groups: [] };
persist();
}
|