blockbench/main.js

93 lines
1.9 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-04-07 18:53:33 +02:00
function createWindow(second_instance) {
2019-03-09 22:06:35 +01:00
if (app.requestSingleInstanceLock && !app.requestSingleInstanceLock()) {
2019-02-03 21:09:35 +01:00
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
})
2019-04-07 18:53:33 +02:00
if (second_instance === true) {
win.webContents.second_instance = true
}
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
2019-04-07 18:53:33 +02:00
createWindow(true)
2019-02-03 21:09:35 +01:00
})
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', () => {
2019-03-09 22:06:35 +01:00
/*if (win === null) {
2018-10-17 19:50:25 +02:00
createWindow()
2019-03-09 22:06:35 +01:00
}*/
2019-01-09 15:54:35 +01:00
})