blockbench/main.js

90 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-02-03 21:09:35 +01:00
const {app, BrowserWindow, Menu} = require('electron')
2017-10-26 19:00:52 +02:00
const path = require('path')
const url = require('url')
2019-02-03 21:09:35 +01:00
let orig_win;
2017-10-26 19:00:52 +02:00
2019-02-03 21:09:35 +01:00
function createWindow() {
if (!app.requestSingleInstanceLock()) {
return;
}
let win = new BrowserWindow({
2018-10-17 19:50:25 +02:00
icon:'icon.ico',
show: false,
backgroundColor: '#21252b',
webPreferences: {
//experimentalFeatures: true,
webgl: true,
2018-12-29 12:26:02 +01:00
webSecurity: true,
nodeIntegration: true
2018-10-17 19:50:25 +02:00
}
})
2019-02-03 21:09:35 +01:00
if (!orig_win) orig_win = win;
2018-10-17 19:50:25 +02:00
var index_path = path.join(__dirname, 'index.html')
2019-02-03 21:09:35 +01:00
if (process.platform === 'darwin') {
var template = [{
label: 'File',
submenu: [{
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click: function() {
app.quit();
}
}]
}, {
label: 'Edit',
submenu: [{
label: 'Cut',
accelerator: 'CmdOrCtrl+X',
selector: 'cut:'
}, {
label: 'Copy',
accelerator: 'CmdOrCtrl+C',
selector: 'copy:'
}, {
label: 'Paste',
accelerator: 'CmdOrCtrl+V',
selector: 'paste:'
}, {
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
selector: 'selectAll:'
}]
}]
var osxMenu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(osxMenu)
} else {
win.setMenu(null);
}
2018-10-17 19:50:25 +02:00
win.maximize()
win.show()
win.loadURL(url.format({
pathname: index_path,
protocol: 'file:',
slashes: true
}))
win.on('closed', () => {
win = null
})
//win.webContents.openDevTools()
2017-10-26 19:00:52 +02:00
}
2019-02-03 21:09:35 +01:00
app.on('second-instance', function (event, argv, cwd) {
process.argv = argv
createWindow()
})
2018-10-17 19:50:25 +02:00
app.commandLine.appendSwitch('ignore-gpu-blacklist')
2019-01-09 15:54:35 +01:00
2017-10-26 19:00:52 +02:00
app.on('ready', createWindow)
app.on('window-all-closed', () => {
2018-12-29 12:26:02 +01:00
app.quit()
2017-10-26 19:00:52 +02:00
})
app.on('activate', () => {
2018-10-17 19:50:25 +02:00
if (win === null) {
createWindow()
}
2019-01-09 15:54:35 +01:00
})