Add SingleInstanceLock

This commit is contained in:
Jadowyne Ulve 2025-05-22 16:58:00 -05:00
parent b06352370a
commit a07e50f0ea

35
main.js
View File

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