Skip to content

Commit 4062b40

Browse files
authored
Merge pull request #12 from BrowserSourcesForOBS/dev
v1.0.6
2 parents 2fd1af9 + 6aaaafa commit 4062b40

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.env
12
core/config.yaml
23
core/db.yaml
34
dist/

core/client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ window.addEventListener('unload', (event) => {
106106
})
107107

108108
buttonClose.addEventListener('click', () => {
109+
socket.send(JSON.stringify({ action: 'stopCode' }))
109110
// Closes the current window or tab
110111
window.close()
111112
})

package-lock.json

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obs-timer-controller",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Handling browser sources for OBS related to timers and countdowns.",
55
"main": "server.js",
66
"repository": {
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"axios": "^1.5.1",
1212
"child_process": "^1.0.2",
13+
"dotenv": "^16.3.1",
1314
"express": "^4.18.2",
1415
"fontkit": "^2.0.2",
1516
"fs-extra": "^11.1.1",
@@ -23,15 +24,15 @@
2324
"scripts": {
2425
"test": "echo \"Error: no test specified\" && exit 1",
2526
"node": "node . test",
26-
"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.\"",
27-
"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.\"",
28-
"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.\"",
27+
"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.\"",
28+
"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.\"",
29+
"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.\"",
2930
"pkg-all": "npm run pkg-win && npm run pkg-linux"
3031
},
3132
"author": "XtoManuel",
3233
"license": "ISC",
3334
"devDependencies": {
34-
"electron": "^27.0.0",
35+
"electron": "^27.0.2",
3536
"electron-packager": "^17.1.2"
3637
}
3738
}

server.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const WebSocket = require('ws')
44
const path = require('path')
55
const fs = require('fs-extra')
66
const open = require('openurl')
7+
const { exec } = require('child_process')
8+
9+
require('dotenv').config() // Load environment variables from .env
710

811
const argsv = process.argv.slice(2)
912

@@ -111,7 +114,7 @@ const actions = {
111114
getVariables: (ws, data) => sendVariableData(ws, GlobalVariables, Config, data.classElement),
112115
createData: (ws, data) => createData(data),
113116
removeData: (ws, data) => removeData(data),
114-
stopCode: () => process.exit()
117+
stopCode: () => stopCode()
115118
}
116119

117120
function sendToAllClients (data) {
@@ -289,6 +292,11 @@ function removeData (data) {
289292
saveVariablesToYAML(GlobalVariables)
290293
}
291294

295+
function stopCode () {
296+
console.log('The code has stopped successfully')
297+
process.exit()
298+
}
299+
292300
// WebSocket connections handling
293301
wss.on('connection', (ws) => {
294302
ws.send(JSON.stringify({ fonts: fontOptions }))
@@ -408,10 +416,35 @@ app.get('/:classElement/control&:request', (req, res) => {
408416

409417
function openUrlWhenConfigExists () {
410418
if (Config) {
411-
open.open(`http://localhost:${PORT}`)
419+
const customBrowser = process.env.BROWSER // Get the value of the BROWSER environment variable
420+
421+
if (customBrowser) {
422+
try {
423+
// If the BROWSER environment variable is defined, try to open that browser
424+
const url = `http://localhost:${PORT}`
425+
switch (process.platform) {
426+
case 'darwin': // macOS
427+
exec(`open -a "${customBrowser}" ${url}`)
428+
break
429+
case 'win32': // Windows
430+
exec(`start ${customBrowser} ${url}`)
431+
break
432+
case 'linux': // Linux
433+
exec(`${customBrowser} ${url}`)
434+
break
435+
default:
436+
console.error('Unsupported operating system.')
437+
}
438+
} catch {
439+
open.open(`http://localhost:${PORT}`)
440+
}
441+
} else {
442+
// If the BROWSER environment variable is not defined, open the default browser
443+
open.open(`http://localhost:${PORT}`)
444+
}
412445
} else {
413-
// Config todavía no existe, espera y vuelve a verificar en un momento
414-
setTimeout(openUrlWhenConfigExists, 1000) // Espera 1 segundo antes de verificar nuevamente
446+
// Configuration doesn't exist yet, wait and check again in a moment
447+
setTimeout(openUrlWhenConfigExists, 1000) // Wait for 1 second before checking again
415448
}
416449
}
417450

0 commit comments

Comments
 (0)