diff --git a/app/base_config.d.ts b/app/base_config.d.ts deleted file mode 100644 index 55c0a3614..000000000 --- a/app/base_config.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface BaseConfig { - set(keyPath: string, value: any): void; - get(keyPath: string): any | undefined; - remove(): void; -} - -interface Options { - allowMalformedOnStartup: boolean; -} - -export function start(name: string, targetPath: string, options: Options): BaseConfig; diff --git a/app/global_errors.js b/app/global_errors.js deleted file mode 100644 index 62ca5c713..000000000 --- a/app/global_errors.js +++ /dev/null @@ -1,50 +0,0 @@ -const electron = require('electron'); - -const { app, dialog, clipboard } = electron; -const { redactAll } = require('../ts/util/privacy'); - -// We use hard-coded strings until we're able to update these strings from the locale. -let quitText = 'Quit'; -let copyErrorAndQuitText = 'Copy error and quit'; - -function handleError(prefix, error) { - if (console._error) { - console._error(`${prefix}:`, error); - } - console.error(`${prefix}:`, error); - - if (app.isReady()) { - // title field is not shown on macOS, so we don't use it - const buttonIndex = dialog.showMessageBox({ - buttons: [quitText, copyErrorAndQuitText], - defaultId: 0, - detail: redactAll(error.stack), - message: prefix, - noLink: true, - type: 'error', - }); - - if (buttonIndex === 1) { - clipboard.writeText(`${prefix}\n\n${redactAll(error.stack)}`); - } - } else { - dialog.showErrorBox(prefix, error.stack); - } - - app.exit(1); -} - -exports.updateLocale = messages => { - quitText = messages.quit; - copyErrorAndQuitText = messages.copyErrorAndQuit; -}; - -exports.addHandler = () => { - process.on('uncaughtException', error => { - handleError('Unhandled Error', error); - }); - - process.on('unhandledRejection', error => { - handleError('Unhandled Promise Rejection', error); - }); -}; diff --git a/ts/node/global_errors.ts b/ts/node/global_errors.ts new file mode 100644 index 000000000..4be5d39ae --- /dev/null +++ b/ts/node/global_errors.ts @@ -0,0 +1,51 @@ +import { app, clipboard, dialog } from 'electron'; +import { redactAll } from '../util/privacy'; +import { LocaleMessagesType } from './locale'; +import { ConsoleCustom } from './logging'; +// tslint:disable: no-console + +// We use hard-coded strings until we're able to update these strings from the locale. +let quitText = 'Quit'; +let copyErrorAndQuitText = 'Copy error and quit'; + +async function handleError(prefix: string, error: any) { + if ((console as ConsoleCustom)._error) { + (console as ConsoleCustom)._error(`${prefix}:`, error); + } + console.error(`${prefix}:`, error); + + if (app.isReady()) { + // title field is not shown on macOS, so we don't use it + const button = await dialog.showMessageBox({ + buttons: [quitText, copyErrorAndQuitText], + defaultId: 0, + detail: redactAll(error.stack), + message: prefix, + noLink: true, + type: 'error', + }); + + if (button.response === 1) { + clipboard.writeText(`${prefix}\n\n${redactAll(error.stack)}`); + } + } else { + dialog.showErrorBox(prefix, error.stack); + } + + app.exit(1); +} + +export const updateLocale = (messages: LocaleMessagesType) => { + quitText = messages.quit; + copyErrorAndQuitText = messages.copyErrorAndQuit; +}; + +export const addHandler = () => { + process.on('uncaughtException', async error => { + await handleError('Unhandled Error', error); + }); + + process.on('unhandledRejection', async error => { + await handleError('Unhandled Promise Rejection', error); + }); +}; diff --git a/ts/node/logging.ts b/ts/node/logging.ts index 21c23d628..6a1fea6cd 100644 --- a/ts/node/logging.ts +++ b/ts/node/logging.ts @@ -18,7 +18,7 @@ let logger: Logger | undefined; // tslint:disable: non-literal-fs-path // tslint:disable: no-console -type ConsoleCustom = typeof console & { +export type ConsoleCustom = typeof console & { _log: (...args: any) => void; _warn: (...args: any) => void; _error: (...args: any) => void;