-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
65 lines (57 loc) · 1.58 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
(function() {
const { app, BrowserWindow, globalShortcut } = require('electron');
const { dialog, ipcMain } = require('electron');
const openDirectory = require('./modules/open-directory');
let window = null;
function createWindow() {
window = new BrowserWindow({
width: 800,
minWidth: 800,
height: 600,
minHeight: 600,
titleBarStyle: 'hidden',
frame: false,
useContentSize: false,
webPreferences: {
nodeIntegration: true
}
});
window.setResizable(true);
window.loadFile('src/index.html');
}
ipcMain.on('open-file-dialog', event => {
dialog
.showOpenDialog(window, {
properties: ['openDirectory']
})
.then(contents => {
const files = contents.filePaths;
if (files.length > 0) {
openDirectory(files, event);
}
})
.catch(err => {
console.error(err);
});
});
app.on('ready', () => {
function registerShortcuts() {
// TODO find a smoother way to register shortcuts
globalShortcut.register('MediaPlayPause', () => {
window.webContents.send('shortcut', 'MediaPlayPause');
});
globalShortcut.register('MediaNextTrack', () => {
window.webContents.send('shortcut', 'MediaNextTrack');
});
globalShortcut.register('MediaPreviousTrack', () => {
window.webContents.send('shortcut', 'MediaPreviousTrack');
});
}
createWindow();
registerShortcuts();
});
app.on('window-all-closed', () => {
globalShortcut.unregisterAll();
app.quit();
});
})();