mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-02-26 04:40:10 +08:00
chore: optimize code
This commit is contained in:
parent
f129465d28
commit
c861aaeb33
@ -12,32 +12,42 @@ if (!app.requestSingleInstanceLock()) {
|
||||
app.quit()
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
||||
|
||||
export const ROOT_PATH = {
|
||||
// /dist
|
||||
dist: join(__dirname, '../..'),
|
||||
// /dist or /public
|
||||
public: join(__dirname, app.isPackaged ? '../..' : '../../../public'),
|
||||
}
|
||||
|
||||
let win: BrowserWindow | null = null
|
||||
// Here, you can also use other preload
|
||||
const splash = join(__dirname, '../preload/splash.js')
|
||||
const preload = join(__dirname, '../preload/index.js')
|
||||
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin
|
||||
const url = `http://${process.env['VITE_DEV_SERVER_HOST']}:${process.env['VITE_DEV_SERVER_PORT']}`
|
||||
const indexHtml = join(ROOT_PATH.dist, 'index.html')
|
||||
|
||||
async function createWindow() {
|
||||
win = new BrowserWindow({
|
||||
title: 'Main window',
|
||||
icon: join(ROOT_PATH.public, 'favicon.ico'),
|
||||
webPreferences: {
|
||||
preload: splash,
|
||||
preload,
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
},
|
||||
})
|
||||
|
||||
if (app.isPackaged) {
|
||||
win.loadFile(join(__dirname, '../../index.html'))
|
||||
win.loadFile(indexHtml)
|
||||
} else {
|
||||
win.loadURL(url)
|
||||
// win.webContents.openDevTools()
|
||||
}
|
||||
|
||||
// Test active push message to Renderer-process
|
||||
// Test actively push message to the Electron-Renderer
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
win?.webContents.send('main-process-message', new Date().toLocaleString())
|
||||
})
|
||||
@ -74,17 +84,15 @@ app.on('activate', () => {
|
||||
})
|
||||
|
||||
// new window example arg: new windows url
|
||||
ipcMain.handle("open-win", (event, arg) => {
|
||||
ipcMain.handle('open-win', (event, arg) => {
|
||||
const childWindow = new BrowserWindow({
|
||||
webPreferences: {
|
||||
preload: splash,
|
||||
preload,
|
||||
},
|
||||
})
|
||||
|
||||
if (app.isPackaged) {
|
||||
childWindow.loadFile(join(__dirname, `../renderer/index.html`), {
|
||||
hash: `${arg}`,
|
||||
})
|
||||
childWindow.loadFile(indexHtml, { hash: arg })
|
||||
} else {
|
||||
childWindow.loadURL(`${url}/#${arg}`)
|
||||
// childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
|
||||
|
Loading…
x
Reference in New Issue
Block a user