-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
80 lines (71 loc) · 1.92 KB
/
main.js
File metadata and controls
80 lines (71 loc) · 1.92 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
const { app, BrowserWindow, ipcMain, dialog } = require("electron");
const dataStore = require('./renderer/dataStore')
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
const myStorage = new dataStore({
'name': 'Music Data'
});
//查看本机缓存位置
const STORE_PATH = app.getPath('userData')
console.log(STORE_PATH)
class AppWindow extends BrowserWindow {
constructor(config, fileLocation) {
const basicConfig = {
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
};
const finalConfig = Object.assign(basicConfig, config);
super(finalConfig);
this.loadFile(fileLocation);
this.once("ready-to-show", () => {
this.show();
});
}
}
app.on("ready", () => {
const mainWindow = new AppWindow({}, "./renderer/index.html");
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.send('getTracks', myStorage.getTracks())
})
ipcMain.on("add-music-window", () => {
const addWindow = new AppWindow(
{
width: 500,
height: 500,
parent: mainWindow,
},
"./renderer/add.html"
);
});
ipcMain.on('add-tracks', (event,tracks) => {
const updatedTracks = myStorage.addTracks(tracks).getTracks()
mainWindow.send('getTracks', updatedTracks)
})
ipcMain.on('delete-track', (event,id) => {
const updatedTracks = myStorage.deleteTrack(id).getTracks()
mainWindow.send('getTracks', updatedTracks)
})
ipcMain.on("open-music-files", (event) => {
dialog
.showOpenDialog({
properties: ["openFile", "multiSelections"],
filters: [
{
name: "music",
extensions: ["mp3"],
},
],
})
.then((files) => {
if (files) {
event.sender.send("selected-files", files.filePaths);
}
})
.catch((err) => {
console.log(err);
});
});
});