pxt-calliope/clients/electron/main.js

40 lines
823 B
JavaScript
Raw Permalink Normal View History

2016-09-21 07:02:18 +02:00
const {app, BrowserWindow, Menu} = require('electron')
2016-08-10 07:08:46 +02:00
const pxt = require('pxt-core')
2016-09-21 07:02:18 +02:00
const path = require('path')
2016-08-09 18:55:37 +02:00
2016-09-21 07:02:18 +02:00
let win
2016-08-09 18:55:37 +02:00
2016-09-21 07:02:18 +02:00
const cliPath = path.join(process.cwd(), "node_modules/pxt-microbit")
2016-08-09 18:55:37 +02:00
2016-09-21 07:02:18 +02:00
function startServerAndCreateWindow() {
pxt.mainCli(cliPath, ["serve", "-no-browser"])
createWindow()
}
2016-08-09 18:55:37 +02:00
2016-09-21 07:02:18 +02:00
function createWindow () {
win = new BrowserWindow({
width: 800,
height: 600,
title: "code the micro:bit"
})
Menu.setApplicationMenu(null)
win.loadURL(`file://${__dirname}/index.html#local_token=${pxt.globalConfig.localToken}`)
win.on('closed', () => {
win = null
2016-08-09 18:55:37 +02:00
})
}
2016-09-21 07:02:18 +02:00
app.on('ready', startServerAndCreateWindow)
2016-08-09 18:55:37 +02:00
2016-09-21 07:02:18 +02:00
app.on('window-all-closed', () => {
2016-08-09 18:55:37 +02:00
if (process.platform !== 'darwin') {
app.quit()
}
})
2016-09-21 07:02:18 +02:00
app.on('activate', () => {
if (win === null) {
2016-08-09 18:55:37 +02:00
createWindow()
}
})