mirror of
https://github.com/tcsenpai/swingmusic-desktop.git
synced 2025-06-06 03:05:33 +00:00
refactored part of the code while enhancing usability
This commit is contained in:
parent
c6860ea0d6
commit
87d31ef333
8
.env
8
.env
@ -1,4 +1,4 @@
|
|||||||
SERVER_URL="https://play.discus.sh"
|
SERVER_URL=""
|
||||||
START_SERVER="false"
|
START_SERVER="true"
|
||||||
GEOM_X="1280"
|
GEOM_X="1600"
|
||||||
GEOM_Y="720"
|
GEOM_Y="900"
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ yarn.lock
|
|||||||
node_modules
|
node_modules
|
||||||
build
|
build
|
||||||
dist
|
dist
|
||||||
|
.env
|
||||||
|
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
4
build_app.sh
Executable file
4
build_app.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Building with electron-builder for all platforms
|
||||||
|
yarn start build
|
23
dev_update_and_build_swingmusic.sh
Executable file
23
dev_update_and_build_swingmusic.sh
Executable file
@ -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."
|
37
main.js
37
main.js
@ -1,17 +1,19 @@
|
|||||||
// Modules to control application life and create native browser window
|
// Modules to control application life and create native browser window
|
||||||
const { app, BrowserWindow, screen } = require('electron')
|
const { app, BrowserWindow, screen } = require('electron')
|
||||||
const path = require('node:path')
|
const path = require('node:path')
|
||||||
require('dotenv').config()
|
require('dotenv').config({path: path.join(__dirname, '.env')})
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
console.log(process.env)
|
|
||||||
const server_url = process.env.SERVER_URL
|
|
||||||
|
|
||||||
let factor = null
|
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() {
|
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) => {
|
server.stdout.on('data', (data) => {
|
||||||
console.log(`[SERVER]: ${data}`);
|
console.log(`[SERVER]: ${data}`);
|
||||||
});
|
});
|
||||||
@ -24,20 +26,33 @@ function launchServer() {
|
|||||||
server.on('close', (code) => {
|
server.on('close', (code) => {
|
||||||
console.log(`[SERVER EXITED] child process exited with code ${code}`);
|
console.log(`[SERVER EXITED] child process exited with code ${code}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function determineServer() {
|
||||||
|
// Settings for either local or remote server support
|
||||||
|
server_url = process.env.SERVER_URL
|
||||||
if (process.env.START_SERVER == "true") {
|
if (process.env.START_SERVER == "true") {
|
||||||
console.log("Launching server")
|
console.log("Launching server")
|
||||||
|
// Supports lazy syntax for local server
|
||||||
|
if (!server_url || server_url==="") {
|
||||||
|
server_url = "http://localhost:1970"
|
||||||
|
}
|
||||||
launchServer()
|
launchServer()
|
||||||
} else {
|
} else {
|
||||||
console.log("Server not launched")
|
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 () {
|
function createWindow () {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
icon: "assets/favicon.ico",
|
icon: "assets/icon.png",
|
||||||
title: "SwingMusic",
|
title: "SwingMusic",
|
||||||
center: true,
|
center: true,
|
||||||
width: process.env.GEOM_X / factor,
|
width: process.env.GEOM_X / factor,
|
||||||
@ -57,6 +72,10 @@ function createWindow () {
|
|||||||
// Create the browser window
|
// Create the browser window
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
|
|
||||||
|
// Determining the server
|
||||||
|
determineServer()
|
||||||
|
console.log("Server is: " + server_url)
|
||||||
|
|
||||||
factor = screen.getPrimaryDisplay().scaleFactor;
|
factor = screen.getPrimaryDisplay().scaleFactor;
|
||||||
console.log("factor: ", factor)
|
console.log("factor: ", factor)
|
||||||
createWindow()
|
createWindow()
|
||||||
@ -75,5 +94,3 @@ app.on("before-quit", function() {
|
|||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', function () {
|
||||||
app.quit()
|
app.quit()
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO Avoid launching with the python script: use instead nodejs
|
|
||||||
|
75
package.json
75
package.json
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "electron-quick-start",
|
"name": "swingmusic-desktop",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "A minimal Electron application",
|
"description": "Let there be music",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "electron ."
|
"start": "electron .",
|
||||||
|
"build": "electron-builder build"
|
||||||
},
|
},
|
||||||
"repository": "https://github.com/tcsenpai/swingmusic-desktop.git",
|
"repository": "https://github.com/tcsenpai/swingmusic-desktop.git",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -16,8 +17,74 @@
|
|||||||
],
|
],
|
||||||
"author": "TheCookingSenpai",
|
"author": "TheCookingSenpai",
|
||||||
"license": "CC0-1.0",
|
"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": {
|
"devDependencies": {
|
||||||
"electron": "^28.2.0"
|
"electron": "^28.2.0",
|
||||||
|
"electron-builder": "^24.9.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.4.1"
|
"dotenv": "^16.4.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user