diff --git a/main.js b/main.js index 9260ccf..281052d 100644 --- a/main.js +++ b/main.js @@ -4,17 +4,18 @@ const path = require('node:path') const socketio = require('socket.io-client') -const socket = socketio('ws://184.83.153.182:5000/') -socket.emit('join-notifications') +let win = null -socket.on('connect-notifications', () => { - console.log('connected to notification stream') - showNotification('Websocket Connected', "You successfully connected to the websocket.") -}) +let getlock = app.requestSingleInstanceLock() -socket.on('send-notification', (data) => { - showNotification(data.title, data.body) -}) +if(!getlock){ + app.quit() +} else { + if (win) { + if (win.isMinimized()) win.restore() + win.focus() + } +} const createWindow = () => { if (!tray){ @@ -69,13 +70,25 @@ function showNotification (title, message) { } app.whenReady().then(() => { - createWindow() - app.setAppUserModelId("Treehouse Hub") + createWindow() + app.setAppUserModelId("Treehouse Hub") app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow() } }) + const socket = socketio('ws://184.83.153.182:5000/') + socket.emit('join-notifications') + + socket.on('connect-notifications', () => { + console.log('connected to notification stream') + showNotification('Websocket Connected', "You successfully connected to the websocket.") + }) + + socket.on('send-notification', (data) => { + showNotification(data.title, data.body) + }) + }) app.on('window-all-closed', (event) => {