Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
core/config.yaml
core/db.yaml
dist/
Expand Down
1 change: 1 addition & 0 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ window.addEventListener('unload', (event) => {
})

buttonClose.addEventListener('click', () => {
socket.send(JSON.stringify({ action: 'stopCode' }))
// Closes the current window or tab
window.close()
})
Expand Down
24 changes: 18 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obs-timer-controller",
"version": "1.0.5",
"version": "1.0.6",
"description": "Handling browser sources for OBS related to timers and countdowns.",
"main": "server.js",
"repository": {
Expand All @@ -10,6 +10,7 @@
"dependencies": {
"axios": "^1.5.1",
"child_process": "^1.0.2",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"fontkit": "^2.0.2",
"fs-extra": "^11.1.1",
Expand All @@ -23,15 +24,15 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"node": "node . test",
"pkg-win": "electron-packager . OBS-Timer-Controller --platform=win32 --arch=x64 --app-version=1.0.5 --out=dist --overwrite --icon=icon.ico --author=\"XtoManuel\" --description=\"Handling browser sources for OBS related to timers and countdowns.\"",
"pkg-linux": "electron-packager . OBS-Timer-Controller --platform=linux --arch=x64 --app-version=1.0.5 --out=dist --overwrite --icon=icon.ico --author=\"XtoManuel\" --description=\"Handling browser sources for OBS related to timers and countdowns.\"",
"pkg-mac": "electron-packager . OBS-Timer-Controller --platform=darwin --arch=x64 --app-version=1.0.5 --out=dist --overwrite --icon=icon.icns --author=\"XtoManuel\" --description=\"Handling browser sources for OBS related to timers and countdowns.\"",
"pkg-win": "electron-packager . OBS-Timer-Controller --platform=win32 --arch=x64 --app-version=1.0.6 --out=dist --overwrite --icon=icon.ico --author=\"XtoManuel\" --description=\"Handling browser sources for OBS related to timers and countdowns.\"",
"pkg-linux": "electron-packager . OBS-Timer-Controller --platform=linux --arch=x64 --app-version=1.0.6 --out=dist --overwrite --icon=icon.ico --author=\"XtoManuel\" --description=\"Handling browser sources for OBS related to timers and countdowns.\"",
"pkg-mac": "electron-packager . OBS-Timer-Controller --platform=darwin --arch=x64 --app-version=1.0.6 --out=dist --overwrite --icon=icon.icns --author=\"XtoManuel\" --description=\"Handling browser sources for OBS related to timers and countdowns.\"",
"pkg-all": "npm run pkg-win && npm run pkg-linux"
},
"author": "XtoManuel",
"license": "ISC",
"devDependencies": {
"electron": "^27.0.0",
"electron": "^27.0.2",
"electron-packager": "^17.1.2"
}
}
41 changes: 37 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const WebSocket = require('ws')
const path = require('path')
const fs = require('fs-extra')
const open = require('openurl')
const { exec } = require('child_process')

require('dotenv').config() // Load environment variables from .env

const argsv = process.argv.slice(2)

Expand Down Expand Up @@ -111,7 +114,7 @@ const actions = {
getVariables: (ws, data) => sendVariableData(ws, GlobalVariables, Config, data.classElement),
createData: (ws, data) => createData(data),
removeData: (ws, data) => removeData(data),
stopCode: () => process.exit()
stopCode: () => stopCode()
}

function sendToAllClients (data) {
Expand Down Expand Up @@ -289,6 +292,11 @@ function removeData (data) {
saveVariablesToYAML(GlobalVariables)
}

function stopCode () {
console.log('The code has stopped successfully')
process.exit()
}

// WebSocket connections handling
wss.on('connection', (ws) => {
ws.send(JSON.stringify({ fonts: fontOptions }))
Expand Down Expand Up @@ -408,10 +416,35 @@ app.get('/:classElement/control&:request', (req, res) => {

function openUrlWhenConfigExists () {
if (Config) {
open.open(`http://localhost:${PORT}`)
const customBrowser = process.env.BROWSER // Get the value of the BROWSER environment variable

if (customBrowser) {
try {
// If the BROWSER environment variable is defined, try to open that browser
const url = `http://localhost:${PORT}`
switch (process.platform) {
case 'darwin': // macOS
exec(`open -a "${customBrowser}" ${url}`)
break
case 'win32': // Windows
exec(`start ${customBrowser} ${url}`)
break
case 'linux': // Linux
exec(`${customBrowser} ${url}`)
break
default:
console.error('Unsupported operating system.')
}
} catch {
open.open(`http://localhost:${PORT}`)
}
} else {
// If the BROWSER environment variable is not defined, open the default browser
open.open(`http://localhost:${PORT}`)
}
} else {
// Config todavía no existe, espera y vuelve a verificar en un momento
setTimeout(openUrlWhenConfigExists, 1000) // Espera 1 segundo antes de verificar nuevamente
// Configuration doesn't exist yet, wait and check again in a moment
setTimeout(openUrlWhenConfigExists, 1000) // Wait for 1 second before checking again
}
}

Expand Down