style(electron): more ui bug fixes

This commit is contained in:
2025-08-10 14:06:50 -04:00
parent 875be6a43c
commit c7a6756453
8 changed files with 1157 additions and 56 deletions

View File

@@ -7,6 +7,7 @@ if (require('electron-squirrel-startup')) {
}
let mainWindow;
let themeUpdateListener;
const createWindow = () => {
// Create the browser window.
@@ -29,10 +30,34 @@ const createWindow = () => {
// Open the DevTools for debugging
// mainWindow.webContents.openDevTools();
nativeTheme.on('updated', () => {
if (mainWindow) {
mainWindow.webContents.send('theme-updated', { shouldUseDarkColors: nativeTheme.shouldUseDarkColors });
// Clean up any existing theme listener
if (themeUpdateListener) {
nativeTheme.removeListener('updated', themeUpdateListener);
}
// Create new theme listener with proper safety checks
themeUpdateListener = () => {
if (mainWindow && !mainWindow.isDestroyed() && mainWindow.webContents) {
try {
mainWindow.webContents.send('theme-updated', { shouldUseDarkColors: nativeTheme.shouldUseDarkColors });
} catch (error) {
console.warn('Failed to send theme update:', error.message);
// Remove the listener if sending fails
nativeTheme.removeListener('updated', themeUpdateListener);
themeUpdateListener = null;
}
}
};
nativeTheme.on('updated', themeUpdateListener);
// Clean up when window is closed
mainWindow.on('closed', () => {
if (themeUpdateListener) {
nativeTheme.removeListener('updated', themeUpdateListener);
themeUpdateListener = null;
}
mainWindow = null;
});
};

View File

@@ -22,8 +22,52 @@ function runPythonCommand(command, kwargs, event) {
let errorOutput = '';
process.stderr.on('data', (data) => {
errorOutput += data.toString();
console.error('Backend STDERR:', data.toString().trim());
const stderrChunk = data.toString();
errorOutput += stderrChunk;
console.error('Backend STDERR:', stderrChunk.trim());
// For fill_bundle, forward stderr to frontend for terminal display
if (isStreaming && event && command === 'fill_bundle') {
// Parse stderr lines and send them as progress updates
const lines = stderrChunk.split('\n').filter(line => line.trim());
lines.forEach(line => {
const trimmedLine = line.trim();
// Check if this is a structured progress message
if (trimmedLine.startsWith('[PROGRESS] {')) {
try {
// Extract JSON from [PROGRESS] prefix
const jsonStr = trimmedLine.substring('[PROGRESS] '.length);
const progressData = JSON.parse(jsonStr);
console.log(`[MAIN_PROCESS] Parsed progress data:`, progressData);
// Send as proper progress update
event.sender.send('fill-bundle-progress', progressData);
} catch (e) {
console.error(`[MAIN_PROCESS] Failed to parse progress JSON: ${trimmedLine}`, e);
// Fallback to stderr if JSON parsing fails
event.sender.send('fill-bundle-progress', {
type: 'stderr',
stderr: trimmedLine
});
}
} else {
// Only skip very specific system messages, include everything else as stderr
const shouldSkip = trimmedLine.includes('[BRIDGE_INFO]') ||
trimmedLine.includes('--- Python backend bridge') ||
trimmedLine.startsWith('[PROGRESS]') || // Skip non-JSON progress messages
trimmedLine === '';
if (!shouldSkip) {
console.log(`[MAIN_PROCESS] Forwarding stderr to frontend: ${trimmedLine}`);
event.sender.send('fill-bundle-progress', {
type: 'stderr',
stderr: trimmedLine
});
}
}
});
}
});
const isStreaming = command === 'fill_bundle';

View File

@@ -1,6 +1,7 @@
const { ipcMain, dialog } = require('electron');
const { ipcMain, dialog, shell } = require('electron');
const { runPythonCommand } = require('./backend-bridge');
const fs = require('fs-extra');
const path = require('path');
const setupBundleIPCHandlers = () => {
// Create bundle handler
@@ -121,6 +122,52 @@ const setupBundleIPCHandlers = () => {
return { success: false, error: error.message };
}
});
// Read license file handler
ipcMain.handle('read-license', async () => {
try {
const licensePath = path.join(__dirname, '..', 'LICENSE.txt');
console.log(`[IPC_HANDLER] Reading license from: ${licensePath}`);
// Check if file exists
const exists = await fs.pathExists(licensePath);
console.log(`[IPC_HANDLER] License file exists: ${exists}`);
if (!exists) {
return {
success: false,
error: 'License file not found',
content: `License file not found at: ${licensePath}`
};
}
const licenseContent = await fs.readFile(licensePath, 'utf8');
console.log(`[IPC_HANDLER] License content length: ${licenseContent.length} characters`);
console.log(`[IPC_HANDLER] License starts with: "${licenseContent.substring(0, 100)}..."`);
console.log(`[IPC_HANDLER] License ends with: "...${licenseContent.substring(licenseContent.length - 100)}"`);
return { success: true, content: licenseContent };
} catch (error) {
console.error('Failed to read LICENSE.txt:', error);
return {
success: false,
error: 'Could not load license file',
content: 'GPL v3 license text could not be loaded. Please check that LICENSE.txt exists in the application directory.'
};
}
});
// Open external URL handler
ipcMain.handle('open-external-url', async (event, url) => {
try {
console.log(`[IPC_HANDLER] Opening external URL: ${url}`);
await shell.openExternal(url);
return { success: true };
} catch (error) {
console.error('Failed to open external URL:', error);
return { success: false, error: error.message };
}
});
};
module.exports = {