-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
107 lines (87 loc) · 2.15 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
104
105
106
107
//== DEPENDENCIES ==//
const {app, BrowserWindow, ipcMain, dialog} = require('electron');
const path = require('path');
const {DataManager} = require('./src/data_manager');
//== GLOBAL VARIABLES ==//
var dm = new DataManager(app.getPath('userData'));
//== FUNCTIONS ==//
// Create the main app window
function CreateWindow()
{
// Create the window object
const win = new BrowserWindow(
{
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'src/index.js')
}
}
);
// Load the main HTML file to the window object
win.loadFile('index.html');
}
// Show dialog to choose a folder
function GetFoldersFromDialog()
{
// Open dialog box
let folderPaths = dialog.showOpenDialogSync({
properties: ['openDirectory', 'multiSelections']
}
);
// undefined means the operation was canceled
if (folderPaths === undefined) folderPaths = [];
// Return selectedfolders (or empty array if none selected)
return folderPaths;
}
//== FUNCTIONS AVAILABLE IN RENDERER ==//
ipcMain.handle('getFolders', () =>
{
return dm.trackedFolderData;
}
);
ipcMain.handle('getAudioFiles', () =>
{
return dm.trackedFileData;
}
);
ipcMain.handle('getAudioFilesInFolder', (event, args) =>
{
return dm.getFilesByFolderID(args);
}
);
ipcMain.handle('folderDialogBox', () =>
{
return GetFoldersFromDialog();
}
);
//== MAIN APP ==//
// Do when app is launched and ready
app.whenReady().then(() =>
{
// Update local variables according to saved data
dm.loadData();
// Create the main app window
CreateWindow();
//dm.traverseAndParseFolder('G:\\My Drive\\Music Production\\Samples\\Custom', true); //////////////////////////////
// If app is activated and there are no windows open, open one
app.on('activate', () =>
{
if (BrowserWindow.getAllWindows().length === 0)
{
CreateWindow();
}
}
);
}
);
// Do when all app windows are closed
app.on('window-all-closed', () =>
{
// Quit app if all windows are closed, except on Mac
if (process.platform !== 'darwin')
{
app.quit();
}
}
);