diff --git a/main.js b/main.js index a03f790..2042452 100644 --- a/main.js +++ b/main.js @@ -434,58 +434,33 @@ async function start() { sendToTauri('status', { message: 'Loading encrypted credentials...' }); serviceManager.credentialManager.loadCredentials(); - sendToTauri('status', { message: 'Starting background services (player)...' }); + sendToTauri('status', { message: 'Installing dependencies...' }); + const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'; + const frontendDir = path.join(APPDATA_DIR, 'frontend'); + if (fs.existsSync(path.join(frontendDir, 'package.json'))) { + const { spawnSync } = require('child_process'); + spawnSync(npmCmd, ['install'], { + cwd: frontendDir, + stdio: 'ignore', + windowsHide: true, + shell: process.platform === 'win32' + }); + } + + sendToTauri('status', { message: 'Starting services (player, frontend)...' }); await serviceManager.startServices([ - { name: 'player', relativeDir: 'player', startScript: 'server.js' } + { name: 'player', relativeDir: 'player', startScript: 'server.js' }, + { name: 'frontend', relativeDir: 'frontend', startScript: 'server.js' } ]); debugLog("Backend services spawn requested."); - sendToTauri('status', { message: 'Waiting for microservices to bind port 3000...' }); - await serviceManager.waitForPorts([3000]); - debugLog("Port 3000 is ready."); + sendToTauri('status', { message: 'Waiting for microservices to bind...' }); + await serviceManager.waitForPorts([3000, 4890]); + debugLog("Ports 3000 and 4890 are ready."); - sendToTauri('status', { message: 'Binding UI server on port 4890...' }); - const frontendDir = path.join(APPDATA_DIR, 'frontend'); - expressApp = express(); - expressApp.use((req, res, next) => { - res.header('Access-Control-Allow-Origin', '*'); - res.header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS'); - res.header('Access-Control-Allow-Headers', '*'); - if (req.method === 'OPTIONS') return res.sendStatus(200); - next(); - }); - expressApp.get('/__tauri_cmd/:cmd', (req, res) => { - debugLog(`[FRONTEND-SERVER:4890] Command received: ${req.params.cmd} (window: ${req.query.window || 'main'})`); - sendToTauri('tauri-cmd', { cmd: req.params.cmd, url: req.query.url, window: req.query.window }); - res.sendStatus(200); - }); - - expressApp.use(sameTabNavMiddleware(frontendDir)); - expressApp.use(express.static(frontendDir, { - etag: false, - setHeaders: (res) => { - res.set('Cache-Control', 'no-store, no-cache, must-revalidate, private'); - } - })); - expressApp.use(express.static(path.join(frontendDir, 'src'), { - etag: false, - setHeaders: (res) => { - res.set('Cache-Control', 'no-store, no-cache, must-revalidate, private'); - } - })); - expressApp.get('*', (req, res) => { - res.set('Cache-Control', 'no-store, no-cache, must-revalidate, private'); - res.sendFile(path.join(frontendDir, 'index.html')); - }); - - const FRONTEND_PORT = 4890; - expressApp.use('/build', express.static(path.join(__dirname, 'build'))); - - expressServer = expressApp.listen(FRONTEND_PORT, '127.0.0.1', () => { - sendToTauri('status', { message: 'All backend services running and healthy.' }); - debugLog("Frontend Express running on 4890. Sending READY to Tauri."); - sendToTauri('ready', { url: `http://127.0.0.1:${FRONTEND_PORT}` }); - }); + sendToTauri('status', { message: 'All backend services running and healthy.' }); + debugLog("Sending READY to Tauri."); + sendToTauri('ready', { url: 'http://127.0.0.1:4890' }); } catch (error) { debugLog(`Fatal Start Error: ${error.message}`); diff --git a/package.json b/package.json index 5e0af0d..d61c176 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@tauri-apps/plugin-opener": "^2.7.0", "@tauri-apps/plugin-process": "^2.4.0", "@tauri-apps/plugin-shell": "^2.4.0", - "@vyla-entertainment/sdk": "^1.16.0", + "@vyla-entertainment/sdk": "^1.18.0", "adm-zip": "^0.6.0", "express": "^4.19.2" }, @@ -54,4 +54,4 @@ "installerHeaderIcon": "build/icon.ico" } } -} +} \ No newline at end of file diff --git a/patcher.js b/patcher.js index e95f825..2ac0591 100644 --- a/patcher.js +++ b/patcher.js @@ -116,7 +116,7 @@ class Patcher { verifyExtraction() { const requiredFiles = [ - 'frontend/index.html', + 'frontend/server.js', 'player/server.js' ]; diff --git a/service-manager.js b/service-manager.js index 99650b1..5dbbd18 100644 --- a/service-manager.js +++ b/service-manager.js @@ -47,8 +47,14 @@ class ServiceManager { this.credentialManager.setCredential('player', 'TOKEN_SECRET', tokenSecret); } + const defaultPorts = { + player: 3000, + frontend: 4890 + }; + const env = { ...process.env, + PORT: (this.envConfig[name] && this.envConfig[name].PORT) || defaultPorts[name] || process.env.PORT || 3000, TOKEN_SECRET: tokenSecret, ...(this.envConfig[name] || {}), ...(this.credentialManager.getServiceCredentials(name) || {}) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8798165..d169945 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -433,7 +433,7 @@ const LINK_HANDLER_SCRIPT: &str = nav.id = 'vyla-floating-nav'; nav.innerHTML = `
+