|
1 | | -const { |
2 | | - app, |
3 | | - BrowserWindow, |
4 | | - globalShortcut, |
5 | | - systemPreferences, |
6 | | - Notification |
7 | | -} = require('electron'); |
| 1 | +(function() { |
| 2 | + const { app, BrowserWindow, globalShortcut } = require('electron'); |
8 | 3 |
|
9 | | -const { dialog, ipcMain } = require('electron'); |
10 | | -const openDirectory = require('./modules/open-directory'); |
11 | | -let window = null; |
| 4 | + const { dialog, ipcMain } = require('electron'); |
| 5 | + const openDirectory = require('./modules/open-directory'); |
| 6 | + let window = null; |
12 | 7 |
|
13 | | -function createWindow() { |
14 | | - window = new BrowserWindow({ |
15 | | - width: 800, |
16 | | - minWidth: 800, |
17 | | - height: 600, |
18 | | - minHeight: 600, |
19 | | - titleBarStyle: 'hiddenInset', |
20 | | - useContentSize: false, |
21 | | - webPreferences: { |
22 | | - nodeIntegration: true |
23 | | - } |
24 | | - }); |
| 8 | + function createWindow() { |
| 9 | + window = new BrowserWindow({ |
| 10 | + width: 800, |
| 11 | + minWidth: 800, |
| 12 | + height: 600, |
| 13 | + minHeight: 600, |
| 14 | + titleBarStyle: 'hidden', |
| 15 | + frame: false, |
| 16 | + useContentSize: false, |
| 17 | + webPreferences: { |
| 18 | + nodeIntegration: true |
| 19 | + } |
| 20 | + }); |
25 | 21 |
|
26 | | - window.setResizable(true); |
27 | | - window.loadFile('src/index.html'); |
28 | | -} |
| 22 | + window.setResizable(true); |
| 23 | + window.loadFile('src/index.html'); |
| 24 | + } |
29 | 25 |
|
30 | | -ipcMain.on('open-file-dialog', (event, path) => { |
31 | | - dialog.showOpenDialog( |
32 | | - window, |
33 | | - { |
34 | | - properties: ['openDirectory'] |
35 | | - }, |
36 | | - filePaths => { |
37 | | - if (filePaths) { |
38 | | - openDirectory(filePaths, event); |
39 | | - } |
40 | | - } |
41 | | - ); |
42 | | -}); |
| 26 | + ipcMain.on('open-file-dialog', event => { |
| 27 | + dialog |
| 28 | + .showOpenDialog(window, { |
| 29 | + properties: ['openDirectory'] |
| 30 | + }) |
| 31 | + .then(contents => { |
| 32 | + const files = contents.filePaths; |
| 33 | + if (files.length > 0) { |
| 34 | + openDirectory(files, event); |
| 35 | + } |
| 36 | + }) |
| 37 | + .catch(err => { |
| 38 | + console.error(err); |
| 39 | + }); |
| 40 | + }); |
43 | 41 |
|
44 | | -app.on('ready', () => { |
45 | | - function registerShortcuts() { |
46 | | - if (process.platform === 'darwin') { |
47 | | - if (!systemPreferences.isTrustedAccessibilityClient(true)) { |
48 | | - const not = new Notification({ |
49 | | - title: 'Violin', |
50 | | - body: |
51 | | - 'Please add Violin as a trusted client, then click on this message or restart Violin.' |
52 | | - }); |
53 | | - not.on('click', () => { |
54 | | - app.relaunch(); |
55 | | - app.quit(); |
56 | | - }); |
57 | | - not.show(); |
58 | | - } |
59 | | - } |
60 | | - // TODO find a smoother way to register shortcuts |
61 | | - globalShortcut.register('MediaPlayPause', () => { |
62 | | - window.webContents.send('shortcut', 'MediaPlayPause'); |
63 | | - }); |
| 42 | + app.on('ready', () => { |
| 43 | + function registerShortcuts() { |
| 44 | + // TODO find a smoother way to register shortcuts |
| 45 | + globalShortcut.register('MediaPlayPause', () => { |
| 46 | + window.webContents.send('shortcut', 'MediaPlayPause'); |
| 47 | + }); |
64 | 48 |
|
65 | | - globalShortcut.register('MediaNextTrack', () => { |
66 | | - window.webContents.send('shortcut', 'MediaNextTrack'); |
67 | | - }); |
| 49 | + globalShortcut.register('MediaNextTrack', () => { |
| 50 | + window.webContents.send('shortcut', 'MediaNextTrack'); |
| 51 | + }); |
68 | 52 |
|
69 | | - globalShortcut.register('MediaPreviousTrack', () => { |
70 | | - window.webContents.send('shortcut', 'MediaPreviousTrack'); |
71 | | - }); |
72 | | - } |
73 | | - createWindow(); |
74 | | - registerShortcuts(); |
75 | | -}); |
| 53 | + globalShortcut.register('MediaPreviousTrack', () => { |
| 54 | + window.webContents.send('shortcut', 'MediaPreviousTrack'); |
| 55 | + }); |
| 56 | + } |
| 57 | + createWindow(); |
| 58 | + registerShortcuts(); |
| 59 | + }); |
76 | 60 |
|
77 | | -app.on('window-all-closed', () => { |
78 | | - globalShortcut.unregisterAll(); |
79 | | - app.quit(); |
80 | | -}); |
| 61 | + app.on('window-all-closed', () => { |
| 62 | + globalShortcut.unregisterAll(); |
| 63 | + app.quit(); |
| 64 | + }); |
| 65 | +})(); |
0 commit comments