-
Notifications
You must be signed in to change notification settings - Fork 228
/
main.js
44 lines (37 loc) · 1.31 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const electron = require('electron')
const { resolve } = require('path')
const { execSync } = require('child_process')
const tryCatch = require('./src/try-catch')
const { app } = electron
const { BrowserWindow } = electron
// enable chrome dev-tools when builded
// require('electron-debug')({ enabled: true, showDevTools: true })
let win
const createWindow = () => {
win = new BrowserWindow({ width: 800, height: 800 })
win.maximize()
win.loadURL(`file://${__dirname}/index.html`)
// open external URLs into default browser
win.webContents.on('new-window', (e, url) => {
e.preventDefault()
execSync(`open ${url}`)
})
win.on('closed', () => { win = null })
}
app.on('ready', () => {
const tmp = require('tmp')
tmp.dir((err, path) => {
if (err) throw err
global.tmpProjectPath = path
createWindow()
execSync(`cp -R ${resolve(__dirname, 'xcode-project')} ${resolve(path)}`)
execSync(`open ${resolve(path, 'xcode-project/pokemon-webspoof.xcodeproj')}`)
// quit xcode && remove tmp directory on exit
app.on('before-quit', () => {
tryCatch(() => execSync('killall Xcode'))
tryCatch(() => execSync(`rm -rf ${path}`))
})
})
})
app.on('window-all-closed', () => (process.platform !== 'darwin') && app.quit())
app.on('activate', () => (win === null) && createWindow())