From d62ec24da8797ad667e6ba869246b728ed275a48 Mon Sep 17 00:00:00 2001 From: chinmaydixit20 <55713205+chinmaydixit20@users.noreply.github.com> Date: Mon, 6 Jul 2020 19:09:13 +0530 Subject: [PATCH] Active users working --- backend/server.js | 1 + public/electron.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- public/index.html | 11 ----------- public/js/index.js | 2 +- public/js/main.js | 4 +++- 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/backend/server.js b/backend/server.js index 2d9fb42..95d9276 100644 --- a/backend/server.js +++ b/backend/server.js @@ -46,6 +46,7 @@ io.on('connection', socket => { socket.on('switch_room', (room) => { const oldRoom = currentUser(socket.id).room; + console.log(oldRoom); const u = userSwitch(socket.id, room); socket.leaveAll(); socket.join(u.room); diff --git a/public/electron.js b/public/electron.js index c4ba136..e4dc8ac 100644 --- a/public/electron.js +++ b/public/electron.js @@ -3,6 +3,7 @@ const path = require('path'); const url = require('url'); const { app, BrowserWindow, ipcMain } = electron; const isDev = require('electron-is-dev'); +const { Menu, globalShortcut } = require('electron'); let mainWindow; @@ -16,6 +17,10 @@ function createWindow() { }); mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, 'index.html')}`); mainWindow.on('closed', () => mainWindow = null); + globalShortcut.register('CmdOrCtrl+Q', () => app.quit()); + + const menu = Menu.buildFromTemplate(menuTemplate); + Menu.setApplicationMenu(menu); } ipcMain.on('userLogin', (e, user) => { @@ -36,4 +41,42 @@ app.on('activate', () => { if (mainWindow === null) { createWindow(); } -}); \ No newline at end of file +}); + +const menuTemplate = [ + { + label: 'Chat', + submenu: [ + { + label: 'Quit', + click() { + app.quit(); + } + }, + { + type: 'separator' + }, + { + role: 'reload' + } + ] + } +] + +if(isDev) { + menuTemplate.push({ + label: 'DevTools', + submenu: [ + { + label: 'DevTools', + click(item, focusedWindow) { + focusedWindow.toggleDevTools(); + } + } + ] + }) +} + +if(process.platform == 'darwin') { + menuTemplate.unshift(); +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index 97d9a92..3e9b75b 100644 --- a/public/index.html +++ b/public/index.html @@ -41,17 +41,6 @@

ChatApp

required /> - diff --git a/public/js/index.js b/public/js/index.js index ccfbab5..5c38242 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -11,7 +11,7 @@ register.addEventListener('submit', (e) => { } console.log(regUser); axios.post('http://localhost:3000/user/register', regUser) - .then(res => alert(res.data)); + .then(res => console.log(res.data)); e.target.elements.username.value = ''; e.target.elements.password.value = ''; diff --git a/public/js/main.js b/public/js/main.js index c307b5a..b2c2a68 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,5 +1,6 @@ const socket = io(); //new connection const electron = require('electron'); +const moment = require('moment'); const { ipcRenderer } = electron; const chatForm = document.getElementById('chat-form'); const chatMessages = document.querySelector('.chat-messages'); @@ -35,7 +36,7 @@ socket.on('loadMsgs', user => { const message = { username: msg.from, text: msg.body, - time: 0 + time: moment(msg.updatedAt).format('DD-MM h:mm a') } outputMessage(message); }) @@ -49,6 +50,7 @@ roomList.addEventListener('click', (e) => { console.log(e.target.innerHTML); const room = e.target.innerHTML; if(room !== currentRoom) { + currentRoom = room; socket.emit('switch_room', room);