From b42e6c659a8f6211263b6fb840bfea442c389c06 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 1 Feb 2024 15:22:29 +1100 Subject: [PATCH] fix: fix crash on password window opening --- ts/components/SessionPasswordPrompt.tsx | 27 ++++++++++++++++------- ts/mains/main_node.ts | 29 +++++++++++++------------ ts/node/locale.ts | 5 ++++- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/ts/components/SessionPasswordPrompt.tsx b/ts/components/SessionPasswordPrompt.tsx index 055fc9aeb..929db35c8 100644 --- a/ts/components/SessionPasswordPrompt.tsx +++ b/ts/components/SessionPasswordPrompt.tsx @@ -1,17 +1,19 @@ -import React, { useEffect } from 'react'; -import classNames from 'classnames'; -import styled from 'styled-components'; import autoBind from 'auto-bind'; +import classNames from 'classnames'; import { isString } from 'lodash'; +import React, { useEffect } from 'react'; +import { toast } from 'react-toastify'; +import styled from 'styled-components'; import { SessionButton, SessionButtonColor, SessionButtonType } from './basic/SessionButton'; -import { SessionSpinner } from './basic/SessionSpinner'; +// import { SessionSpinner } from './basic/SessionSpinner'; import { SessionTheme } from '../themes/SessionTheme'; +import { switchPrimaryColorTo } from '../themes/switchPrimaryColor'; import { switchThemeTo } from '../themes/switchTheme'; -import { ToastUtils } from '../session/utils'; import { SessionToastContainer } from './SessionToastContainer'; import { SessionWrapperModal } from './SessionWrapperModal'; -import { switchPrimaryColorTo } from '../themes/switchPrimaryColor'; +import { SessionSpinner } from './basic/SessionSpinner'; +import { SessionToast } from './basic/SessionToast'; interface State { errorCount: number; @@ -34,6 +36,15 @@ const StyledContent = styled.div` width: 100%; `; +// We cannot import toastutils from the password window as it is pulling the whole sending +// pipeline(and causing crashes on Session instances with password) +function pushToastError(id: string, title: string, description?: string) { + toast.error(, { + toastId: id, + updateId: id, + }); +} + class SessionPasswordPromptInner extends React.PureComponent { private inputRef?: any; @@ -112,9 +123,9 @@ class SessionPasswordPromptInner extends React.PureComponent { }); if (error && isString(error)) { - ToastUtils.pushToastError('onLogin', error); + pushToastError('onLogin', error); } else if (error?.message && isString(error.message)) { - ToastUtils.pushToastError('onLogin', error.message); + pushToastError('onLogin', error.message); } global.setTimeout(() => { diff --git a/ts/mains/main_node.ts b/ts/mains/main_node.ts index 5c531c9f3..cf4f34122 100644 --- a/ts/mains/main_node.ts +++ b/ts/mains/main_node.ts @@ -8,33 +8,33 @@ import { app, BrowserWindow, dialog, + protocol as electronProtocol, ipcMain as ipc, Menu, nativeTheme, - protocol as electronProtocol, screen, shell, systemPreferences, } from 'electron'; +import crypto from 'crypto'; +import fs from 'fs'; +import os from 'os'; import path, { join } from 'path'; import { platform as osPlatform } from 'process'; import url from 'url'; -import os from 'os'; -import fs from 'fs'; -import crypto from 'crypto'; +import Logger from 'bunyan'; import _, { isEmpty } from 'lodash'; import pify from 'pify'; -import Logger from 'bunyan'; -import { setup as setupSpellChecker } from '../node/spell_check'; // checked - only node import { setupGlobalErrorHandler } from '../node/global_errors'; // checked - only node +import { setup as setupSpellChecker } from '../node/spell_check'; // checked - only node +import electronLocalshortcut from 'electron-localshortcut'; import packageJson from '../../package.json'; // checked - only node setupGlobalErrorHandler(); -import electronLocalshortcut from 'electron-localshortcut'; const getRealPath = pify(fs.realpath); @@ -75,15 +75,15 @@ import { initAttachmentsChannel } from '../node/attachment_channel'; import * as updater from '../updater/index'; // checked - only node -import { createTrayIcon } from '../node/tray_icon'; // checked - only node import { ephemeralConfig } from '../node/config/ephemeral_config'; // checked - only node import { getLogger, initializeLogger } from '../node/logging'; // checked - only node +import { createTemplate } from '../node/menu'; // checked - only node +import { installPermissionsHandler } from '../node/permissions'; // checked - only node +import { installFileHandler, installWebHandler } from '../node/protocol_filter'; // checked - only node import { sqlNode } from '../node/sql'; // checked - only node import * as sqlChannels from '../node/sql_channel'; // checked - only node +import { createTrayIcon } from '../node/tray_icon'; // checked - only node import { windowMarkShouldQuit, windowShouldQuit } from '../node/window_state'; // checked - only node -import { createTemplate } from '../node/menu'; // checked - only node -import { installFileHandler, installWebHandler } from '../node/protocol_filter'; // checked - only node -import { installPermissionsHandler } from '../node/permissions'; // checked - only node let appStartInitialSpellcheckSetting = true; @@ -156,9 +156,9 @@ if (windowFromUserConfig) { } // import {load as loadLocale} from '../..' -import { load as loadLocale, LocaleMessagesWithNameType } from '../node/locale'; -import { setLastestRelease } from '../node/latest_desktop_release'; import { getAppRootPath } from '../node/getRootPath'; +import { setLastestRelease } from '../node/latest_desktop_release'; +import { load as loadLocale, LocaleMessagesWithNameType } from '../node/locale'; import { classicDark } from '../themes'; // Both of these will be set after app fires the 'ready' event @@ -757,13 +757,14 @@ app.on('ready', async () => { } const key = getDefaultSQLKey(); - // Try to show the main window with the default key // If that fails then show the password window const dbHasPassword = userConfig.get('dbHasPassword'); if (dbHasPassword) { + assertLogger().info('showing password window'); await showPasswordWindow(); } else { + assertLogger().info('showing main window'); await showMainWindow(key); } }); diff --git a/ts/node/locale.ts b/ts/node/locale.ts index 89ec89ab9..8737eed3b 100644 --- a/ts/node/locale.ts +++ b/ts/node/locale.ts @@ -1,12 +1,15 @@ -import path from 'path'; import fs from 'fs'; import _ from 'lodash'; +import path from 'path'; import { getAppRootPath } from './getRootPath'; function normalizeLocaleName(locale: string) { if (/^en-/.test(locale)) { return 'en'; } + if (/^en_/.test(locale)) { + return 'en'; + } return locale; }