This commit is contained in:
parent
1602cef5cd
commit
75fdd5daf3
28
main.js
28
main.js
|
@ -1,22 +1,27 @@
|
|||
// Modules to control application life and create native browser window
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const path = require('path')
|
||||
const {app, BrowserWindow, shell} = require('electron')
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
// webPreferences: {
|
||||
// preload: path.join(__dirname, 'preload.js')
|
||||
// }
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
}
|
||||
})
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadFile('frontend/index.html')
|
||||
// Open external links in the browser
|
||||
mainWindow.webContents.on('new-window', function (e, url) {
|
||||
e.preventDefault()
|
||||
shell.openExternal(url)
|
||||
})
|
||||
|
||||
// Hide the toolbar
|
||||
mainWindow.setMenuBarVisibility(false)
|
||||
|
||||
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools()
|
||||
// mainWindow.webContents.openDevTools()
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
|
@ -35,9 +40,6 @@ app.whenReady().then(() => {
|
|||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', function () {
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
||||
|
|
67
src/index.js
67
src/index.js
|
@ -1,67 +0,0 @@
|
|||
const {app, BrowserWindow, protocol, shell} = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
const frontendAssetsPath = 'frontend/'
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const win = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
},
|
||||
})
|
||||
|
||||
// Remove external links in the browser
|
||||
win.webContents.on('new-window', function (e, url) {
|
||||
e.preventDefault()
|
||||
shell.openExternal(url)
|
||||
})
|
||||
|
||||
// Hide the toolbar
|
||||
win.setMenuBarVisibility(false)
|
||||
|
||||
const p = path.normalize(`${__dirname}/../${frontendAssetsPath}index.html`)
|
||||
|
||||
// The starting point of the app
|
||||
win.loadFile(p)
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
const root = path.normalize(`${__dirname}/..`)
|
||||
|
||||
// file:// interceptor to serve all assets without running a web server in the background
|
||||
protocol.interceptFileProtocol('file', (request, callback) => {
|
||||
let url = request.url.substr(7) /* all urls start with 'file://' */
|
||||
if (!url.startsWith(root)) {
|
||||
if (url.startsWith('css/fonts') || url.startsWith('css/img')) {
|
||||
url = url.substr(4)
|
||||
}
|
||||
url = path.normalize(`${root}/${frontendAssetsPath}${url}`)
|
||||
}
|
||||
callback({path: url})
|
||||
})
|
||||
|
||||
createWindow()
|
||||
})
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user