Skip to content

Commit

Permalink
v1.1.54 ( v2.0 pre-release ) (#45)
Browse files Browse the repository at this point in the history
* error fix attempting

* error fix display correct

* open dir added

* open folder, open file, remove renders list copy line, improve renders list style

* image row table fixes: expected checkbox behavior, fixed incorrect color gen, audio table: create start elngth if duration is filled in, renders table: fixed delete render behavior

* 1.1.54
  • Loading branch information
MartinBarker authored Feb 11, 2025
1 parent 64a6636 commit 1272ce5
Show file tree
Hide file tree
Showing 7 changed files with 543 additions and 169 deletions.
124 changes: 103 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { app, BrowserWindow, ipcMain, protocol, session, dialog, Menu } from 'electron';
import { nativeImage } from 'electron';
import { app, BrowserWindow, ipcMain, protocol, session, dialog, Menu, shell } from 'electron';
import { nativeImage } from 'electron';
import { execa } from 'execa';
import pkg from 'electron-updater';
import path from 'path';
Expand Down Expand Up @@ -35,7 +35,12 @@ console.log(`Thumbnail cache directory is set to: ${thumbnailCacheDir}`);
const thumbnailMapPath = path.join(thumbnailCacheDir, 'thumbnails.json');
let thumbnailMap = {};
if (fs.existsSync(thumbnailMapPath)) {
thumbnailMap = JSON.parse(fs.readFileSync(thumbnailMapPath, 'utf-8'));
try {
thumbnailMap = JSON.parse(fs.readFileSync(thumbnailMapPath, 'utf-8'));
} catch (error) {
console.error('Error parsing thumbnails.json:', error);
thumbnailMap = {}; // Reset to an empty object if parsing fails
}
}

function saveThumbnailMap() {
Expand Down Expand Up @@ -219,33 +224,32 @@ ipcMain.on('run-ffmpeg-command', async (event, ffmpegArgs) => {
var duration = parseInt(ffmpegArgs.outputDuration, 10);
var renderId = ffmpegArgs.renderId;
console.log('Received FFmpeg command:', cmdArgsList);
console.log('duration:', duration);
console.log('Duration:', duration);

const ffmpegPath = getFfmpegPath();
console.log('Using FFmpeg path:', ffmpegPath);
if (!app.isPackaged) {
//logStream.write(`FFmpeg command: ${ffmpegPath} ${cmdArgsList.join(' ')}\n`);
}

const process = execa(ffmpegPath, cmdArgsList);
ffmpegProcesses.set(renderId, process); // Store the process

const rl = readline.createInterface({ input: process.stderr });

let progress = 0;
const outputBuffer = [];
let errorBuffer = []; // Store all stderr lines

rl.on('line', (line) => {
if (!app.isPackaged) {
console.log('FFmpeg output:', line);
//logStream.write('FFmpeg output: ' + line + '\n');
console.log('~~~~~~~ FFmpeg output:\n', line, '\n~~~~~~~\n');
}

outputBuffer.push(line);
if (outputBuffer.length > 10) {
outputBuffer.shift(); // Keep only the last 10 lines
// Store full FFmpeg stderr logs
errorBuffer.push(line);
if (errorBuffer.length > 100) {
errorBuffer.shift(); // Keep the last 100 lines to avoid memory overflow
}
const match = line.match(/time=([\d:.]+)/);

// Extract progress updates
let match = line.match(/time=([\d:.]+)/);
if (match) {
const elapsed = match[1].split(':').reduce((acc, time) => (60 * acc) + +time, 0);
progress = duration ? Math.min((elapsed / duration) * 100, 100) : 0;
Expand All @@ -260,27 +264,65 @@ ipcMain.on('run-ffmpeg-command', async (event, ffmpegArgs) => {

process.on('exit', (code, signal) => {
if (signal === 'SIGTERM') {
console.log("!! ffmpeg exit SIGTERM !!");
console.log(`FFmpeg process with ID: ${renderId} was stopped by user`);
event.reply('ffmpeg-stop-response', { renderId, status: 'Stopped' });
} else if (code === 0) {
ffmpegProcesses.delete(renderId); // Remove the process when done
event.reply('ffmpeg-output', { stdout: process.stdout, progress: 100 });
} else {
const errorOutput = process.stderr ? process.stderr.toString().split('\n').slice(-10).join('\n') : 'No error details';
event.reply('ffmpeg-error', { message: `FFmpeg exited with code ${code}`, lastOutput: errorOutput, ffmpegPath: getFfmpegPath() });
console.log(`!! ffmpeg unexpected exit, signal = ${signal} `);

// Extract key FFmpeg error details
const relevantError = extractRelevantError(errorBuffer);

event.reply('ffmpeg-error', {
message: `FFmpeg exited with code ${code}`,
lastOutput: relevantError,
fullErrorLog: errorBuffer.join('\n') // Send full stderr log for debugging
});
}
});

} catch (error) {
console.error('FFmpeg command failed:', error.message);
if (!app.isPackaged) {
//logStream.write('error.message: ' + error.message + '\n');
}
const errorOutput = error.stderr ? error.stderr.toString().split('\n').slice(-10).join('\n') : 'No error details';
event.reply('ffmpeg-error', { message: error.message, lastOutput: errorOutput, ffmpegPath: getFfmpegPath() });
const errorOutput = error.stderr ? error.stderr.toString().split('\n') : ['No error details'];
const relevantError = extractRelevantError(errorOutput);

event.reply('ffmpeg-error', {
message: error.message,
lastOutput: relevantError,
fullErrorLog: errorOutput.join('\n') // Send full stderr log for debugging
});
}
});

// Function to extract the most relevant FFmpeg error messages
function extractRelevantError(errorLines) {
const relevantLines = [];
let captureNext = false;
let capturedLines = 0;

for (let i = errorLines.length - 1; i >= 0; i--) {
const line = errorLines[i];

// Start capturing when we detect an error
if (line.includes('Error') || line.includes('Failed') || line.includes('Invalid') || line.includes('Could not')) {
captureNext = true;
}

// Include a few lines before the error for context
if (captureNext && capturedLines < 10) {
relevantLines.unshift(line);
capturedLines++;
}
}

return relevantLines.length ? relevantLines.join('\n') : "Unknown FFmpeg error occurred.";
}



ipcMain.on('stop-ffmpeg-render', (event, { renderId }) => {
console.log(`Received request to stop FFmpeg render with ID: ${renderId}`);
const process = ffmpegProcesses.get(renderId);
Expand Down Expand Up @@ -474,3 +516,43 @@ ipcMain.on('unmaximize-window', function () {
mainWindow.unmaximize();
}
});

//open directory
ipcMain.on('open-dir', async (event, folderPath) => {
try {
if (folderPath) {
console.log('Opening directory:', folderPath);
shell.showItemInFolder(folderPath);
} else {
console.error('Error: folderPath is undefined');
}
} catch (error) {
console.error('Error opening directory:', error);
}
});

//open file with default application
ipcMain.on('open-file', async (event, filepath) => {
try {
console.log('Opening file:', filepath);
shell.openPath(filepath);
} catch (error) {
console.error('Error opening file:', error);
}
});

ipcMain.on('delete-file', async (event, filePath) => {
try {
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
console.log(`Deleted file: ${filePath}`);
event.reply('delete-file-response', { success: true, filePath });
} else {
console.log(`File not found: ${filePath}`);
event.reply('delete-file-response', { success: false, error: 'File not found' });
}
} catch (error) {
console.error(`Error deleting file: ${filePath}`, error);
event.reply('delete-file-response', { success: false, error: error.message });
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "RenderTune",
"version": "1.1.52",
"version": "1.1.54",
"description": "My Electron app",
"type": "module",
"main": "main.js",
Expand Down
5 changes: 4 additions & 1 deletion preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ contextBridge.exposeInMainWorld('api', {
'get-audio-metadata',
'open-file-dialog',
'open-folder-dialog',
'open-dir',
'open-file',
'get-path-separator',
'set-output-folder',
'get-color-palette',
'stop-ffmpeg-render',
'delete-render-file'
'delete-render-file',
'delete-file'
];
if (validSendChannels.includes(channel)) {
ipcRenderer.send(channel, data);
Expand Down
Loading

0 comments on commit 1272ce5

Please sign in to comment.