Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
180 lines (152 loc) · 5.73 KB
/
Copy pathindex.js
File metadata and controls
180 lines (152 loc) · 5.73 KB
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
const path = require("path")
const { ipcMain, BrowserWindow } = require("electron")
module.exports = class LyricsWindowPlugin {
win;
constructor(env) {
// Define plugin enviornment within the class
this.env = env
}
// Called when the backend is ready
onReady(win) {
// console.log("=== Backend Plugin Loaded ===")
// // Setting up an ipcMain channel for front end to communicate with
// ipcMain.handle("plugin.frontendComm", (event, message) => {
// // Print out what the front end says
// console.debug(`Frontend says: ${message}`)
// // Get the main window and send a messsage to it
// this.env.utils.getWindow().webContents.send("plugin.backendComm", "Hello from the backend!")
// })
}
// Called when the renderer is ready (app.init())
onRendererReady(win) {
console.debug("Renderer Ready Called")
// Load the frontend plugin
this.env.utils.loadJSFrontend(path.join(this.env.dir, "index.frontend.js"))
// Add listener to initialize lyrics window
ipcMain.on("LyricsWindowOpen", (event, args) => {
// Create a new lyrics window
console.log('Lyrics Window Opening')
if (this.win == null) {
this.win = new BrowserWindow({
width: 400, height: 300, show: false,
frame: false,
minWidth: 350,
minHeight: 230,
x: 0,
y: 0,
alwaysOnTop : true, // change it to false to make it normal
webPreferences: {
nodeIntegration: true, contextIsolation: false
}
});
this.win.loadFile(path.join(this.env.dir, "index.html"));
this.win.show();
this.win.on('closed', () => {
this.win = null
});
this.win.webContents.on('did-finish-load', () => {
if (this.win) {
this.win.webContents.send('truelyrics', data);
}
})
}
})
ipcMain.on('wsapi-updatePlaybackState', (_event, arg) => {
if (this.win) {
this.win.webContents.send('playbackInfoLW', arg);
}
})
ipcMain.on('LWAirPlayStatus', (_event, arg) => {
if (this.win) {
this.win.webContents.send('AirPlayStatus', arg);
}
})
ipcMain.on('LWLyricsUpdate', (_event, arg) => {
if (this.win) {
this.win.webContents.send('LyricsUpdate', arg);
}
})
ipcMain.on('LWRichLyricsUpdate', (_event, arg) => {
if (this.win) {
this.win.webContents.send('RichLyricsUpdate', arg);
}
})
ipcMain.on('LWBGUpdate', (_event, arg) => {
if (this.win) {
this.win.webContents.send('LWBGUpdate', arg);
}
})
ipcMain.handle('LW_GetLyrics', async (_event, arg) => {
if (this.win) {
return await this.env.utils.getWindow().webContents.executeJavaScript(`app?.lyrics ?? []`)
}
})
ipcMain.handle('LW_GetBG', async (_event, arg) => {
if (this.win) {
return await this.env.utils.getWindow().webContents.executeJavaScript(`app?.currentArtUrl ?? ""`)
}
})
ipcMain.handle('LW_SeekTo', async (_event, arg) => {
if (this.win) {
return await this.env.utils.getWindow().webContents.executeJavaScript(`app.seekTo(${arg})`)
}
})
ipcMain.handle('LW_Maximize', async (_event, arg) => {
if (this.win) {
if (this.win.isMaximized()) {
this.win.unmaximize();
} else {
this.win.maximize();
}
}
})
ipcMain.handle('LW_Minimize', async (_event, arg) => {
if (this.win) {
this.win.minimize();
}
})
ipcMain.handle('LW_SetTop', (_event, arg) => {
if (this.win) {
if (arg === ""){
if(this.win.isAlwaysOnTop()){
this.win.setAlwaysOnTop(false);
return false;
} else {
this.win.setAlwaysOnTop(true);
return true;
}
} else {
console.log('onTop',arg)
this.win.setAlwaysOnTop(arg === 'true');
return (arg === 'true');
}
} else {return false}
})
ipcMain.handle('LW_OnTop', async (_event, arg) => {
if (this.win) {
return this.win.isAlwaysOnTop();
} else {return false}
})
ipcMain.handle('LW_SongControl', async (_event, arg) => {
if (this.win) {
switch (arg){
case 'prev':
this.env.utils.playback.previous();
break;
case 'next':
this.env.utils.playback.next();
break;
case 'pause':
case 'play':
this.env.utils.playback.playPause();
break;
}
}
})
}
// onNowPlayingItemDidChange(attributes){
// if (this.win) {
// this.win.webContents.send('LyricsUpdate', attributes);
// }
// }
}