diff --git a/app/electron-builder.config.js b/app/electron-builder.config.js index 9551ae94..904c704d 100644 --- a/app/electron-builder.config.js +++ b/app/electron-builder.config.js @@ -10,7 +10,7 @@ const config = { output: 'dist', buildResources: './assets/', }, - files: ['build/**'], + files: ['build/**', './server/**', './generated/**'], extraMetadata: { version: getVersion(), }, @@ -44,8 +44,9 @@ const config = { category: 'Audio', artifactName: `\${name}-linux-\${arch}-${getGithubSafeVersion()}.\${ext}`, }, - extraResources: ['./server/**', './generated/**'], - asar: false, + // extraResources: ['./server/**', './generated/**'], + asar: true, + asarUnpack: ['node_modules/ffmpeg-static/**'], }; module.exports = config; diff --git a/app/main_process/server.ts b/app/main_process/server.ts index 85b53d45..2fb08ebb 100644 --- a/app/main_process/server.ts +++ b/app/main_process/server.ts @@ -1,7 +1,7 @@ import path from 'path'; import process from 'process'; import fs from 'fs'; -import { spawn } from 'child_process'; +import { spawn, execFile } from 'child_process'; import { app, dialog } from 'electron'; import { publishServerInfo, publishServerStderr } from '../ipc/ipc_main'; import { ServerInfo } from './types'; @@ -15,8 +15,12 @@ function findServer() { // In development path.join(process.cwd(), 'server', 'server'), path.join(process.cwd(), 'server', 'server.exe'), + + path.join('server', 'server'), + path.join('server', 'server.exe'), ]; for (const path of possibilities) { + console.log('trying', path, 'exists:', fs.existsSync(path)); if (fs.existsSync(path)) { return path; } @@ -45,8 +49,7 @@ function getServerProcess() { return null; } console.log('Starting server from', path); - return spawn(path, { - stdio: 'pipe', + return execFile(path, { env: { ...process.env }, }); } @@ -73,21 +76,24 @@ function startServer() { if (!serverProcess) { return; } - serverProcess.stdout.on('data', (data: Buffer) => { + serverProcess.stdout?.on('data', (data: Buffer) => { console.log('server-stdout', data.toString()); - try { - const parsed_data: ServerStartingMessage | ServerStartedMessage = JSON.parse(data.toString()); - if (parsed_data.msg == 'server_starting') { - publishServerInfo({ state: 'starting', port: parsed_data.port }); - } else if (parsed_data.msg == 'server_started') { - publishServerInfo({ state: 'running', token: parsed_data.token }); + for (const line of data.toString().trim().split(/\r?\n/)) { + console.log('line', line); + try { + const parsed_data: ServerStartingMessage | ServerStartedMessage = JSON.parse(line); + if (parsed_data.msg == 'server_starting') { + publishServerInfo({ state: 'starting', port: parsed_data.port }); + } else if (parsed_data.msg == 'server_started') { + publishServerInfo({ state: 'running', token: parsed_data.token }); + } + } catch (e) { + console.log('error decoding stdout json', e); } - } catch (e) { - console.log('error decoding stdout json', e); } }); - serverProcess.stderr.on('data', (data: Buffer) => { + serverProcess.stderr?.on('data', (data: Buffer) => { console.log(`server-stderr: \n${data}`); publishServerStderr(data.toString()); }); diff --git a/app/src/core/ffmpeg.ts b/app/src/core/ffmpeg.ts index 34baa42e..652c6eda 100644 --- a/app/src/core/ffmpeg.ts +++ b/app/src/core/ffmpeg.ts @@ -8,7 +8,7 @@ import { player } from './player'; import { WebVtt } from '@audapolis/webvtt-writer'; const { FFmpegCommand, FFmpegInput, FFmpegOutput, FilterNode, FilterChain } = Fessonia({ - ffmpeg_bin: ffmpegPath, + ffmpeg_bin: ffmpegPath.replace('app.asar', 'app.asar.unpacked'), }); export function getSubtitleCodec(outputPath: string): string { @@ -166,7 +166,7 @@ async function runFfmpegWithProgress( cmd: Fessonia.FFmpegCommand, onTimeProgress: ProgressCallback ) { - console.debug('ffmpeg commandline: ', getFfmpegComandLine(cmd)); + console.debug('ffmpeg commandline: ', cmd.toString()); cmd.on('update', (data: { out_time_ms: number }) => { onTimeProgress(data.out_time_ms / 1000); }); @@ -270,6 +270,7 @@ export async function convertToWav( cmd.on('success', resolve); cmd.on('error', reject); }); + console.log('running ffmpeg', cmd.toString()); cmd.spawn(true); console.log('ffmpeg result', await promise); @@ -292,17 +293,6 @@ export async function copyToMp4(input_path: string): Promise { return fileData; } -function getFfmpegComandLine(cmd: Fessonia.FFmpegCommand) { - return ( - cmd.toCommand().command + - ' ' + - cmd - .toCommand() - .args.map((x) => `'${x}'`) - .join(' ') - ); -} - function getTempDir(): Promise { return new Promise(function (resolve, reject) { const cacheDir = new AppDirectory({