feature: 在应用未打包时自动打开 devTools

This commit is contained in:
SaberAlter 2022-07-27 00:05:20 +08:00
parent 858ea14cfa
commit aec9a41f66

View File

@ -2,6 +2,8 @@ import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'os' import { release } from 'os'
import { join } from 'path' import { join } from 'path'
const { isPackaged } = app
// Disable GPU Acceleration for Windows 7 // Disable GPU Acceleration for Windows 7
if (release().startsWith('6.1')) app.disableHardwareAcceleration() if (release().startsWith('6.1')) app.disableHardwareAcceleration()
@ -46,13 +48,16 @@ async function createWindow() {
}, },
}) })
if (app.isPackaged) { if (isPackaged) {
win.loadFile(indexHtml) win.loadFile(indexHtml)
} else { } else {
win.loadURL(url) win.loadURL(url)
// win.webContents.openDevTools() // win.webContents.openDevTools()
} }
// Open devTool if the app is not packaged
!isPackaged && win.webContents.openDevTools()
// Test actively push message to the Electron-Renderer // Test actively push message to the Electron-Renderer
win.webContents.on('did-finish-load', () => { win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString()) win?.webContents.send('main-process-message', new Date().toLocaleString())