Polish Electron desktop shell

This commit is contained in:
th committed 2026-06-05 17:34:50 +02:00
1 parent 70cf131c47
commit 32cc3ecec3
8 files changed
+249 -8

No files matched your search

+116 -7
View File
@@ -4,9 +4,17 @@ import path from 'node:path'
const isDev = !app.isPackaged
const devServerUrl = process.env.VITE_DEV_SERVER_URL ?? 'http://localhost:5200'
const appIconPath = isDev
? path.join(process.cwd(), 'build', 'icon.png')
: path.join(process.resourcesPath, 'build', 'icon.png')
let mainWindow: BrowserWindowInstance | null = null
function sendAppCommand(command: string): void {
if (!mainWindow || mainWindow.isDestroyed()) return
mainWindow.webContents.send('ruwio:menu-command', command)
}
function createMainWindow(): void {
mainWindow = new BrowserWindow({
width: 1280,
@@ -14,6 +22,7 @@ function createMainWindow(): void {
minWidth: 1024,
minHeight: 700,
title: 'RUWIO',
icon: appIconPath,
show: false,
backgroundColor: '#14171f',
webPreferences: {
@@ -55,13 +64,38 @@ function createMenu(): void {
{
label: 'File',
submenu: [
{ label: 'New Project', accelerator: 'CmdOrCtrl+N', enabled: false },
{ label: 'Open...', accelerator: 'CmdOrCtrl+O', enabled: false },
{
label: 'New Project',
accelerator: 'CmdOrCtrl+N',
click: () => sendAppCommand('new-project'),
},
{
label: 'Open...',
accelerator: 'CmdOrCtrl+O',
click: () => sendAppCommand('open-project'),
},
{
label: 'Recent Projects',
accelerator: 'CmdOrCtrl+Shift+O',
click: () => sendAppCommand('recent-projects'),
},
{ type: 'separator' },
{ label: 'Save', accelerator: 'CmdOrCtrl+S', enabled: false },
{ label: 'Save As...', accelerator: 'CmdOrCtrl+Shift+S', enabled: false },
{
label: 'Save',
accelerator: 'CmdOrCtrl+S',
click: () => sendAppCommand('save-project'),
},
{
label: 'Save As...',
accelerator: 'CmdOrCtrl+Shift+S',
click: () => sendAppCommand('save-project-as'),
},
{ type: 'separator' },
{ label: 'Export...', accelerator: 'CmdOrCtrl+E', enabled: false },
{
label: 'Export...',
accelerator: 'CmdOrCtrl+E',
click: () => sendAppCommand('export-project'),
},
{ type: 'separator' },
process.platform === 'darwin' ? { role: 'close' } : { role: 'quit' },
],
@@ -69,13 +103,27 @@ function createMenu(): void {
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{
label: 'Undo',
accelerator: 'CmdOrCtrl+Z',
click: () => sendAppCommand('undo'),
},
{
label: 'Redo',
accelerator: 'CmdOrCtrl+Shift+Z',
click: () => sendAppCommand('redo'),
},
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Copy Current Frame',
accelerator: 'CmdOrCtrl+Alt+C',
click: () => sendAppCommand('copy-current-frame'),
},
],
},
{
@@ -85,6 +133,43 @@ function createMenu(): void {
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{
label: 'Play / Pause',
accelerator: 'Space',
click: () => sendAppCommand('toggle-playback'),
},
{
label: 'Stop',
accelerator: 'Escape',
click: () => sendAppCommand('stop-playback'),
},
{
label: 'Jump to Start',
accelerator: 'R',
click: () => sendAppCommand('rewind'),
},
{
label: 'Fullscreen Preview',
accelerator: 'Shift+Space',
click: () => sendAppCommand('fullscreen-preview'),
},
{ type: 'separator' },
{
label: 'Toggle Side Panels',
accelerator: 'Tab',
click: () => sendAppCommand('toggle-panels'),
},
{
label: 'Media Library',
accelerator: 'CmdOrCtrl+M',
click: () => sendAppCommand('media-library'),
},
{
label: 'Document Settings',
accelerator: 'CmdOrCtrl+,',
click: () => sendAppCommand('document-settings'),
},
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
@@ -99,6 +184,30 @@ function createMenu(): void {
{ role: 'zoom' },
],
},
{
label: 'Help',
submenu: [
{
label: 'RUWIO Help',
accelerator: 'F1',
click: () => sendAppCommand('help'),
},
{
label: 'About RUWIO',
click: () => sendAppCommand('about'),
},
...(isDev
? [
{ type: 'separator' as const },
{
label: 'Open Test Runner',
accelerator: 'CmdOrCtrl+Shift+Alt+T',
click: () => sendAppCommand('test-runner'),
},
]
: []),
],
},
]
if (process.platform === 'darwin') {
+8 -1
View File
@@ -1,4 +1,4 @@
import { contextBridge } from 'electron'
import { contextBridge, ipcRenderer } from 'electron'
contextBridge.exposeInMainWorld('ruwioDesktop', {
platform: process.platform,
@@ -7,4 +7,11 @@ contextBridge.exposeInMainWorld('ruwioDesktop', {
chrome: process.versions.chrome,
node: process.versions.node,
},
onMenuCommand(callback: (command: string) => void) {
const listener = (_event: Electron.IpcRendererEvent, command: string) => callback(command)
ipcRenderer.on('ruwio:menu-command', listener)
return () => {
ipcRenderer.removeListener('ruwio:menu-command', listener)
}
},
})