-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (66 loc) · 1.9 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict'
const electron = require('electron')
const app = electron.app
const minimist = require('minimist')
const argv = minimist(process.argv.slice(2))
const path = require('path')
const debug = require('debug')('electron-scope:app')
// params
const script_path = argv['path'] || process.argv[2]
console.log('Electron-scope is debugging: "' + script_path + '"')
if (!script_path) {
throw new Error('Script path required')
}
// reloads electron process on file changes
const watched_path = script_path.replace(/([^\/]+)$/, '')
require('./modules/electron-reload')(watched_path);
debug('Watching for file changes within ', watched_path)
// adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')()
// prevent window being garbage collected
let mainWindow
function onClosed() {
// dereference the window
// for multiple windows store them in an array
mainWindow = null
}
function createMainWindow() {
const win = new electron.BrowserWindow({
width: 600,
height: 400,
webPreferences: {
nodeIntegration: true
}
})
if (script_path.match(/\.html?$/)) {
debug('Loading html app as electron-scope html window render process')
win.loadURL('file://' + path.resolve(script_path))
win.webContents.openDevTools({mode: 'right'})
} else {
debug('Embedding node app within electron-scope html window render process')
win.loadURL(`file://${__dirname}/index.html?${script_path}`)
win.webContents.openDevTools({mode: 'detached'})
}
win.on('closed', onClosed)
//win.webContents.openDevTools()
win.webContents.on('devtools-opened', () => {
setImmediate(() => {
win.webContents.reload()
})
})
win.maximize()
return win
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (!mainWindow) {
mainWindow = createMainWindow()
}
})
app.on('ready', () => {
mainWindow = createMainWindow()
})