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
31 changes: 24 additions & 7 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ async function darkThemeCheck () {
// Read the package.json file
async function getVersion () {
try {
const data = await fs.promises.readFile((argsv[0] === 'test') ? './package.json' : './resources/app/package.json', 'utf8')
// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Build the path to the package.json file
const data = await fs.promises.readFile((argsv[0] === 'test') ? './package.json' : `./${appFolder}/app/package.json`, 'utf8')

// Parse the content of the JSON file
const packageJson = await JSON.parse(data)
Expand Down Expand Up @@ -143,8 +147,11 @@ exports.loadConfig = async () => {
let Config

try {
// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Read the YAML file (if it exists)
const yamlFile = fs.readFileSync((argsv[0] === 'test') ? './core/config.yaml' : './resources/app/core/config.yaml', 'utf8')
const yamlFile = fs.readFileSync((argsv[0] === 'test') ? './core/config.yaml' : `./${appFolder}/app/core/config.yaml`, 'utf8')

// Convert the YAML file content to a JavaScript object
const data = yaml.load(yamlFile)
Expand All @@ -169,8 +176,11 @@ exports.saveConfig = (config) => {
// Convert the configuration object to YAML format
const configYAML = yaml.dump(config)

// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Write the content to the YAML file
fs.writeFileSync((argsv[0] === 'test') ? './core/config.yaml' : './resources/app/core/config.yaml', configYAML, 'utf8')
fs.writeFileSync((argsv[0] === 'test') ? './core/config.yaml' : `./${appFolder}/app/core/config.yaml`, configYAML, 'utf8')

// console.log('Variables saved to YAML file.');
} catch (error) {
Expand Down Expand Up @@ -207,8 +217,11 @@ exports.saveVariablesToYAML = (GlobalVariables) => {
// Convert global variables to YAML format
const variablesYAML = yaml.dump(GlobalVariables)

// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Write the content to the YAML file
fs.writeFileSync((argsv[0] === 'test') ? './core/db.yaml' : './resources/app/core/db.yaml', variablesYAML, 'utf8')
fs.writeFileSync((argsv[0] === 'test') ? './core/db.yaml' : `./${appFolder}/app/core/db.yaml`, variablesYAML, 'utf8')

// console.log('Variables saved to YAML file.');
} catch (error) {
Expand Down Expand Up @@ -319,9 +332,13 @@ exports.createDataYAML = (GlobalVariables, classType) => {

// Send variable data to a WebSocket client
exports.sendVariableData = (client, GlobalVariables, configuration, classE) => {
if (GlobalVariables && typeof GlobalVariables === 'object') {
const formats = this.loadDataFromYAML((argsv[0] === 'test') ? './core/formats.yaml' : './resources/app/core/formats.yaml')
const translates = this.loadDataFromYAML((argsv[0] === 'test') ? `./core/translates/${configuration.lang}.yaml` : `./resources/app/core/translates/${configuration.lang}.yaml`)
if (GlobalVariables && typeof GlobalVariables === 'object') {
// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Build the path to the package.json file
const formats = this.loadDataFromYAML((argsv[0] === 'test') ? './core/formats.yaml' : `./${appFolder}/app/core/formats.yaml`)
const translates = this.loadDataFromYAML((argsv[0] === 'test') ? `./core/translates/${configuration.lang}.yaml` : `./${appFolder}/app/core/translates/${configuration.lang}.yaml`)

// Send variable data to the client
if (classE === 'home') {
Expand Down
Binary file added icon.icns
Binary file not shown.
4 changes: 2 additions & 2 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "obs-timer-controller",
"version": "1.0.5",
"description": "Handling browser fonts for OBS related to timers and countdowns.",
"description": "Handling browser sources for OBS related to timers and countdowns.",
"main": "server.js",
"repository": {
"type": "git",
Expand All @@ -23,10 +23,10 @@
"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 fonts 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 fonts 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.ico --author=\"XtoManuel\" --description=\"Handling browser fonts for OBS related to timers and countdowns.\"",
"pkg-all": "npm run pkg-win && npm run pkg-linux && npm run pkg-mac"
"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-all": "npm run pkg-win && npm run pkg-linux && npm pkg-mac"
},
"author": "XtoManuel",
"license": "ISC",
Expand Down
31 changes: 25 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ const fontOptions = getFonts()

// Load variables from the YAML file at server startup
let GlobalVariables
GlobalVariables = loadDataFromYAML((argsv[0] === 'test') ? './core/db.yaml' : './resources/app/core/db.yaml')

// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Build the path to the package.json file
GlobalVariables = loadDataFromYAML((argsv[0] === 'test') ? './core/db.yaml' : `./${appFolder}/app/core/db.yaml`)
try {
Object.keys(GlobalVariables).forEach((key) => {
if (GlobalVariables[key].status === 'started') {
Expand Down Expand Up @@ -250,9 +255,14 @@ function changeColor (data) {

function createData (data) {
const page = createDataYAML(GlobalVariables, data.classType)

// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

fs.copy(
argsv[0] === 'test' ? `./core/template/${data.classType}` : `./resources/app/core/template/${data.classType}`,
argsv[0] === 'test' ? `./core/${page}` : `./resources/app/core/${page}`
// Build the path to the package.json file
argsv[0] === 'test' ? `./core/template/${data.classType}` : `./${appFolder}/app/core/template/${data.classType}`,
argsv[0] === 'test' ? `./core/${page}` : `./${appFolder}/app/core/${page}`
)
.then(() => {
console.log('Folder copied successfully.')
Expand All @@ -264,7 +274,12 @@ function createData (data) {

function removeData (data) {
delete GlobalVariables[data.remove]
fs.remove(argsv[0] === 'test' ? `./core/${data.remove}` : `./resources/app/core/${data.remove}`)

// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Build the path to the package.json file
fs.remove(argsv[0] === 'test' ? `./core/${data.remove}` : `./${appFolder}/app/core/${data.remove}`)
.then(() => {
// console.log(`Folder deleted successfully: ${folderToDelete}`);
})
Expand All @@ -281,7 +296,11 @@ wss.on('connection', (ws) => {
ws.on('message', (message) => {
const data = JSON.parse(message)

GlobalVariables = loadDataFromYAML(argsv[0] === 'test' ? './core/db.yaml' : './resources/app/core/db.yaml')
// Determines the folder name based on the operating system
const appFolder = process.platform === 'darwin' ? 'Resources' : 'resources'

// Build the path to the package.json file
GlobalVariables = loadDataFromYAML(argsv[0] === 'test' ? './core/db.yaml' : `./${appFolder}/app/core/db.yaml`)

if (actions[data.action]) {
actions[data.action](ws, data)
Expand Down Expand Up @@ -309,7 +328,7 @@ app.get('/:classElement/control', (req, res) => {
app.get('/:classElement/control&:request', (req, res) => {
const classElement = req.params.classElement
const request = req.params.request
GlobalVariables = loadDataFromYAML((argsv[0] === 'test') ? './core/db.yaml' : './resources/app/core/db.yaml')
GlobalVariables = loadDataFromYAML((argsv[0] === 'test') ? './core/db.yaml' : `./${appFolder}/app/core/db.yaml`)

// Here you can check the value of 'request' and perform the corresponding action
if (request === 'start' && !classElement.startsWith('cdowntime') && !classElement.startsWith('time')) {
Expand Down