This repository was archived by the owner on Sep 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
83 lines (60 loc) · 1.96 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
82
83
"use strict"
const electron = require('electron')
const {app, BrowserWindow, ipcMain: ipc, globalShortcut, Tray} = electron
const fs = require('fs')
const Settings = require('./js-server/settings')
function main() {
let mainWindow, tray
function createWindow() {
mainWindow = new BrowserWindow({
width: Settings.settings.windowWidth,
height: Settings.settings.windowHeight,
x: Settings.settings.windowX,
y: Settings.settings.windowY,
show: false,
frame: false,
icon: `${__dirname}/imgs/gitmoji.ico`,
alwaysOnTop: Settings.settings.alwaysOnTop,
center: Settings.settings.windowPosCenter,
title: 'Gitmoji'
})
mainWindow.loadURL(`file://${__dirname}/index.html`)
mainWindow.on('ready-to-show', function () {
this.show()
})
}
function registerGlobalShortcut(shortcut) {
globalShortcut.register(shortcut, () => {mainWindow.show()})
}
function init() {
Settings.init()
createWindow()
registerGlobalShortcut(Settings.settings.showWindowShortcut)
tray = new Tray(`${__dirname}/imgs/gitmoji.ico`)
tray.setToolTip("Gitmoji cheat sheet")
tray.on('click', () => {
mainWindow.show()
})
}
app.on('ready', init)
app.on('window-all-closed', () => {
app.quit();
})
// IPC
ipc.on('hide-window', () => {
mainWindow.hide()
})
ipc.on('shut-down', () => {
app.quit()
})
ipc.on('get-settings', (e) => {
e.sender.send('send-settings', Settings.settings)
})
ipc.on('save-settings', (e, settings) => {
globalShortcut.unregister(Settings.settings.showWindowShortcut)
Settings.save(settings)
registerGlobalShortcut(Settings.settings.showWindowShortcut)
e.sender.send('settings-reloaded', Settings.settings)
})
}
main()