diff --git a/functions.js b/functions.js index 4403519..c8d500d 100644 --- a/functions.js +++ b/functions.js @@ -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) @@ -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) @@ -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) { @@ -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) { @@ -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') { diff --git a/icon.icns b/icon.icns new file mode 100644 index 0000000..015992b Binary files /dev/null and b/icon.icns differ diff --git a/package-lock.json b/package-lock.json index cf3c9c1..33932f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obs-timer-controller", - "version": "1.0.4", + "version": "1.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obs-timer-controller", - "version": "1.0.4", + "version": "1.0.5", "license": "ISC", "dependencies": { "axios": "^1.5.1", diff --git a/package.json b/package.json index 137cc26..b2ba9dc 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/server.js b/server.js index 20a23fd..a504a57 100644 --- a/server.js +++ b/server.js @@ -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') { @@ -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.') @@ -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}`); }) @@ -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) @@ -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')) {