diff --git a/.env b/.env index 39e5bcc..584be1d 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -SERVER_URL="https://play.discus.sh" -START_SERVER="false" -GEOM_X="1280" -GEOM_Y="720" \ No newline at end of file +SERVER_URL="" +START_SERVER="true" +GEOM_X="1600" +GEOM_Y="900" \ No newline at end of file diff --git a/.gitignore b/.gitignore index bf3ee36..4fd2852 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ package-lock.json yarn.lock node_modules build -dist \ No newline at end of file +dist +.env diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..1a8e433 Binary files /dev/null and b/assets/icon.png differ diff --git a/build_app.sh b/build_app.sh new file mode 100755 index 0000000..525ae5d --- /dev/null +++ b/build_app.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Building with electron-builder for all platforms +yarn start build \ No newline at end of file diff --git a/dev_update_and_build_swingmusic.sh b/dev_update_and_build_swingmusic.sh new file mode 100755 index 0000000..243a120 --- /dev/null +++ b/dev_update_and_build_swingmusic.sh @@ -0,0 +1,23 @@ +# Updating +cd ../swingmusic || exit -1 +git pull || exit -2 +cd ../swingmusic-client || exit -3 +git pull || exit -4 + +# Cleanup +cd ../swingmusic || exit -5 +rm -rf client/* || exit -6 +rm -rf build dist || exit -7 + +# Build the client +cd ../swingmusic-client || exit -8 +yarn build --outDir ../swingmusic/client/ || exit -9 + +# Build the server +cd ../swingmusic || exit -10 +poetry run python manage.py --build || exit -11 + +# Copying the client to the appropriate location +echo "Done building. Moving to the next step" +cp -r dist/swingmusic ../swingmusic-desktop/swingmusic_bin || exit -12 +echo "Done copying. Done." \ No newline at end of file diff --git a/main.js b/main.js index 8306bf2..a73fa70 100644 --- a/main.js +++ b/main.js @@ -1,17 +1,19 @@ // Modules to control application life and create native browser window const { app, BrowserWindow, screen } = require('electron') const path = require('node:path') -require('dotenv').config() +require('dotenv').config({path: path.join(__dirname, '.env')}) const { spawn } = require('child_process'); -console.log(process.env) -const server_url = process.env.SERVER_URL - let factor = null +let server = null +let server_url = null -var server = null +// Debug line +console.log(process.env) + +// Allow launching a local server quickly function launchServer() { - server = spawn('swingmusic_bin/swingmusic'); + server = spawn('swingmusic_bin/swingmusic', ["--host", "127.0.0.1", "--port", "1970"]); // Defaults to 1970 port server.stdout.on('data', (data) => { console.log(`[SERVER]: ${data}`); }); @@ -24,20 +26,33 @@ function launchServer() { server.on('close', (code) => { console.log(`[SERVER EXITED] child process exited with code ${code}`); }); - } -if (process.env.START_SERVER == "true") { - console.log("Launching server") - launchServer() -} else { - console.log("Server not launched") +function determineServer() { + // Settings for either local or remote server support + server_url = process.env.SERVER_URL + if (process.env.START_SERVER == "true") { + console.log("Launching server") + // Supports lazy syntax for local server + if (!server_url || server_url==="") { + server_url = "http://localhost:1970" + } + launchServer() + } else { + console.log("Server not launched") + } + + // Mandatory: we need a server_url here + if (!server_url || server_url==="") { + console.log("[FATAL] Server URL is not defined") + process.exit(-1) + } } function createWindow () { // Create the browser window. const mainWindow = new BrowserWindow({ - icon: "assets/favicon.ico", + icon: "assets/icon.png", title: "SwingMusic", center: true, width: process.env.GEOM_X / factor, @@ -57,6 +72,10 @@ function createWindow () { // Create the browser window app.whenReady().then(() => { + // Determining the server + determineServer() + console.log("Server is: " + server_url) + factor = screen.getPrimaryDisplay().scaleFactor; console.log("factor: ", factor) createWindow() @@ -74,6 +93,4 @@ app.on("before-quit", function() { app.on('window-all-closed', function () { app.quit() -}) - -// TODO Avoid launching with the python script: use instead nodejs +}) \ No newline at end of file diff --git a/package.json b/package.json index 6f9afbd..c30d8db 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { - "name": "electron-quick-start", + "name": "swingmusic-desktop", "version": "1.0.0", - "description": "A minimal Electron application", + "description": "Let there be music", "main": "main.js", "scripts": { - "start": "electron ." + "start": "electron .", + "build": "electron-builder build" }, "repository": "https://github.com/tcsenpai/swingmusic-desktop.git", "keywords": [ @@ -16,8 +17,74 @@ ], "author": "TheCookingSenpai", "license": "CC0-1.0", + "build": { + "appId": "com.swingmusic.swingmusic-desktop", + "mac": { + "target": "zip", + "category": "io.music.swingmusic" + }, + "win": { + "target": "portable" + }, + "linux": { + "target": "AppImage", + "category": "Music", + "description": "Let there be music", + "desktop": { + "Name": "SwingMusicDesktop", + "Comment": "Let there be music", + "executableName": "swingmusic-desktop", + "Icon": "build/icons/icon.png" + } + }, + "directories": { + "output": "dist/", + "buildResources": "assets/" + }, + "files": [ + "dist/main/**/*", + "node_modules/**/*", + "main.js", + "libs/**/*", + ".env", + "package.json", + "assets/**/*", + "swingmusic_bin/**/*" + ], + "extraFiles": [ + { + "from": "swingmusic_bin/swingmusic", + "to": "swingmusic_bin/swingmusic", + "filter": [ + "**/*" + ] + }, + { + "from": ".env", + "to": ".env", + "filter": [ + "**/*" + ] + }, + { + "from": "assets", + "to": "assets", + "filter": [ + "**/*" + ] + }, + { + "from": "swingmusic_bin/swingmusic.exe", + "to": "swingmusic_bin/swingmusic.exe", + "filter": [ + "**/*" + ] + } + ] + }, "devDependencies": { - "electron": "^28.2.0" + "electron": "^28.2.0", + "electron-builder": "^24.9.1" }, "dependencies": { "dotenv": "^16.4.1"