feat: boot-экран, стабильность Windows и оптимизация Pixi/пульта
- Экран загрузки (boot.html, bootWindow): статусы, ensureRoots и проверка лицензии, редактор после готовности; закрытие через destroy при closable:false. - Упакованное приложение на Windows: disableHardwareAcceleration, sandbox выкл. вне dev, отложенный показ редактора, ensureWindowBecomesVisible, фокус на splash при second-instance. - Vite: вход boot.html; eslint: игнор release/; тесты boot и maxFPS тикера. - Пульт: позиция курсора кисти через ref/DOM без setState на каждый move; черновик эффекта через rAF; Pixi: maxFPS 32, resolution cap, antialias off, debounce ResizeObserver, меньше частиц poisonCloud, contain на хосте. Made-with: Cursor
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
import { app, BrowserWindow, nativeImage, screen } from 'electron';
|
||||
|
||||
import { getBootSplashWindow } from './bootWindow';
|
||||
|
||||
type WindowKind = 'editor' | 'presentation' | 'control';
|
||||
|
||||
const windows = new Map<WindowKind, BrowserWindow>();
|
||||
@@ -24,15 +25,29 @@ function isDev() {
|
||||
return process.env.NODE_ENV === 'development' || process.env.VITE_DEV_SERVER_URL !== undefined;
|
||||
}
|
||||
|
||||
function getRendererUrl(kind: WindowKind): string {
|
||||
/** Вне dev-сервера на Windows с `loadFile` + preload иногда ломается sandbox; оставляем изоляцию через preload/contextBridge. */
|
||||
function shouldUseRendererSandbox(): boolean {
|
||||
if (process.env.VITE_DEV_SERVER_URL) return true;
|
||||
return process.platform !== 'win32';
|
||||
}
|
||||
|
||||
function getRendererHtmlPath(kind: WindowKind): string {
|
||||
return path.join(app.getAppPath(), 'dist', 'renderer', `${kind}.html`);
|
||||
}
|
||||
|
||||
/**
|
||||
* В production `loadURL(file://…)` на Windows с asar иногда даёт чёрный экран;
|
||||
* `loadFile` корректно открывает HTML из asar и на Windows, и на macOS.
|
||||
*/
|
||||
function loadWindowPage(win: BrowserWindow, kind: WindowKind): void {
|
||||
const dev = process.env.VITE_DEV_SERVER_URL;
|
||||
if (dev) {
|
||||
const page =
|
||||
kind === 'editor' ? 'editor.html' : kind === 'presentation' ? 'presentation.html' : 'control.html';
|
||||
return new URL(page, dev).toString();
|
||||
void win.loadURL(new URL(page, dev).toString());
|
||||
return;
|
||||
}
|
||||
const filePath = path.join(app.getAppPath(), 'dist', 'renderer', `${kind}.html`);
|
||||
return pathToFileURL(filePath).toString();
|
||||
void win.loadFile(getRendererHtmlPath(kind));
|
||||
}
|
||||
|
||||
function getPreloadPath(): string {
|
||||
@@ -121,9 +136,35 @@ export function applyDockIconIfNeeded(): void {
|
||||
type CreateWindowOpts = {
|
||||
/** Дочернее окно (например пульт) держится над родителем (экран просмотра). */
|
||||
parent?: BrowserWindow;
|
||||
/** Только редактор: не показывать окно до `show()` (экран загрузки). */
|
||||
deferVisibility?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Только `ready-to-show` на части систем (первый холодный старт Windows) не приходит вовремя —
|
||||
* окно остаётся с `show: false` и кажется «зависшим». Дублируем показ по `did-finish-load` и таймауту.
|
||||
*/
|
||||
function ensureWindowBecomesVisible(win: BrowserWindow): void {
|
||||
let shown = false;
|
||||
const showOnce = (): void => {
|
||||
if (shown) return;
|
||||
if (win.isDestroyed()) return;
|
||||
shown = true;
|
||||
win.show();
|
||||
};
|
||||
|
||||
win.once('ready-to-show', showOnce);
|
||||
win.webContents.once('did-finish-load', () => {
|
||||
showOnce();
|
||||
});
|
||||
const safetyTimer = setTimeout(showOnce, 8000);
|
||||
win.once('closed', () => {
|
||||
clearTimeout(safetyTimer);
|
||||
});
|
||||
}
|
||||
|
||||
function createWindow(kind: WindowKind, opts?: CreateWindowOpts): BrowserWindow {
|
||||
const deferEditor = kind === 'editor' && opts?.deferVisibility === true;
|
||||
const icon = resolveWindowIcon();
|
||||
const win = new BrowserWindow({
|
||||
width: kind === 'editor' ? 1280 : kind === 'control' ? 1200 : 1280,
|
||||
@@ -134,11 +175,13 @@ function createWindow(kind: WindowKind, opts?: CreateWindowOpts): BrowserWindow
|
||||
...(opts?.parent ? { parent: opts.parent } : {}),
|
||||
webPreferences: {
|
||||
contextIsolation: true,
|
||||
sandbox: true,
|
||||
sandbox: shouldUseRendererSandbox(),
|
||||
nodeIntegration: false,
|
||||
devTools: isDev(),
|
||||
devTools: isDev() || process.env.DND_OPEN_DEVTOOLS === '1',
|
||||
preload: getPreloadPath(),
|
||||
autoplayPolicy: 'no-user-gesture-required',
|
||||
// file:// + бандл Vite: без этого на Windows часто не грузятся чанки; http:// (dev server) оставляем строгим.
|
||||
webSecurity: Boolean(process.env.VITE_DEV_SERVER_URL),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -148,9 +191,14 @@ function createWindow(kind: WindowKind, opts?: CreateWindowOpts): BrowserWindow
|
||||
win.webContents.on('did-fail-load', (_event, errorCode, errorDescription, validatedURL) => {
|
||||
console.error(`[did-fail-load] ${String(errorCode)} ${errorDescription} ${validatedURL}`);
|
||||
});
|
||||
win.webContents.on('render-process-gone', (_event, details) => {
|
||||
console.error('[render-process-gone]', details.reason, details.exitCode);
|
||||
});
|
||||
|
||||
win.once('ready-to-show', () => win.show());
|
||||
void win.loadURL(getRendererUrl(kind));
|
||||
if (!deferEditor) {
|
||||
ensureWindowBecomesVisible(win);
|
||||
}
|
||||
loadWindowPage(win, kind);
|
||||
if (kind === 'editor') {
|
||||
win.on('close', (e) => {
|
||||
if (appQuitting) return;
|
||||
@@ -169,7 +217,47 @@ export function createWindows() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Редактор создаётся скрытым до окончания экрана загрузки. */
|
||||
export function createEditorWindowDeferred(): BrowserWindow {
|
||||
const existing = windows.get('editor');
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
return createWindow('editor', { deferVisibility: true });
|
||||
}
|
||||
|
||||
/** Дождаться первой отрисовки редактора (готовность к показу без чёрного экрана). */
|
||||
export function waitForEditorWindowReady(win: BrowserWindow): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
let settled = false;
|
||||
const timer = setTimeout(() => {
|
||||
if (!settled) {
|
||||
settled = true;
|
||||
resolve(undefined);
|
||||
}
|
||||
}, 35000);
|
||||
const finish = (): void => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
resolve(undefined);
|
||||
};
|
||||
win.once('ready-to-show', finish);
|
||||
win.webContents.once('did-finish-load', finish);
|
||||
}).then(
|
||||
() =>
|
||||
new Promise<void>((r) => {
|
||||
setTimeout(r, 120);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function focusEditorWindow(): void {
|
||||
const splash = getBootSplashWindow();
|
||||
if (splash && !splash.isDestroyed()) {
|
||||
splash.focus();
|
||||
return;
|
||||
}
|
||||
const win = windows.get('editor');
|
||||
if (win) {
|
||||
if (win.isMinimized()) win.restore();
|
||||
|
||||
Reference in New Issue
Block a user