feat(electron): added key managment ui
This commit is contained in:
@@ -10,16 +10,21 @@ function runPythonCommand(command, kwargs, event) {
|
||||
// Determine executable name based on platform
|
||||
const executableName = process.platform === 'win32' ? 'fourdst-backend.exe' : 'fourdst-backend';
|
||||
|
||||
// Initialize args first
|
||||
let args = [command, JSON.stringify(kwargs)];
|
||||
|
||||
if (app.isPackaged) {
|
||||
// In packaged app, backend is in resources/backend/ directory
|
||||
backendPath = path.join(process.resourcesPath, 'backend', executableName);
|
||||
} else {
|
||||
// In development, use the meson build output
|
||||
backendPath = path.join(buildDir, 'electron', 'dist', 'fourdst-backend', executableName);
|
||||
// In development, use the Python bridge.py directly for faster iteration
|
||||
backendPath = 'python';
|
||||
// Update args to include the bridge.py path as the first argument
|
||||
const bridgePath = path.join(__dirname, '..', 'bridge.py');
|
||||
args.unshift(bridgePath);
|
||||
}
|
||||
|
||||
console.log(`[MAIN_PROCESS] Spawning backend: ${backendPath}`);
|
||||
const args = [command, JSON.stringify(kwargs)];
|
||||
console.log(`[MAIN_PROCESS] With args: [${args.join(', ')}]`);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
@@ -29,6 +29,23 @@ const setupFileDialogHandlers = () => {
|
||||
return null;
|
||||
});
|
||||
|
||||
// Key file selection dialog
|
||||
ipcMain.handle('select-key-file', async () => {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openFile'],
|
||||
title: 'Select Public Key File',
|
||||
filters: [
|
||||
{ name: 'Public Key Files', extensions: ['pub', 'pem'] },
|
||||
{ name: 'All Files', extensions: ['*'] }
|
||||
]
|
||||
});
|
||||
|
||||
if (!result.canceled && result.filePaths.length > 0) {
|
||||
return result.filePaths[0];
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
// Save file dialog
|
||||
ipcMain.handle('select-save-file', async () => {
|
||||
const result = await dialog.showSaveDialog({
|
||||
|
||||
@@ -3,6 +3,69 @@ const { runPythonCommand } = require('./backend-bridge');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const setupKeyIPCHandlers = () => {
|
||||
// List keys handler
|
||||
ipcMain.handle('list-keys', async (event) => {
|
||||
const kwargs = {};
|
||||
return runPythonCommand('list_keys', kwargs, event);
|
||||
});
|
||||
|
||||
// Generate key handler
|
||||
ipcMain.handle('generate-key', async (event, { keyName, keyType, outputDir }) => {
|
||||
const kwargs = {
|
||||
key_name: keyName,
|
||||
key_type: keyType,
|
||||
output_dir: outputDir
|
||||
};
|
||||
return runPythonCommand('generate_key', kwargs, event);
|
||||
});
|
||||
|
||||
// Add key handler
|
||||
ipcMain.handle('add-key', async (event, keyPath) => {
|
||||
const kwargs = {
|
||||
key_path: keyPath
|
||||
};
|
||||
return runPythonCommand('add_key', kwargs, event);
|
||||
});
|
||||
|
||||
// Remove key handler
|
||||
ipcMain.handle('remove-key', async (event, keyIdentifier) => {
|
||||
const kwargs = {
|
||||
key_identifier: keyIdentifier
|
||||
};
|
||||
return runPythonCommand('remove_key', kwargs, event);
|
||||
});
|
||||
|
||||
// Sync remotes handler
|
||||
ipcMain.handle('sync-remotes', async (event) => {
|
||||
const kwargs = {};
|
||||
return runPythonCommand('sync_remotes', kwargs, event);
|
||||
});
|
||||
|
||||
// Get remote sources handler
|
||||
ipcMain.handle('get-remote-sources', async (event) => {
|
||||
const kwargs = {};
|
||||
return runPythonCommand('get_remote_sources', kwargs, event);
|
||||
});
|
||||
|
||||
// Add remote source handler
|
||||
ipcMain.handle('add-remote-source', async (event, { name, url }) => {
|
||||
const kwargs = {
|
||||
name: name,
|
||||
url: url
|
||||
};
|
||||
return runPythonCommand('add_remote_source', kwargs, event);
|
||||
});
|
||||
|
||||
// Remove remote source handler
|
||||
ipcMain.handle('remove-remote-source', async (event, name) => {
|
||||
const kwargs = {
|
||||
name: name
|
||||
};
|
||||
return runPythonCommand('remove_remote_source', kwargs, event);
|
||||
});
|
||||
};
|
||||
|
||||
const setupBundleIPCHandlers = () => {
|
||||
// Create bundle handler
|
||||
ipcMain.handle('create-bundle', async (event, bundleData) => {
|
||||
@@ -171,5 +234,6 @@ const setupBundleIPCHandlers = () => {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
setupBundleIPCHandlers
|
||||
setupBundleIPCHandlers,
|
||||
setupKeyIPCHandlers
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user