-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
115 lines (100 loc) · 3.88 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
110
111
112
113
114
const {app, BrowserWindow, Menu, dialog} = require("electron");
const { opendir } = require("fs");
const path = require("path");
const Shell = require("node-powershell");
//flag for production or dev environment
process.env.NODE_ENV = "development";
/*
Menu contains file operations including "Open", "Save", and "Publish".
Menu's file operations are not yet fully functional - will probably need to establish some
variables saved within the application which control the active open project directory, and
potentially more, haven't thought through it a ton, just trying to start a menu skeleton.
Menu also contains functionality to toggle a fully operational Chrome devtool menu.
*/
var mainMenuTemplate = [
{
label: 'File',
submenu: [
{
label: 'Open',
click(item, focusedWindow, event)
{
/*
This probably doesn't actually open any directories, just opens the system open dialog.
*/
dialog.showOpenDialog(opendir);
}
},
{
label: 'Save',
click(item, focusedWindow, event)
{
/*
This probably doesn't actually save anything, just opens the system save dialog.
*/
dialog.showSaveDialog();
}
},
{
label: 'Publish',
click(item, focusedWindow, event)
{
/*
Uses node to instantiate powershell in order to eventually execute shell commands.
*/
var powershell = new Shell();
/*
Git commands would go below as well. The app should store a string variable
controlling the directory to the local site that the user has open currently.
In place of __dirname, we would cd into the currently open path.
*/
powershell.addCommand('cd ' + __dirname);
/*
The below then obviously invokes the commands which we added to the shell script.
Not sure if we want to console.log the output/errors but the implementation in
order to do so is there.
*/
powershell.invoke()
.then(function(output)
{
console.log(output);
})
.catch(function(err)
{
console.log(err);
powershell.dispose();
})
}
}
]
},
{
label: 'Developer Tools',
click(item, focusedWindow) {
focusedWindow.toggleDevTools();
}
}
];
function createWindow() {
var mainWindow = new BrowserWindow();
//Build menu from above template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
Menu.setApplicationMenu(mainMenu);
/*
Would it make sense to have a static "welcome" page with buttons allowing the user
to open a local project, and other functionality? I think this would make sense.
It would then involve simply revamping the mainWindow.html page I think. Also, what's
the deal with the mainWindow.removeMenu() call? Was this meant to remove the devtools
toggle option?
*/
mainWindow.loadFile(path.join(__dirname, "mainWindow.html"));
if(process.env.NODE_ENV === "production")
mainWindow.removeMenu();
//Quit app when closed
mainWindow.on("closed", function() {
app.quit();
})
}
app.on("ready", function() {
createWindow();
})