initial commit
This commit is contained in:
commit
13ae6c773c
36 files changed
+24137
No files matched your search
@@ -0,0 +1,81 @@
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import path from 'path'
|
||||
import Constants from './utils/Constants'
|
||||
|
||||
export default class MainRunner {
|
||||
static async createMainWindow (mainWindow) {
|
||||
mainWindow = new BrowserWindow({
|
||||
show: false,
|
||||
width: Constants.IS_DEV_ENV ? 1500 : 1200,
|
||||
height: 650,
|
||||
icon: path.join(__static, Constants.APP_ICON),
|
||||
title: Constants.APP_NAME,
|
||||
useContentSize: true,
|
||||
webPreferences: Constants.DEFAULT_WEB_PREFERENCES
|
||||
})
|
||||
|
||||
mainWindow.setMenu(null)
|
||||
mainWindow.on('close', (event) => {
|
||||
event.preventDefault()
|
||||
MainRunner.exitApp(mainWindow)
|
||||
})
|
||||
|
||||
mainWindow.on('show', () => {
|
||||
mainWindow.focus()
|
||||
})
|
||||
|
||||
mainWindow.webContents.on('did-frame-finish-load', () => {
|
||||
if (Constants.IS_DEV_ENV) {
|
||||
mainWindow.webContents.openDevTools()
|
||||
}
|
||||
})
|
||||
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
mainWindow.setAlwaysOnTop(true)
|
||||
mainWindow.show()
|
||||
mainWindow.setAlwaysOnTop(false)
|
||||
})
|
||||
|
||||
await mainWindow.loadURL(`${Constants.APP_INDEX_URL}`)
|
||||
|
||||
return mainWindow
|
||||
}
|
||||
|
||||
static createCrashWindow (crashWindow, mainWindow, details) {
|
||||
if (!Constants.IS_DEV_ENV) {
|
||||
mainWindow?.hide()
|
||||
}
|
||||
|
||||
crashWindow = new BrowserWindow({
|
||||
show: false,
|
||||
title: Constants.APP_NAME,
|
||||
icon: path.join(__static, Constants.APP_ICON),
|
||||
resizable: Constants.IS_DEV_ENV,
|
||||
webPreferences: Constants.DEFAULT_WEB_PREFERENCES
|
||||
})
|
||||
crashWindow.setMenu(null)
|
||||
crashWindow.loadURL(`${Constants.APP_INDEX_URL}#/crash`).then(() => true)
|
||||
crashWindow.on('ready-to-show', () => {
|
||||
if (!Constants.IS_DEV_ENV && mainWindow && !mainWindow.isDestroyed()) {
|
||||
mainWindow.destroy()
|
||||
}
|
||||
crashWindow.show()
|
||||
crashWindow.focus()
|
||||
})
|
||||
crashWindow.webContents.on('did-frame-finish-load', () => {
|
||||
if (Constants.IS_DEV_ENV) {
|
||||
crashWindow.webContents.openDevTools()
|
||||
}
|
||||
})
|
||||
|
||||
return crashWindow
|
||||
}
|
||||
|
||||
static exitApp (mainWindow) {
|
||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
mainWindow.hide()
|
||||
}
|
||||
mainWindow = null
|
||||
app.exit()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { app } from 'electron'
|
||||
import './index'
|
||||
import * as electronDevtoolsInstaller from 'electron-devtools-installer'
|
||||
|
||||
app.on('ready', async () => {
|
||||
await electronDevtoolsInstaller.default(electronDevtoolsInstaller.VUEJS_DEVTOOLS)
|
||||
.catch(e => {
|
||||
console.log(`Failed to install Vue Devtools \n(${e})`)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import { app } from 'electron'
|
||||
import path from 'path'
|
||||
import MainRunner from './MainRunner'
|
||||
import { fileURLToPath } from 'url'
|
||||
import Constants from './utils/Constants'
|
||||
import electronRemote from '@electron/remote/main'
|
||||
|
||||
let mainWindow
|
||||
let crashWindow
|
||||
|
||||
if (!Constants.IS_DEV_ENV) {
|
||||
global.__static = path.join(path.dirname(fileURLToPath(import.meta.url)), '/static')
|
||||
.replace(/\\/g, '\\\\')
|
||||
}
|
||||
|
||||
app.on('ready', () => {
|
||||
electronRemote.initialize()
|
||||
|
||||
mainWindow = MainRunner.createMainWindow(mainWindow)
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
if (!mainWindow) {
|
||||
mainWindow = MainRunner.createMainWindow(mainWindow)
|
||||
}
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
mainWindow = null
|
||||
|
||||
if (!Constants.IS_MAC) {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('render-process-gone', (ev, webContents, details) => {
|
||||
crashWindow = MainRunner.createCrashWindow(crashWindow, mainWindow, details)
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
import path from 'path'
|
||||
import os from 'os'
|
||||
import { app } from 'electron'
|
||||
|
||||
export default class Constants {
|
||||
static APP_NAME = 'Vutron'
|
||||
static APP_ICON = 'app-icon.png'
|
||||
|
||||
static IS_DEV_ENV = process.env.NODE_ENV === 'development'
|
||||
|
||||
static IS_MAC = os.platform() === 'darwin'
|
||||
|
||||
static DEFAULT_WEB_PREFERENCES = {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
nodeIntegrationInWorker: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
|
||||
static APP_INDEX_URL = process.env.NODE_ENV === 'development'
|
||||
? 'http://localhost:9080/index.html'
|
||||
: path.join('file://', app.getAppPath(), '/dist/electron/index.html')
|
||||
}
|
||||
Reference in new issue
Block a user