Files
md-preview-desktop/src/main/create-window.ts
andres 2acfa56c1c chore: finish refactoring
feat: make watcher track directory changes
2023-12-08 18:40:26 +01:00

46 lines
1.2 KiB
TypeScript

import { join } from 'path'
import { is } from '@electron-toolkit/utils'
import { BrowserWindow, shell } from 'electron'
import icon from '../../resources/icon.png?asset'
export function createWindow(): BrowserWindow {
const mainWindow = new BrowserWindow({
autoHideMenuBar: true,
height: 670,
show: false,
width: 900,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: false,
},
})
mainWindow.on('ready-to-show', () => {
mainWindow?.show()
})
mainWindow.webContents.setWindowOpenHandler(details => {
shell.openExternal(details.url)
return { action: 'deny' }
})
mainWindow.webContents.on('will-navigate', (event, url) => {
event.preventDefault()
shell.openExternal(url)
})
// HMR for renderer base on electron-vite cli.
// Load the remote URL for development or the local html file for production.
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
} else {
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
}
return mainWindow
}