-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
141 lines (120 loc) · 3.54 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
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
const electron=require('electron');
const url = require('url');
const path = require('path');
const express = require('express');
const server = express();
const exserver = require('http').createServer(server);
const session = require('express-session');
const parser = require('body-parser');
const io = require('socket.io').listen(exserver);
const mysql = require('mysql');
const fs = require('fs');
process.env.NODE_ENV = 'development'; //change to production for release builds
server.use(parser.json());
server.use(parser.urlencoded({ extended: true}));
server.use(session({
name : 'sID',
secret : '#14@4%=%^25$',
resave: false,
saveUninitialized:false
}));
exserver.listen(process.env.PORT || 3000); //Listening on port 3000
server.get('/',function(req,res){
req.session.currentCommunity = "roorkee"; //will later be replaced by the current location of the user, obtained via geolocation API
req.session.uname = "USER"; //will be replaced by logged credentials
res.sendFile(__dirname+'/main.html');
});
const {app, BrowserWindow, Menu, ipcMain} = electron;
let mainWindow;
app.on('ready',function(){
mainWindow = new BrowserWindow({});
mainWindow.maximize();
mainWindow.loadURL('http://localhost:3000/');
const mainmenu = Menu.buildFromTemplate(menutemp);
Menu.setApplicationMenu(mainmenu);
if(process.env.NODE_ENV!='development'){
mainWindow.setMenuBarVisibility(false);
}
});
let pwindow; //just a placeholder for debugging.
function profile(){
pwindow= new BrowserWindow({
height:500,
width:200
});
pwindow.loadURL(url.format({
pathname: path.join(__dirname,'comsign.html'),
protocol:'file:',
slashes:true
}));
}
// template for the top-menu
const menutemp = [{
label:'user',
submenu:[{
label:'profile',
click(){development
profile();}
},
{
label:'privacy settings'
},
{
label:'Quit',
accelerator :'ctrl+w',
click(){app.quit();}
}]
}];
//for ease in development
if(process.env.NODE_ENV=='development'){
menutemp.push({
label : 'Developer tools',
submenu :[{
label: "Dev Tools",
click(item,focusedWindow){focusedWindow.toggleDevTools();},
accelerator: 'ctrl + i'
},{
role : 'reload'
}]
})
}
//express starts here
//handle requests to open a community
server.get('/communities/:com/:page',function(req,res){
if(req.params.page=='dashboard'){
req.session.currentCommunity = req.params.com; //stores the currently active community as a session variable
$images = fs.readdirSync('images/public/'+req.params.com+'/');
res.render('comdash.ejs',{comname:req.params.com , gallery:[$images[0],$images[1],$images[2],$images[3],$images[4]] }); //for non-members
}
else{
res.render('commain',{ comname:req.params.com}); // for members of the community
}
});
//Add memo page
server.get('/memo',function(req,res){
res.render('memo.ejs',{ uname : req.session.uname });
});
//handle community join requests
server.get('/join/:com',function(req,res){
//TODO
});
//Image routing
server.get('/images/dispics/:com',function(req,res){
res.sendFile(__dirname+'/images/dispics/'+req.params.com+'.jpg');
});
//Serving gallery images
server.get('/images/public/:file',function(req,res){
res.sendFile(__dirname + '/images/public/'+req.session.currentCommunity+'/'+req.params.file);
});
//CSS files
server.get('/styles/:file',function(req,res){
res.sendFile(__dirname+'/styles/'+req.params.file);
});
//JS Files
server.get('/scripts/:file',function(req,res){
res.sendFile(__dirname+'/scripts/'+req.params.file);
});
//Lib files
server.get('/lib/:file',function(req,res){
res.sendFile(__dirname+'/lib/'+req.params.file);
});