Fix script deletion during execution on desktop
This commit fixes an issue seen on certain Windows environments (Windows 10 22H2 and 11 23H2 Pro Azure VMs) where scripts were being deleted during execution due to temporary directory usage. To resolve this, scripts are now stored in a persistent directory, enhancing reliability for long-running scripts and improving auditability along with troubleshooting. Key changes: - Move script execution logic to the `main` process from `preloader` to utilize Electron's `app.getPath`. - Improve runtime environment detection for non-browser environments to allow its usage in Electron main process. - Introduce a secure module to expose IPC channels from the main process to the renderer via the preloader process. Supporting refactorings include: - Simplify `CodeRunner` interface by removing the `tempScriptFolderName` parameter. - Rename `NodeSystemOperations` to `NodeElectronSystemOperations` as it now wraps electron APIs too, and convert it to class for simplicity. - Rename `TemporaryFileCodeRunner` to `ScriptFileCodeRunner` to reflect its new functinoality. - Rename `SystemOperations` folder to `System` for simplicity. - Rename `HostRuntimeEnvironment` to `BrowserRuntimeEnvironment` for clarity. - Refactor main Electron process configuration to align with latest Electron documentation/recommendations. - Refactor unit tests `BrowserRuntimeEnvironment` to simplify singleton workaround. - Use alias imports like `electron/main` and `electron/common` for better clarity.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { contextBridge } from 'electron';
|
||||
import { contextBridge } from 'electron/renderer';
|
||||
import { bindObjectMethods } from './MethodContextBinder';
|
||||
import { provideWindowVariables } from './RendererApiProvider';
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export function convertPlatformToOs(platform: NodeJS.Platform): OperatingSystem | undefined {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return OperatingSystem.macOS;
|
||||
case 'win32':
|
||||
return OperatingSystem.Windows;
|
||||
case 'linux':
|
||||
return OperatingSystem.Linux;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
14
src/presentation/electron/preload/ContextBridging/README.md
Normal file
14
src/presentation/electron/preload/ContextBridging/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Context Bridging Module
|
||||
|
||||
This module establishes secure, maintainable, and efficient inter-process communication between the preloader
|
||||
and renderer processes.
|
||||
|
||||
## Benefits
|
||||
|
||||
- **Security**: Exposes intended parts of an object to the renderer process, safeguarding the application's
|
||||
integrity and security.
|
||||
- **Type Safety and Maintainability**: Offers type-checked contracts for robust and easy-to-maintain code.
|
||||
- **Simplicity**: Streamlines the process of exposing APIs to the renderer process, minimizing the complexity
|
||||
of context bindings.
|
||||
- **Scalability**: Enhances the scalability of API exposure and simplifies managing more complex API structures,
|
||||
overcoming the limitations of ad-hoc approaches.
|
||||
@@ -1,27 +1,27 @@
|
||||
import { createElectronLogger } from '@/infrastructure/Log/ElectronLogger';
|
||||
import { Logger } from '@/application/Common/Log/Logger';
|
||||
import { WindowVariables } from '@/infrastructure/WindowVariables/WindowVariables';
|
||||
import { TemporaryFileCodeRunner } from '@/infrastructure/CodeRunner/TemporaryFileCodeRunner';
|
||||
import { CodeRunner } from '@/application/CodeRunner';
|
||||
import { convertPlatformToOs } from './NodeOsMapper';
|
||||
import { convertPlatformToOs } from '@/infrastructure/RuntimeEnvironment/Node/NodeOsMapper';
|
||||
import { createIpcConsumerProxy } from '../../shared/IpcBridging/IpcProxy';
|
||||
import { IpcChannelDefinitions } from '../../shared/IpcBridging/IpcChannelDefinitions';
|
||||
import { createSecureFacade } from './SecureFacadeCreator';
|
||||
|
||||
export function provideWindowVariables(
|
||||
createCodeRunner: CodeRunnerFactory = () => new TemporaryFileCodeRunner(),
|
||||
createLogger: LoggerFactory = () => createElectronLogger(),
|
||||
convertToOs = convertPlatformToOs,
|
||||
createApiFacade: ApiFacadeFactory = createSecureFacade,
|
||||
ipcConsumerCreator: IpcConsumerProxyCreator = createIpcConsumerProxy,
|
||||
): WindowVariables {
|
||||
return {
|
||||
isDesktop: true,
|
||||
log: createApiFacade(createLogger(), ['info', 'debug', 'warn', 'error']),
|
||||
os: convertToOs(process.platform),
|
||||
codeRunner: createApiFacade(createCodeRunner(), ['runCode']),
|
||||
codeRunner: ipcConsumerCreator(IpcChannelDefinitions.CodeRunner),
|
||||
};
|
||||
}
|
||||
|
||||
export type LoggerFactory = () => Logger;
|
||||
|
||||
export type CodeRunnerFactory = () => CodeRunner;
|
||||
|
||||
export type ApiFacadeFactory = typeof createSecureFacade;
|
||||
|
||||
export type IpcConsumerProxyCreator = typeof createIpcConsumerProxy;
|
||||
|
||||
Reference in New Issue
Block a user