-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
119 lines (104 loc) · 3 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
const { app, BrowserWindow, ipcMain, nativeImage, Menu } = require("electron");
const path = require("path");
app.setPath('userData', path.join(app.getPath('home'), 'AppData\\Local\\YouTubeMusicDesktopClient'));
console.log('User Data Path:', app.getPath('userData'));
let mainWindow;
let isPlaying = false;
let isLiked = true;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
nodeIntegration: true,
contextIsolation: false,
},
frame: true,
});
mainWindow.loadURL("https://music.youtube.com/");
Menu.setApplicationMenu(null);
updateThumbarButtons(false);
mainWindow.on("close", (event) => {
mainWindow.webContents.send("media-play-pause");
app.quit();
});
}
function updateThumbarButtons(isTrackSelected) {
const radioIconPath = path.join(__dirname, "icons", "radio.png");
const playPauseIconPath = path.join(
__dirname,
"icons",
isPlaying ? "pause.png" : "play.png"
);
const prevIconPath = path.join(__dirname, "icons", "prev.png");
const nextIconPath = path.join(__dirname, "icons", "next.png");
const likeIconPath = path.join(
__dirname,
"icons",
isLiked ? "like.png" : "like-fill.png"
);
const radioIcon = nativeImage.createFromPath(radioIconPath);
const playPauseIcon = nativeImage.createFromPath(playPauseIconPath);
const prevIcon = nativeImage.createFromPath(prevIconPath);
const nextIcon = nativeImage.createFromPath(nextIconPath);
const likeIcon = nativeImage.createFromPath(likeIconPath);
mainWindow.setThumbarButtons([
{
tooltip: "Start radio",
icon: radioIcon,
click() {
mainWindow.webContents.send("media-radio-track");
},
flags: isTrackSelected ? [] : ["disabled"],
},
{
tooltip: "Previous",
icon: prevIcon,
click() {
mainWindow.webContents.send("media-previous-track");
},
flags: isTrackSelected ? [] : ["disabled"],
},
{
tooltip: isPlaying ? "Pause" : "Play",
icon: playPauseIcon,
click() {
mainWindow.webContents.send("media-play-pause");
},
},
{
tooltip: "Next",
icon: nextIcon,
click() {
mainWindow.webContents.send("media-next-track");
},
flags: isTrackSelected ? [] : ["disabled"],
},
{
tooltip: isLiked ? "Like" : "Unlike",
icon: likeIcon,
click() {
mainWindow.webContents.send("like-track");
},
flags: isTrackSelected ? [] : ["disabled"],
},
]);
}
ipcMain.on("update-thumbar-buttons", (event, { isTrackSelected }) => {
updateThumbarButtons(isTrackSelected);
});
ipcMain.on("update-play-pause", (event, playing) => {
isPlaying = playing;
updateThumbarButtons(true);
});
ipcMain.on("update-like-button", (event, liked) => {
isLiked = liked;
updateThumbarButtons(true);
});
app.on("ready", createWindow);
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});