feat(editor): настройки экрана презентации при запуске сессии
Выбор монитора и полноэкранного режима в настройках; при «Запустить» окно презентации открывается на выбранном дисплее автоматически. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
|
||||
import { readPresentationSettings, writePresentationSettings } from './appPreferences';
|
||||
|
||||
void test('appPreferences: presentation settings round-trip without clobbering eula', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dnd-prefs-'));
|
||||
const prefsPath = path.join(dir, 'preferences.json');
|
||||
fs.writeFileSync(prefsPath, `${JSON.stringify({ eulaAcceptedVersion: 2 }, null, 2)}\n`, 'utf8');
|
||||
|
||||
writePresentationSettings(dir, { displayId: 42, fullScreen: false });
|
||||
const loaded = readPresentationSettings(dir);
|
||||
assert.equal(loaded.displayId, 42);
|
||||
assert.equal(loaded.fullScreen, false);
|
||||
|
||||
const raw = JSON.parse(fs.readFileSync(prefsPath, 'utf8')) as {
|
||||
eulaAcceptedVersion?: number;
|
||||
presentation?: { displayId: number | null; fullScreen: boolean };
|
||||
};
|
||||
assert.equal(raw.eulaAcceptedVersion, 2);
|
||||
assert.equal(raw.presentation?.displayId, 42);
|
||||
assert.equal(raw.presentation?.fullScreen, false);
|
||||
});
|
||||
|
||||
void test('appPreferences: defaults when preferences missing', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dnd-prefs-'));
|
||||
const loaded = readPresentationSettings(dir);
|
||||
assert.equal(loaded.displayId, null);
|
||||
assert.equal(loaded.fullScreen, true);
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import fs from 'node:fs';
|
||||
|
||||
import type { PresentationSettings } from '../../shared/types/presentationSettings';
|
||||
import { DEFAULT_PRESENTATION_SETTINGS } from '../../shared/types/presentationSettings';
|
||||
import { preferencesPath } from '../license/paths';
|
||||
|
||||
type StoredPreferences = {
|
||||
eulaAcceptedVersion?: number;
|
||||
presentation?: Partial<PresentationSettings>;
|
||||
};
|
||||
|
||||
function readAll(userData: string): StoredPreferences {
|
||||
try {
|
||||
const raw = fs.readFileSync(preferencesPath(userData), 'utf8');
|
||||
return JSON.parse(raw) as StoredPreferences;
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function writeAll(userData: string, prefs: StoredPreferences): void {
|
||||
fs.mkdirSync(userData, { recursive: true });
|
||||
fs.writeFileSync(preferencesPath(userData), `${JSON.stringify(prefs, null, 2)}\n`, 'utf8');
|
||||
}
|
||||
|
||||
export function readPresentationSettings(userData: string): PresentationSettings {
|
||||
const prefs = readAll(userData);
|
||||
return {
|
||||
...DEFAULT_PRESENTATION_SETTINGS,
|
||||
...prefs.presentation,
|
||||
};
|
||||
}
|
||||
|
||||
export function writePresentationSettings(
|
||||
userData: string,
|
||||
patch: Partial<PresentationSettings>,
|
||||
): PresentationSettings {
|
||||
const prefs = readAll(userData);
|
||||
const next: PresentationSettings = {
|
||||
...DEFAULT_PRESENTATION_SETTINGS,
|
||||
...prefs.presentation,
|
||||
...patch,
|
||||
};
|
||||
prefs.presentation = next;
|
||||
writeAll(userData, prefs);
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user