Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Enable asar #448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config = {
output: 'dist',
buildResources: './assets/',
},
files: ['build/**'],
files: ['build/**', './server/**', './generated/**'],
extraMetadata: {
version: getVersion(),
},
Expand Down Expand Up @@ -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;
32 changes: 19 additions & 13 deletions app/main_process/server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 },
});
}
Expand All @@ -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());
});
Expand Down
16 changes: 3 additions & 13 deletions app/src/core/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);

Expand All @@ -292,17 +293,6 @@ export async function copyToMp4(input_path: string): Promise<Buffer> {
return fileData;
}

function getFfmpegComandLine(cmd: Fessonia.FFmpegCommand) {
return (
cmd.toCommand().command +
' ' +
cmd
.toCommand()
.args.map((x) => `'${x}'`)
.join(' ')
);
}

function getTempDir(): Promise<string> {
return new Promise(function (resolve, reject) {
const cacheDir = new AppDirectory({
Expand Down