-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
103 lines (92 loc) · 2.42 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
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const {Menu,globalShortcut} = require('electron');
const fs = require('fs');
app.on('ready', function() {
mainWindow = new BrowserWindow({width: 612, height: 384})
// ,frame: false})
mainWindow.loadURL(`file://${__dirname}/app/index.html`)
// mainWindow.webContents.openDevTools();
mainWindow.setResizable(false)
mainWindow.on('closed', function () {
mainWindow = null
})
var template = [
{},
{
label: 'Sound Control',
submenu: [
{
label:'Select Folder',
accelerator:'CommandOrControl+O',
click:function(){
openFolderDialog();
}
},
{
label:'Song Control',
submenu:[
{
label:'Pause',
accelerator:'CommandOrControl+E',
click:function(){
sendPauseSongMessage();
}
},
{
label:'Next',
accelerator:'CommandOrControl+N',
click:function(){
sendNextSongMessage();
}
},
{
label:'Previous',
accelerator:'CommandOrControl+P',
click:function(){
sendNextSongMessage();
}
}
]
}
]
}
];
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu);
// globalShortcut.register('CommandOrControl+P', function(){
// openFolderDialog();
// });
});
function sendPauseSongMessage(){
mainWindow.webContents.send('modal-pause-song','pause');
}
function sendNextSongMessage(){
mainWindow.webContents.send('modal-next-song','next');
}
function sendPrevSongMessage(){
mainWindow.webContents.send('modal-prev-song','prev');
}
function openFolderDialog(){
var dialog = electron.dialog;
dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
},function(filePath){
fs.readdir(filePath[0],function(err, files){
var arr = [];
for(var i=0;i<files.length;i++)
{
if(files[i].substr(-4) === ".mp3")
{
arr.push(files[i]);
}
}
console.log(arr);
var objToSend = {};
objToSend.path = filePath[0];
objToSend.files = arr;
mainWindow.webContents.send('modal-folder-content',objToSend);
})
})
}