-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
223 lines (181 loc) · 5.15 KB
/
index.js
File metadata and controls
223 lines (181 loc) · 5.15 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
const electron = require('electron');
const firebase = require('firebase');
const Nexmo = require('nexmo');
const nodemailer = require('nodemailer');
// Nexmo key retrieving
const nexmo = new Nexmo({
apiKey: '01fd6f3b',
apiSecret: 'mtkQ7iJW2yPapMNs',
});
// Nodemailer setup
let transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
secure: 'true',
port: '465',
auth: {
user: 'vyas.khushal1999@gmail.com',
pass: 'abcd'
}
});
// Setting up firebase credentials
firebase.initializeApp({
apiKey: "AIzaSyDG_-iXxQpVwYlaXDGhDxKxUAG4RyDOjPg",
authDomain: "greetify-52576.firebaseapp.com",
databaseURL: "https://greetify-52576.firebaseio.com",
projectId: "greetify-52576",
storageBucket: "greetify-52576.appspot.com",
messagingSenderId: "340375775378"
});
// ref() has all the database info objects we want
var ref = firebase.database().ref('guest');
global.ref = ref;
// Declaring some global variables to use across all other windows
global.nexo = nexmo.message;
global.mail = transporter;
const {app, BrowserWindow, Menu, ipcMain} = electron;
//Menu.setApplicationMenu(false);
var mainWindow;
var host;
var addGuest;
var guestDetails;
var storeData = new Object();
// Function to create main Window of our app
function createWindow() {
mainWindow = new BrowserWindow({
// Setting up webpreferences since nodeintegration default is false with electron so we need to actiavte it
webPreferences: {
nodeIntegration: true
}});
mainWindow.loadFile('index.html');
// Building menu from templates
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
// Inserting Menu
Menu.setApplicationMenu(mainMenu);
}
// Adding Guest Window
function createAddGuest() {
addGuest = new BrowserWindow({
width: 500,
height:300,
title: 'Add New Guest',
webPreferences: {
nodeIntegration: true
}
});
addGuest.loadFile('addGuest.html');
addGuest.on('close', function() {
addGuest = null;
});
}
// Main function which has all the guest form data from the addGuest.html file via ipcRenderer
ipcMain.on('item:add', function(e, items){
if(Object.keys(items) == 'InTime' || Object.keys(items) == 'OutTime') {
Object.values(items) = Object.values(items).replace('/T/g',',');
}
storeData = items;
console.log(test(storeData));
// Sending data as an items{} object
mainWindow.webContents.send('item:add', items);
addGuest.close();
// Still have a reference to addGuest in memory. We need to reclaim memory (Grabage collection)
});
// Adding Host Login Window
function createHost() {
host = new BrowserWindow({
width: 500,
height:300,
title: 'Owner',
webPreferences: {
nodeIntegration: true
}
});
host.loadFile('loginHost.html');
host.on('close', function() {
host = null;
});
}
// adding a window to fetch and query all the guest details from the firebase
function guestDetail() {
guestDetails = new BrowserWindow({
width: 700,
height:500,
title: 'Guest Details',
webPreferences: {
nodeIntegration: true
}
});
guestDetails.loadFile('guestDetails.html');
guestDetails.on('close', function() {
guestDetails = null;
});
}
// Create Main Menu Template
const mainMenuTemplate = [
{
label: 'File',
submenu: [
{
label: 'Host Login',
click() {
createHost();
}
},
{
label: 'Guest Entry',
click() {
createAddGuest();
}
},
{
label: 'Show Guest Details',
click(){
guestDetail();
}
},
{
label: 'Guest Exit',
click(){
mainWindow.webContents.send('item:clear');
}
},
{
label: 'Exit App',
accelerator: process.platform == 'darwin' ? 'Command+Q' : 'Ctrl+Q',
click(){
app.quit();
}
}
]
}
];
// Adding Dev Tools only for application handlers not in production
if(process.env.NODE_ENV !== 'production'){
mainMenuTemplate.push({
label: 'Developer Tools',
submenu: [
{
label: 'Toogle DevTools',
accelerator: process.platform == 'darwin' ? 'Command + I' : 'Ctrl+I',
click(item, focusedWindow) {
focusedWindow.toggleDevTools();
}
},
{
role: 'reload'
}
]
});
}
// Pushing data into firebase
function test(storeData) {
ref.push(storeData);
return true;
}
// Retrieving Data from firebase
ref.on("value", function(snapshot) {
snapshot.forEach(gus => {console.log(gus.child('Email').val())})
});
//console.log(guestName)
// lets get our app ready
app.on("ready",createWindow);