Show save/execution error dialogs on desktop #264
This commit introduces system-native error dialogs on desktop application for code save or execution failures, addressing user confusion described in issue #264. This commit adds informative feedback when script execution or saving fails. Changes: - Implement support for system-native error dialogs. - Refactor `CodeRunner` and `Dialog` interfaces and their implementations to improve error handling and provide better type safety. - Introduce structured error handling, allowing UI to display detailed error messages. - Replace error throwing with an error object interface for controlled handling. This ensures that errors are propagated to the renderer process without being limited by Electron's error object serialization limitations as detailed in electron/electron#24427. - Add logging for dialog actions to aid in troubleshooting. - Rename `fileName` to `defaultFilename` in `saveFile` functions to clarify its purpose. - Centralize message assertion in `LoggerStub` for consistency. - Introduce `expectTrue` in tests for clearer boolean assertions. - Standardize `filename` usage across the codebase. - Enhance existing test names and organization for clarity. - Update related documentation.
This commit is contained in:
@@ -1,8 +1,25 @@
|
||||
import { RuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/RuntimeEnvironment';
|
||||
import { Dialog } from '@/presentation/common/Dialog';
|
||||
import { BrowserDialog } from '@/infrastructure/Dialog/Browser/BrowserDialog';
|
||||
import { decorateWithLogging } from '@/infrastructure/Dialog/LoggingDialogDecorator';
|
||||
import { ClientLoggerFactory } from '../Log/ClientLoggerFactory';
|
||||
|
||||
export function determineDialogBasedOnEnvironment(
|
||||
export function createEnvironmentSpecificLoggedDialog(
|
||||
environment: RuntimeEnvironment,
|
||||
dialogLoggingDecorator: DialogLoggingDecorator = ClientLoggingDecorator,
|
||||
windowInjectedDialogFactory: WindowDialogCreationFunction = () => globalThis.window.dialog,
|
||||
browserDialogFactory: BrowserDialogCreationFunction = () => new BrowserDialog(),
|
||||
): Dialog {
|
||||
const dialog = determineDialogBasedOnEnvironment(
|
||||
environment,
|
||||
windowInjectedDialogFactory,
|
||||
browserDialogFactory,
|
||||
);
|
||||
const loggingDialog = dialogLoggingDecorator(dialog);
|
||||
return loggingDialog;
|
||||
}
|
||||
|
||||
function determineDialogBasedOnEnvironment(
|
||||
environment: RuntimeEnvironment,
|
||||
windowInjectedDialogFactory: WindowDialogCreationFunction = () => globalThis.window.dialog,
|
||||
browserDialogFactory: BrowserDialogCreationFunction = () => new BrowserDialog(),
|
||||
@@ -10,16 +27,23 @@ export function determineDialogBasedOnEnvironment(
|
||||
if (!environment.isRunningAsDesktopApplication) {
|
||||
return browserDialogFactory();
|
||||
}
|
||||
const dialog = windowInjectedDialogFactory();
|
||||
if (!dialog) {
|
||||
const windowDialog = windowInjectedDialogFactory();
|
||||
if (!windowDialog) {
|
||||
throw new Error([
|
||||
'The Dialog API could not be retrieved from the window object.',
|
||||
'Failed to retrieve Dialog API from window object in desktop environment.',
|
||||
'This may indicate that the Dialog API is either not implemented or not correctly exposed in the current desktop environment.',
|
||||
].join('\n'));
|
||||
}
|
||||
return dialog;
|
||||
return windowDialog;
|
||||
}
|
||||
|
||||
export type WindowDialogCreationFunction = () => Dialog | undefined;
|
||||
|
||||
export type BrowserDialogCreationFunction = () => Dialog;
|
||||
|
||||
export type DialogLoggingDecorator = (dialog: Dialog) => Dialog;
|
||||
|
||||
const ClientLoggingDecorator: DialogLoggingDecorator = (dialog) => decorateWithLogging(
|
||||
dialog,
|
||||
ClientLoggerFactory.Current.logger,
|
||||
);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Dialog } from '@/presentation/common/Dialog';
|
||||
import { CurrentEnvironment } from '@/infrastructure/RuntimeEnvironment/RuntimeEnvironmentFactory';
|
||||
import { determineDialogBasedOnEnvironment } from './ClientDialogFactory';
|
||||
import { createEnvironmentSpecificLoggedDialog } from './ClientDialogFactory';
|
||||
|
||||
export function useDialog(
|
||||
factory: DialogFactory = () => determineDialogBasedOnEnvironment(CurrentEnvironment),
|
||||
factory: DialogFactory = () => createEnvironmentSpecificLoggedDialog(CurrentEnvironment),
|
||||
) {
|
||||
const dialog = factory();
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user