1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 07:26:36 +01:00
Whalebird-desktop-client-ma.../main/background.ts
2023-11-02 01:20:27 +09:00

48 lines
1.1 KiB
TypeScript

import path from 'path'
import { app, ipcMain, shell, IpcMainInvokeEvent } from 'electron'
import serve from 'electron-serve'
import { createWindow } from './helpers'
const isProd = process.env.NODE_ENV === 'production'
if (isProd) {
serve({ directory: 'app' })
} else {
app.setPath('userData', `${app.getPath('userData')} (development)`)
}
;(async () => {
await app.whenReady()
const mainWindow = createWindow('main', {
width: 1000,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
webSecurity: false,
preload: path.join(__dirname, 'preload.js')
}
})
if (isProd) {
await mainWindow.loadURL('app://./')
} else {
const port = process.argv[2]
await mainWindow.loadURL(`http://localhost:${port}/`)
mainWindow.webContents.openDevTools()
}
})()
app.on('window-all-closed', () => {
app.quit()
})
ipcMain.on('message', async (event, arg) => {
event.reply('message', `${arg} World!`)
})
ipcMain.handle('open-browser', (_event: IpcMainInvokeEvent, url: string) => {
shell.openExternal(url)
})