-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
64 lines (59 loc) · 2.07 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
const { app, BrowserWindow, ipcMain, dialog } = require("electron");
const path = require("path");
const remoteMain = require("@electron/remote/main");
let win, sec;
remoteMain.initialize();
function createWindows() {
/* main window */
win = new BrowserWindow({
maxHeight: 600,
width: 450,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
autoHideMenuBar: true,
});
win.loadFile("./src/views/index.html");
win.setTitle("SC Media Player");
// win.setPosition(50, 50);
remoteMain.enable(win.webContents);
// win.webContents.openDevTools();
/* second window */
sec = new BrowserWindow({
height: 180,
minHeight: 180,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
parent: win,
frame: false,
autoHideMenuBar: true,
});
sec.loadFile("./src/views/sec.html");
sec.setTitle("SC-Media-Player-Second");
// sec.setPosition(500, 50);
sec.setAspectRatio(16 / 9);
// sec.webContents.openDevTools();
}
app.whenReady()
.then(() => app.on("activate", () => BrowserWindow.getAllWindows().length === 0) ? createWindows() : "");
app.on("window-all-closed", () => process.platform !== "darwin" ? app.quit() : "");
/* code */
ipcMain.on('setMidia', (e, a) => sec.webContents.send('setMidia', a));
ipcMain.on('video/control', (e, a) => sec.webContents.send('video/control', a));
ipcMain.on('video/setProgress', (e, a) => sec.webContents.send('video/setProgress', a));
ipcMain.on('timeupdate', (e, a) => win.webContents.send('timeupdate', a));
ipcMain.on("addMidiaInDb", (e, a) => {
dialog
.showOpenDialog({ properties: ["openFile"] })
.then((result) => {
if (!result.canceled) {
const filePath = result.filePaths[0];
const fileName = path.parse(filePath).name;
win.webContents.send("addMidiaInDb", { name: fileName, src: filePath });
}
})
.catch((err) => console.log(err));
});