-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
executable file
·79 lines (63 loc) · 1.78 KB
/
app.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
#!/usr/bin/env electron
var path = require('path')
var mkdirp = require('mkdirp')
var electron = require('electron')
var app = electron.app // Module to control application life.
var BrowserWindow = electron.BrowserWindow // Module to create native browser window.
var APP_NAME = 'Hyperpad'
var win = null
// Set up app storage dir
var userDataPath = require('./get-doc-dir')()
mkdirp.sync(userDataPath)
console.log(userDataPath)
// Set up global node exception handler
handleUncaughtExceptions()
// Create app window
createMainWindow()
//---------------------------------------------------------------------------
function createMainWindow () {
var win
app.once('ready', ready)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
app.quit()
})
function ready () {
var INDEX = 'file://' + path.resolve(__dirname, './index.html')
if (!win) {
win = new BrowserWindow({title: APP_NAME, show: false})
win.once('ready-to-show', function () {
win.show()
win.maximize()
})
}
// if (argv.debug) win.webContents.openDevTools()
win.loadURL(INDEX)
win.on('closed', function () {
win = null
app.quit()
})
var ipc = electron.ipcMain
ipc.on('get-user-data-path', function (ev) {
ev.returnValue = userDataPath
})
}
return win
}
function handleUncaughtExceptions () {
process.on('uncaughtException', function (error) {
console.log('uncaughtException in Node:', error)
// Show a vaguely informative dialog.
if (app && win) {
var opts = {
type: 'error',
buttons: [ 'OK' ],
title: 'Error Fatal',
message: error.message
}
electron.dialog.showMessageBox(win, opts, function () {
process.exit(1)
})
}
})
}