-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
204 lines (160 loc) · 5.73 KB
/
main.js
File metadata and controls
204 lines (160 loc) · 5.73 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
const { app, BrowserWindow, ipcMain, dialog } = require("electron");
const path = require("path");
const fs = require("fs");
//backend js files
const dbMngr = require('./dbManager');
const scoreVal = require('./scoreValidation');
const createWindow = () => {
const win = new BrowserWindow({
width: 1280,
height: 720,
webPreferences: {
preload: path.join(__dirname, '/js/preload.js'),
},
});
// We cannot require the screen module until the app is ready.
const { screen } = require('electron')
// Create a window that fills the screen's available work area.
const primaryDisplay = screen.getPrimaryDisplay()
const { width, height } = primaryDisplay.workAreaSize
win.setMinimumSize(width / 2, height / 2);
win.loadFile('html/index.html');
};
app.whenReady().then(() => {
ipcMain.handle("openPackagesDir", async () => {
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
properties: ["openFile", "multiSelections"],
filters: [
{ name: "Packages", extensions: ["db"], }
],
});
});
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
/********************************************************
*
* ELECTRON MAIN HANDLERS FOR KNEX DB CALL
*
*******************************************************/
//merge inputted database path to main database
ipcMain.handle('mergeDB', async (event, dbPath)=> {
const res = await dbMngr.mergeDatabases(dbPath);
return res;
});
ipcMain.handle('replaceDB', async (event, dbPath)=> {
const res = await dbMngr.replaceDatabase(dbPath);
return res;
});
ipcMain.handle('exportDB', async (event)=> {
const res = await dbMngr.exportDatabase();
return res;
});
ipcMain.handle('databaseAction', async (event, bReplace) => {
var result = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
properties: ["openFile"],
filters: [{
name: "Package", extensions: ["db"],
}]
});
if(!result.canceled && result.filePaths.length) {
var path = result.filePaths[0];
//const database = dbMngr.getDBPath("InQuizIt.db");
if(fs.existsSync(path)) {
// if(!fs.existsSync(database))
// fs.copyFileSync(path, database);
// else {
if(bReplace)
return await dbMngr.replaceDatabase(path);
else
return await dbMngr.mergeDatabases(path);
//}
}
}
});
//Question Data Insertion
ipcMain.handle('newQuestionSet', async (event, Category, Name, Options)=> {
const res = await dbMngr.newQuestionSet(Category, Name, Options);
return res;
});
ipcMain.handle('newQuestion', async (event, Category, Name, Options, Type, Question)=> {
const res = await dbMngr.newQuestion(Category, Name, Options, Type, Question);
return res;
});
ipcMain.handle('newAnswer', async (event, Category, Name, Options, Type, Question,Ans)=> {
const res = await dbMngr.newAnswer(Category, Name, Options, Type, Question,Ans);
return res;
});
//user insertion
ipcMain.handle('newUser', async (event, FirstName, LastName)=> {
const res = await dbMngr.newUser(FirstName, LastName);
return res;
});
//user retrieval
ipcMain.handle('getAllUsers', async (event) => {
const res = await dbMngr.getAllUsers();
return res;
});
//Question data retrieval
ipcMain.handle('getAllQuestionSets', async (event) => {
const res = await dbMngr.getAllQuestionSets();
return res;
});
ipcMain.handle('getAllCategories', async (event) => {
const res = await dbMngr.getAllCategories();
return res;
});
ipcMain.handle('getQuestionSet', async (event,setCategory, setName, setOptions) => {
const res = await dbMngr.getQuestionSet(setCategory, setName, setOptions);
return res;
});
ipcMain.handle('getAllQuestions', async (event, setCategory, setName, setOptions) => {
const res = await dbMngr.getAllQuestions(setCategory, setName, setOptions);
return res;
});
ipcMain.handle('getAllAnswers', async (event, setCategory, setName, setOptions, questionContent, questionType) => {
const res = await dbMngr.getAllAnswers(setCategory, setName, setOptions, questionContent, questionType);
return res;
});
//Deletion
ipcMain.handle('delQuestion', async (event, setCategory, setName, setOptions, questionContent, questionType) => {
const res = await dbMngr.deleteQuestion(setCategory, setName, setOptions, questionContent, questionType);
return res;
});
ipcMain.handle('delQuestionSet', async (event, setCategory, setName, setOptions) => {
const res = await dbMngr.deleteQuestionSet(setCategory, setName, setOptions);
return res;
});
ipcMain.handle('delUser', async (event, firstName, lastName) => {
const res = await dbMngr.deleteUser(firstName, lastName);
return res;
});
/*******************************************************
* Score Database Functions
*******************************************************/
ipcMain.handle('getAllScores', async (event,firstName,lastName) => {
const res = await dbMngr.getAllScores(firstName,lastName);
return res;
});
ipcMain.handle('updateScore', async (event,firstName,lastName, setCategory, setName, setOptions, scoreVal) => {
const res = await dbMngr.updateScore(firstName,lastName, setCategory, setName, setOptions, scoreVal);
return res;
});
/*******************************************************
* Score Validation Funcitons
*******************************************************/
ipcMain.handle('encryptScore', (event,scoreString) => {
return scoreVal.encryptScore(scoreString);
});
ipcMain.handle('decryptScore', (event,str1,str2,str3) => {
return scoreVal.decryptScore(str1,str2,str3);
});