/
Mativ
/
solo-master
Обзор
Документация
Войти
/
Mativ
/
solo-master
Код
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/services/WindowsService.ts
129 строк
4 KB
mativ
sound multiselect
17 май 2026, 15:50
17 май 2026, 15:50
c6c9570
Код
Авторство
О чём код?
import { app, BrowserWindow, Menu } from "electron"; import path from 'node:path'; import { MonitorService } from './MonitorService'; class WindowsServiceImpl { private main!: BrowserWindow; private view!: BrowserWindow; private splash!: BrowserWindow; create() { this.createSplash(); this.createMain(); this.createView(); this.createMenu(); this.view.hide(); } getMain(): BrowserWindow { return this.main; } sendImageToView(dataUrl: string): void { this.view.webContents.send('view-image', dataUrl); } sendViewTransformToView(transform: object): void { this.view.webContents.send('view-transform', transform); } hideView(): void { this.view.hide(); this.main.webContents.send('view-visibility-changed', false); } showView(displayIndex: number): void { this.view.show(); // On Wayland the compositor decides window placement, so don't try to set bounds if (!MonitorService.isWaylandNative()) { MonitorService.applyToWindow(this.view, displayIndex); } this.main.webContents.send('view-visibility-changed', true); const [width, height] = this.view.getContentSize(); this.main.webContents.send('view-resize', { width, height }); } private createSplash(): void { this.splash = new BrowserWindow({ width: 300, height: 180, frame: false, resizable: false, center: true, alwaysOnTop: true, }); this.splash.loadFile(path.join(app.getAppPath(), 'src/splash.html')); } private createMain(): void { this.main = new BrowserWindow({ width: 1920, height: 1080, show: false, webPreferences: { preload: path.join(__dirname, 'preload-main.js'), }, }); this.main.once('ready-to-show', () => { this.splash.close(); this.main.show(); }); this.main.on('closed', () => { app.quit(); }); // and load the index.html of the app. if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { this.main.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL); // Open the DevTools. this.main.webContents.openDevTools(); } else { this.main.loadFile( path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`), ); } } private createView(): void { this.view = new BrowserWindow({ width: 800, height: 600, frame: false, webPreferences: { preload: path.join(__dirname, 'preload-view.js'), }, }); this.view.on('resize', () => { const [width, height] = this.view.getContentSize(); this.main.webContents.send('view-resize', { width, height }); }); this.view.on('close', (event) => { if (this.main.isDestroyed()) return; event.preventDefault(); this.view.hide(); this.main.webContents.send('view-visibility-changed', false); }); // and load the index.html of the app. if (VIEW_WINDOW_VITE_DEV_SERVER_URL) { this.view.loadURL(VIEW_WINDOW_VITE_DEV_SERVER_URL); // Open the DevTools. // this.view.webContents.openDevTools(); } else { this.view.loadFile( path.join(__dirname, `../renderer/${VIEW_WINDOW_VITE_NAME}/index.html`), ); } } private createMenu() { Menu.setApplicationMenu(null) } } export const WindowsService = new WindowsServiceImpl();