This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (63 loc) · 1.56 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
const fs = require('fs');
const util = require('util');
const path = require('path');
const { app, BrowserWindow } = require("electron");
const debug = /--debug/.test(process.argv[2]);
const readFileP = util.promisify(fs.readFile);
const rootPath = app.getAppPath();
const musicPath = path.join(rootPath, 'src', 'music.js');
const MUSIC_URL = "https://music.youtube.com";
let window = null;
let musics = [];
const createWindow = async () => {
try {
musics = await Promise.all([
// other ...
readFileP(musicPath, 'utf8'),
]);
} catch (error) {
alert('Please restart youtube music app')
console.error(error);
return;
}
const add = (a, b) => a + b;
const fileList = musics.reduce(add, '');
window = new BrowserWindow({
show: false,
width: 1200,
height: 800,
webPreferences: { preload: path.join(rootPath, 'src', 'preload.js') }
});
window.loadURL(MUSIC_URL);
window.webContents.on('dom-ready', () => {
window.webContents.executeJavaScript(fileList);
});
window.once("ready-to-show", () => {
window.show();
// -- debug mode
if (debug) {
window.webContents.openDevTools();
window.maximize();
require('devtron').install()
}
});
window.on("closed", () => {
window = null;
});
};
function initialize() {
app.on("ready", function () {
createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
});
app.on('activate', () => {
if (window === null) {
createWindow()
}
});
}
initialize();