forked from jlord/git-it-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
76 lines (62 loc) · 2.13 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
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
var app = require('app')
var BrowserWindow = require('browser-window')
var crashReporter = require('crash-reporter')
var Menu = require('menu')
var ipc = require('ipc')
var dialog = require('dialog')
var fs = require('fs')
var path = require('path')
var darwinTemplate = require('./menus/darwin-menu.js')
var otherTemplate = require('./menus/other-menu.js')
var emptyData = require('./empty-data.json')
var mainWindow = null
var menu = null
var iconPath = path.join(__dirname, '/assets/git-it.png')
crashReporter.start()
app.on('window-all-closed', function appQuit () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('ready', function appReady () {
mainWindow = new BrowserWindow({"min-width": 800, "min-width": 600, width: 900, height: 600, title: 'Git-it', icon: iconPath })
mainWindow.loadUrl('file://' + __dirname + '/index.html')
var userDataPath = path.join(app.getPath('userData'), 'user-data.json')
fs.exists(userDataPath, function (exists) {
if (!exists) {
fs.writeFile(userDataPath, JSON.stringify(emptyData, null, ' '), function (err) {
if (err) return console.log(err)
})
}
})
ipc.on('getUserDataPath', function (event) {
event.returnValue = userDataPath
})
ipc.on('open-file-dialog', function (event) {
var files = dialog.showOpenDialog(mainWindow, { properties: [ 'openFile', 'openDirectory' ]})
if (files) {
event.sender.send('selected-directory', files)
}
})
ipc.on('confirm-clear', function (event) {
var options = {
type: 'info',
buttons: ['Yes', 'No'],
title: 'Confirm Clearing Statuses',
message: 'Are you sure you want to clear the status for every challenge?'
}
dialog.showMessageBox(options, function cb (response) {
event.sender.send('confirm-clear-response', response)
})
})
if (process.platform === 'darwin') {
menu = Menu.buildFromTemplate(darwinTemplate(app, mainWindow))
Menu.setApplicationMenu(menu)
} else {
menu = Menu.buildFromTemplate(otherTemplate(mainWindow))
mainWindow.setMenu(menu)
}
mainWindow.on('closed', function winClosed () {
mainWindow = null
})
})