-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
main.js
217 lines (204 loc) · 5.49 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"use strict";
let eventEmitter = require("events");
eventEmitter = new eventEmitter();
const { app, Tray, Menu, shell } = require("electron");
const storage = require("./storage");
const touchbar = require("./touchbar")(__dirname, eventEmitter);
const { searchNewUpdate } = require("./checkUpdate");
const browsers = require("./browsers")(__dirname, storage, {
touchbar,
eventEmitter,
});
const { colorpicker, colorsbook, picker, settings } = browsers;
// @TODO remove when [email protected]
app.allowRendererProcessReuse = true;
require("./events")(storage, browsers, eventEmitter);
if (process.platform === "linux") {
app.disableHardwareAcceleration();
}
let tray;
let createTray = () => {
if (tray) { return; }
if (process.platform === "darwin") {
tray = new Tray(`${__dirname}/ressources/[email protected]`);
}
if (process.platform === "win32") {
tray = new Tray(`${__dirname}/ressources/[email protected]`); // color here
}
if (process.platform === "linux") {
tray = new Tray(`${__dirname}/ressources/[email protected]`);
}
if (process.platform === "darwin") {
tray.setPressedImage(`${__dirname}/ressources/[email protected]`);
}
tray.on("click", (event) => colorpicker.init());
};
/**
* [setMenu - set new app menu]
* @return {void}
*/
let setMenu = () => {
let template = [
{
label: "Colorpicker",
submenu: [
{
label: "About Colorpicker",
accelerator: "Shift+CmdOrCtrl+A",
click: () => settings.init(),
},
{ label: `Version ${app.getVersion()}`, enabled: false },
{ type: "separator" },
{
label: "Preferences",
accelerator: "CmdOrCtrl+,",
click: () => settings.init(),
},
{ type: "separator" },
{
label: "Hide Colorpicker",
accelerator: "CmdOrCtrl+H",
role: "minimize",
},
{
label: "Developer",
submenu: [
{
label: "Toggle Devtools",
accelerator: "CmdOrCtrl+Alt+I",
role: "toggledevtools",
},
{
label: "Reload Window",
accelerator: "CmdOrCtrl+R",
role: "reload",
},
],
},
{ type: "separator" },
{
label: "Quit",
accelerator: "CmdOrCtrl+Q",
click: () => app.quit(),
},
],
},
{
label: "Edit",
role: "editMenu",
},
{
label: "View",
submenu: [
{
label: "Show Colorpicker",
accelerator: "Shift+CmdOrCtrl+C",
click: () => colorpicker.init(),
},
{
label: "Show ColorsBook",
accelerator: "Shift+CmdOrCtrl+B",
click: () => colorsbook.init(),
},
{ type: "separator" },
{
label: "Save Color",
accelerator: "CmdOrCtrl+S",
click: () => colorpicker.getWindow().webContents.send("shortSave"),
},
{ type: "separator" },
{
label: "Copy Hex Color",
accelerator: "CmdOrCtrl+W",
click: () => colorpicker.getWindow().webContents.send("shortCopyHex"),
},
{
label: "Copy RGB(a) Color",
accelerator: "Shift+CmdOrCtrl+W",
click: () => colorpicker.getWindow().webContents.send("shortCopyRGB"),
},
{ type: "separator" },
{
label: "set Negative Color",
accelerator: "CmdOrCtrl+N",
click: () =>
colorpicker.getWindow().webContents.send("shortNegative"),
},
],
},
{
label: "Tools",
submenu: [
{
label: "Pin to Foreground",
accelerator: "CmdOrCtrl+F",
click: () => colorpicker.getWindow().webContents.send("shortPin"),
},
{ type: "separator" },
{
label: "Pick Color",
accelerator: "CmdOrCtrl+P",
click: () => picker.init(),
},
{
label: "Get Clipboard's Colors",
accelerator: "Shift+CmdOrCtrl+V",
click: () => colorpicker.getWindow().webContents.send("shortApply"),
},
{
label: "Toggle Shading",
accelerator: "CmdOrCtrl+T",
click: () => colorpicker.getWindow().webContents.send("shortShading"),
},
{
label: "Set Random Color",
accelerator: "CmdOrCtrl+M",
click: () => colorpicker.getWindow().webContents.send("shortRandom"),
},
],
},
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
};
/**
* [App ready - On app ready]
*/
app.on("ready", () => {
storage.init().then(() => {
// createTray();
setMenu();
colorpicker.init();
searchNewUpdate();
});
});
/**
* [App activate - On app icon clicked]
*/
app.on("activate", () => {
colorpicker.init();
});
/**
* [App window-all-closed - quit app on all window closed ]
*/
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("web-contents-created", (event, contents) => {
/**
* If your app need to navigate, uncomment the condition and update it.
*/
contents.on("will-navigate", (event, navigationUrl) => {
shell.openExternal(navigationUrl);
event.preventDefault();
//}
});
/**
* We block the creation of new window and open the link in a good navigator.
*/
contents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: "deny" };
});
});