-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
224 lines (210 loc) · 4.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
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
218
219
220
221
222
const { app, Menu, BrowserWindow, nativeImage, Tray, clipboard, dialog } = require('electron');
const path = require('path');
const os = require('os')
const myUserAgent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'
let mainWindow, tray
let iconImage = nativeImage.createFromPath(
path.join(__dirname, "/build/icon.png")
);
// Create the main menu template
const mainMenuTemplate = [
{
label: 'File',
submenu: [
{
label: "Force Reload",
accelerator: "CmdOrCtrl+Shift+R",
click() {
mainWindow.webContents.reload();
},
},
{
label: "Quit",
accelerator: "CmdOrCtrl+Q",
click() {
// Quit the app
app.exit(0);
},
},
],
},
{
label: "Edit",
submenu: [
{
label: "Undo",
accelerator: "CmdOrCtrl+Z",
selector: "undo:",
},
{
label: "Redo",
accelerator: "Shift+CmdOrCtrl+Z",
selector: "redo:",
},
{
type: "separator",
},
{
label: "Cut",
accelerator: "CmdOrCtrl+X",
selector: "cut:",
},
{
label: "Copy",
accelerator: "CmdOrCtrl+C",
selector: "copy:",
},
{
label: "Paste",
accelerator: "CmdOrCtrl+V",
selector: "paste:",
},
{
label: "Select All",
accelerator: "CmdOrCtrl+A",
selector: "selectAll:",
}
],
},
{
label: "View",
submenu: [
{
label: "Toggle Fullscreen",
accelerator: "F11",
click() {
mainWindow.setFullScreen(!mainWindow.fullScreen);
},
},
],
},
{
label: "About",
submenu: [
{
label: "About",
click() {
let versionInfo = `Wynk music: ${app.getVersion()}
Electron: ${process.versions.electron}
Chrome: ${process.versions.chrome}
V8: ${process.versions.v8}
OS: ${os.type()} ${os.arch()} ${os.release()}`;
dialog.showMessageBox({
type: "info",
title: `Wynk music v${app.getVersion()}`,
message: `Made by Jothi Prasath.`,
detail: `${versionInfo}`,
icon: iconImage,
buttons: ["Copy Version Info", "OK"],
})
.then((res) => {
let buttonClicked = res.response;
switch (buttonClicked) {
case 0:
clipboard.write({
text: versionInfo,
});
break;
}
})
.catch((err) => {
console.error(err);
});
},
},
{
label: "Links",
submenu: [
{
label: "Report Bugs/Issues",
click: () => {
shell.openExternal(
"https://github.com/jothi-prasath/wynk-music/issues"
);
},
},
{
label: "Repository",
click: () => {
shell.openExternal("https://github.com/jothi-prasath/wynk-music");
},
},
],
},
],
}
]
// Create context menu for tray icon
let trayContextMenu = Menu.buildFromTemplate([
{
label: "Maximize",
click() {
if (mainWindow) {
// Show the main window
mainWindow.show();
// Focus the main window
mainWindow.focus();
}
}
},
{
label: "Minimize to Tray",
click() {
// Hide the main window i.e. minimize to tray
mainWindow.hide();
}
},
{
label: "Exit",
click() {
// Quit the app
app.exit(0);
}
}
])
function createWindow() {
// Create the browser window
mainWindow = new BrowserWindow({
width: 1202,
height: 600,
minWidth: 1202,
minHeight: 600,
center: true,
// Set main window background color to hide loading
backgroundColor: "#282C34",
icon: iconImage,
show: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
preload: path.join(__dirname, '/js/preload.js'),
}
})
mainWindow.webContents.userAgent = myUserAgent
mainWindow.setSize(1260, 600, false)
mainWindow.loadURL('http://wynk.in')
// Building main menu from template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
// Setting the main menu
Menu.setApplicationMenu(mainMenu)
}
app.whenReady().then(() => {
// Show the main window after app ready
mainWindow.show()
tray = new Tray(iconImage)
tray.setToolTip('Wynk music')
tray.on('click', () => mainWindow.show())
// Setting the tray menu
tray.setContextMenu(trayContextMenu)
})
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})