Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
153 lines (134 loc) · 3.79 KB
/
Copy pathmain.js
File metadata and controls
153 lines (134 loc) · 3.79 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"use strict"
const electron = require('electron');
const {app, BrowserWindow, Menu, ipcMain} = electron;
// SET ENV
//process.env.NODE_ENV = 'production'; // to remove 'DevTools' options
process.env.NODE_ENV = 'development'; // to add 'DevTools' options
console.log("process env = " + process.env.NODE_ENV)
let mainWindow; // main window
let addWindow; // new window variable
/* Use npm.cmd on windows executables
if (process.platform=="win32") {
var cmd = 'npm.cmd'
} else {
var cmd = 'npm'
}*/
// Listen for the app to ready
app.on('ready', function(){
// Create new window
mainWindow = new BrowserWindow({
// solves: Uncaught ReferenceError: require is not defined when loading page with devTools
webPreferences: {
nodeIntegration: true
}
});
// Load html into window
mainWindow.loadFile('mainWindow.html')
// QUIT: quit app fully when closed
mainWindow.on('closed', function(){
app.quit();
});
// Build the menu from the template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
// Insert menu
Menu.setApplicationMenu(mainMenu);
});
// Functions for menu functions
function createAddWindow(){
// Create new window
addWindow = new BrowserWindow({
width: 600,
height: 600,
// solves: Uncaught ReferenceError: require is not defined when loading page with devTools
webPreferences: {
nodeIntegration: true
}
});
// Load html for addwindow option
addWindow.loadFile('addWindow.html')
// Build the menu from the template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
// Insert menu option
Menu.setApplicationMenu(mainMenu);
// Garbage collection handle (optmization)benclear
addWindow.on('close', function(){
addWindow = null;
});
}
// Catch custom_folder_name:add from Add Window
ipcMain.on('custom_folder_name:add', function(e, custom_folder_name){
if (process.env.NODE_ENV != 'production') {
console.log(`New Folder: '${custom_folder_name}'`);
// if not in production, print console commands
}
mainWindow.webContents.send('custom_folder_name:add', custom_folder_name); // send items to main window
//addWindow.close(); // close add window after each entry
});
// Create menu template to replace default
const mainMenuTemplate = [
{
label:'FileX',
submenu:[
{
label: 'Add Account',
// add hot key
accelerator: process.platform=='darwin' ? 'Command+N' : 'Ctrl+N', // close window with either command+n for mac or ctrl+n for other OS'
click(){
createAddWindow();
}
},
{
label: 'Clear Custom Folder List',
click(){
mainWindow.webContents.send('custom_folder_name:clear');
}
},
{type: 'separator'}, // add line between menu items and 'quit' option
{
label: 'Quit',
// add hot key
accelerator: process.platform=='darwin' ? 'Command+Q' : 'Ctrl+Q', // close window with either command+q for mac or ctrl+q for other OS'
// mac (darwin), windows (win32), linux (linux)
// exit via the 'Quit' option
click() {
app.quit();
}
}
]
},
{
label: 'Help',
submenu:[
{
label: 'Report a Bug',
},
{
label: 'About Anansi',
},
]
}
];
// Check if on a mac (add empty object to run file menu)
if (process.platform == 'darwin'){
mainMenuTemplate.unshift({}); // adds to the beginning of the array for menu
}
// Add developer tools if not in 'Production'
if (process.env.NODE_ENV != 'production'){
mainMenuTemplate.push({
label: 'Developer Tools',
submenu: [
{
label: 'Toggle DevTools',
// add hot key
accelerator: process.platform=='darwin' ? 'Command+I' : 'Ctrl+I', // close window with either command+i for mac or ctrl+i for other OS'
click(custom_folder_name, focusedWindow){
// Will make devTools to show up on whatever window is running
focusedWindow.toggleDevTools();
}
},
{
role: 'reload' // reloads/refreshes the page
}
]
});
}