feat: initialize Multi-PHP server project with Electron, React, and service management infrastructure
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { app, shell, BrowserWindow, Tray, Menu, nativeImage } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import { registerIpcHandlers } from './ipc'
|
||||
|
||||
let tray: Tray | null = null
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
|
||||
function createTray(): void {
|
||||
// Use a simple colored pixel if no icon is available for now
|
||||
const icon = nativeImage.createFromPath(join(__dirname, '../../resources/icon.png'))
|
||||
tray = new Tray(icon.isEmpty() ? nativeImage.createEmpty() : icon)
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{ label: 'Trunçgil Multi-PHP', enabled: false },
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Göster/Gizle', click: () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isVisible()) mainWindow.hide()
|
||||
else mainWindow.show()
|
||||
}
|
||||
}
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{ label: 'Başlat (Tüm Servisler)', click: () => { /* TODO: Start services */ } },
|
||||
{ label: 'Durdur (Tüm Servisler)', click: () => { /* TODO: Stop services */ } },
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Çıkış', click: () => {
|
||||
app.quit()
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
tray.setToolTip('Trunçgil Multi-PHP Server')
|
||||
tray.setContextMenu(contextMenu)
|
||||
|
||||
tray.on('double-click', () => {
|
||||
if (mainWindow) mainWindow.show()
|
||||
})
|
||||
}
|
||||
|
||||
function createWindow(): void {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1000,
|
||||
height: 750,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false
|
||||
}
|
||||
})
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
if (mainWindow) mainWindow.show()
|
||||
})
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
electronApp.setAppUserModelId('com.electron')
|
||||
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
createWindow()
|
||||
createTray()
|
||||
registerIpcHandlers()
|
||||
|
||||
app.on('activate', function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
})
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
// Overriding default behavior: stay in tray if all windows closed
|
||||
// unless on certain platforms where we really want to quit.
|
||||
// For this server app, we often want it to stay alive in Tray.
|
||||
if (process.platform === 'darwin') {
|
||||
// macOS behavior
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user