-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.js
executable file
·109 lines (92 loc) · 2.53 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
108
109
var app = require('app');
var ipc = require('ipc');
var dialog = require('dialog');
var BrowserWindow = require('browser-window');
var globalShortcut = require('global-shortcut');
var fileSizeTree = require('file-size-tree-js');
var mainWindow = null;
app.on('ready', function() {
createAppWindow();
addAppEventListeners();
registerKeyboardShortcuts();
});
function createAppWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
// Include the application icon when packaging for Linux.
// (The application icon when packaging for OS X and Windows
// is included by the corresponding packaging scripts in
// package.json.)
icon: 'app/icons/Icon.png'
});
mainWindow.loadUrl('file://' + __dirname + '/app/index.html');
}
function addAppEventListeners() {
app.on('window-all-closed', function() {
quit();
});
ipc.on('select-directory', function(event, path) {
if (path) {
mapDirectory(path);
} else {
selectDirectory();
}
});
ipc.on('toggle-sidebar', function() {
toggleSidebar();
});
ipc.on('toggle-tooltip', function(event, tooltipToggledWithCheckbox) {
toggleTooltip(tooltipToggledWithCheckbox);
});
ipc.on('quit', function() {
quit();
});
}
function registerKeyboardShortcuts() {
globalShortcut.register('CmdOrCtrl+O', function() {
selectDirectory();
});
globalShortcut.register('CmdOrCtrl+D', function() {
toggleSidebar();
});
globalShortcut.register('CmdOrCtrl+T', function () {
toggleTooltip();
});
globalShortcut.register('CmdOrCtrl+Q', function() {
quit();
});
globalShortcut.register('Alt+CmdOrCtrl+I', function() {
mainWindow.toggleDevTools();
});
}
function selectDirectory() {
var dialogOptions = {
properties: ['openDirectory']
};
dialog.showOpenDialog(mainWindow, dialogOptions, function(filenames) {
if (filenames === undefined) return;
var path = filenames[0];
mapDirectory(path);
});
}
function mapDirectory(path) {
console.log('mapDirectory():' + path);
var options = {
fileName: 'name',
files: 'children',
directoryName: 'name'
};
var tree = fileSizeTree(path, options);
mainWindow.webContents.send('update-directory', path, tree);
}
function toggleSidebar() {
mainWindow.webContents.send('toggle-sidebar');
}
function toggleTooltip(tooltipToggledWithCheckbox) {
tooltipToggledWithCheckbox = tooltipToggledWithCheckbox || false;
mainWindow.webContents.send('toggle-tooltip', tooltipToggledWithCheckbox);
}
function quit() {
app.quit();
}