Files
Iisyourdad 52fd516a5d
Template tests / tests (push) Failing after 29s
Make capture sessions continuous: click-capture + interval auto-capture
The session previously only listened for the global hotkey, which is
unreliable under WSLg/Wayland — users got one screenshot and nothing
more. Sessions now layer three triggers:

- click-capture via OS adapters (xinput test-xi2 on X11, PowerShell
  GetAsyncKeyState polling on Windows), debounced, ignoring clicks on
  StepForge itself
- interval auto-capture (3/5/10 s) as the always-works fallback,
  enabled by default when click detection is unavailable
- the existing global hotkey, plus a manual Shoot button

The REC bar now shows live count + active trigger with Shoot / Auto /
Pause / Finish. New captures and added steps are selected in the
editor (explicit reload(stepId) wins over a surviving selection).
Capture self-test hook (STEPFORGE_CAPTURE_SELFTEST) verifies 3x
hotkey-path captures and interval capture end-to-end.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 22:33:12 -05:00

96 lines
2.4 KiB
JavaScript

'use strict';
const path = require('node:path');
const { writeJsonSync, readJsonIfExists, deepClone } = require('./util');
const DEFAULT_SETTINGS = {
schemaVersion: 1,
appearance: 'system', // system | light | dark
language: 'en',
spellcheck: true,
capture: {
delayMs: 0,
mode: 'fullscreen', // fullscreen | window | region
includeCursor: true,
clickMarker: true,
clickMarkerColor: '#E5484D',
hotkeyCapture: 'CommandOrControl+Shift+1',
hotkeyPauseResume: 'CommandOrControl+Shift+2',
captureOutsideClicks: true,
confirmSimpleCapture: false,
autoIntervalSec: 5, // session fallback when click capture is unavailable
},
editor: {
focusedViewDefaultForNewSteps: false,
autoTitleTemplate: '[[Mode]] capture [[Time]]',
},
exports: {
previewStepCount: 3,
openFolderAfterExport: true,
lastOutputDirs: {}, // format -> dir
},
library: {
sortBy: 'updatedAt',
},
backups: {
automatic: true,
keepLast: 10,
everyNSaves: 25,
},
};
class Settings {
constructor(settingsDir) {
this.file = path.join(settingsDir, 'app-settings.json');
this.globalPlaceholdersFile = path.join(settingsDir, 'placeholders.json');
this.data = this.load();
}
load() {
const stored = readJsonIfExists(this.file, {});
return mergeDeep(deepClone(DEFAULT_SETTINGS), stored);
}
save() {
writeJsonSync(this.file, this.data);
return this.data;
}
get(keyPath) {
return keyPath.split('.').reduce((o, k) => (o == null ? undefined : o[k]), this.data);
}
set(keyPath, value) {
const keys = keyPath.split('.');
let obj = this.data;
for (const k of keys.slice(0, -1)) {
if (typeof obj[k] !== 'object' || obj[k] === null) obj[k] = {};
obj = obj[k];
}
obj[keys[keys.length - 1]] = value;
return this.save();
}
getGlobalPlaceholders() {
return readJsonIfExists(this.globalPlaceholdersFile, {});
}
setGlobalPlaceholders(values) {
writeJsonSync(this.globalPlaceholdersFile, values);
return values;
}
}
function mergeDeep(base, extra) {
for (const [k, v] of Object.entries(extra || {})) {
if (v && typeof v === 'object' && !Array.isArray(v) && base[k] && typeof base[k] === 'object' && !Array.isArray(base[k])) {
mergeDeep(base[k], v);
} else {
base[k] = v;
}
}
return base;
}
module.exports = { Settings, DEFAULT_SETTINGS };