mirror of
https://github.com/JannisX11/blockbench.git
synced 2024-11-27 04:21:46 +08:00
90 lines
1.8 KiB
JavaScript
90 lines
1.8 KiB
JavaScript
const {app, BrowserWindow, Menu} = require('electron')
|
|
const path = require('path')
|
|
const url = require('url')
|
|
|
|
let orig_win;
|
|
|
|
function createWindow() {
|
|
if (app.requestSingleInstanceLock && !app.requestSingleInstanceLock()) {
|
|
return;
|
|
}
|
|
let win = new BrowserWindow({
|
|
icon:'icon.ico',
|
|
show: false,
|
|
backgroundColor: '#21252b',
|
|
webPreferences: {
|
|
//experimentalFeatures: true,
|
|
webgl: true,
|
|
webSecurity: true,
|
|
nodeIntegration: true
|
|
}
|
|
})
|
|
if (!orig_win) orig_win = win;
|
|
var index_path = path.join(__dirname, 'index.html')
|
|
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);
|
|
}
|
|
win.maximize()
|
|
win.show()
|
|
win.loadURL(url.format({
|
|
pathname: index_path,
|
|
protocol: 'file:',
|
|
slashes: true
|
|
}))
|
|
win.on('closed', () => {
|
|
win = null
|
|
})
|
|
//win.webContents.openDevTools()
|
|
}
|
|
|
|
app.on('second-instance', function (event, argv, cwd) {
|
|
process.argv = argv
|
|
createWindow()
|
|
})
|
|
|
|
app.commandLine.appendSwitch('ignore-gpu-blacklist')
|
|
|
|
app.on('ready', createWindow)
|
|
|
|
app.on('window-all-closed', () => {
|
|
app.quit()
|
|
})
|
|
|
|
app.on('activate', () => {
|
|
/*if (win === null) {
|
|
createWindow()
|
|
}*/
|
|
})
|