2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-06-17 21:15:09 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { MenuItemConstructorOptions } from 'electron';
|
2021-06-17 21:15:09 +00:00
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { MenuActionType } from '../../types/menu';
|
2021-08-31 20:58:39 +00:00
|
|
|
import { App } from '../../components/App';
|
2023-01-18 23:31:10 +00:00
|
|
|
import { getName as getOSName } from '../../OS';
|
2021-06-17 21:15:09 +00:00
|
|
|
import { SmartCallManager } from './CallManager';
|
|
|
|
import { SmartGlobalModalContainer } from './GlobalModalContainer';
|
2022-12-10 02:02:22 +00:00
|
|
|
import { SmartLightbox } from './Lightbox';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { SmartStories } from './Stories';
|
2022-07-06 19:06:20 +00:00
|
|
|
import { SmartStoryViewer } from './StoryViewer';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
2022-06-08 22:00:32 +00:00
|
|
|
import {
|
|
|
|
getIntl,
|
|
|
|
getLocaleMessages,
|
|
|
|
getTheme,
|
|
|
|
getIsMainWindowMaximized,
|
|
|
|
getIsMainWindowFullScreen,
|
|
|
|
getMenuOptions,
|
|
|
|
} from '../selectors/user';
|
2022-07-06 19:06:20 +00:00
|
|
|
import {
|
2022-07-29 20:22:55 +00:00
|
|
|
hasSelectedStoryData,
|
2022-07-06 19:06:20 +00:00
|
|
|
shouldShowStoriesView,
|
|
|
|
} from '../selectors/stories';
|
2022-06-20 18:26:31 +00:00
|
|
|
import { getHideMenuBar } from '../selectors/items';
|
2021-06-17 21:15:09 +00:00
|
|
|
import { mapDispatchToProps } from '../actions';
|
2022-07-29 00:10:07 +00:00
|
|
|
import { ErrorBoundary } from '../../components/ErrorBoundary';
|
2022-10-17 16:58:49 +00:00
|
|
|
import { ModalContainer } from '../../components/ModalContainer';
|
2023-01-02 21:34:41 +00:00
|
|
|
import { SmartInbox } from './Inbox';
|
|
|
|
|
|
|
|
function renderInbox(): JSX.Element {
|
|
|
|
return <SmartInbox />;
|
|
|
|
}
|
2021-06-17 21:15:09 +00:00
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
const mapStateToProps = (state: StateType) => {
|
2022-07-29 00:10:07 +00:00
|
|
|
const i18n = getIntl(state);
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
const { osName } = state.user;
|
|
|
|
|
|
|
|
let osClassName = '';
|
|
|
|
|
|
|
|
if (osName === 'windows') {
|
|
|
|
osClassName = 'os-windows';
|
|
|
|
} else if (osName === 'macos') {
|
|
|
|
osClassName = 'os-macos';
|
|
|
|
} else if (osName === 'linux') {
|
|
|
|
osClassName = 'os-linux';
|
|
|
|
}
|
|
|
|
|
2021-06-17 21:15:09 +00:00
|
|
|
return {
|
|
|
|
...state.app,
|
2022-07-29 00:10:07 +00:00
|
|
|
i18n,
|
2022-06-08 22:00:32 +00:00
|
|
|
localeMessages: getLocaleMessages(state),
|
|
|
|
isMaximized: getIsMainWindowMaximized(state),
|
|
|
|
isFullScreen: getIsMainWindowFullScreen(state),
|
|
|
|
menuOptions: getMenuOptions(state),
|
2022-07-05 16:44:53 +00:00
|
|
|
hasCustomTitleBar: window.SignalContext.OS.hasCustomTitleBar(),
|
2023-01-18 23:31:10 +00:00
|
|
|
OS: getOSName(),
|
2023-01-13 00:24:59 +00:00
|
|
|
osClassName,
|
2022-06-20 18:26:31 +00:00
|
|
|
hideMenuBar: getHideMenuBar(state),
|
2022-10-17 16:58:49 +00:00
|
|
|
renderCallManager: () => (
|
|
|
|
<ModalContainer className="module-calling__modal-container">
|
|
|
|
<SmartCallManager />
|
|
|
|
</ModalContainer>
|
|
|
|
),
|
2021-06-17 21:15:09 +00:00
|
|
|
renderGlobalModalContainer: () => <SmartGlobalModalContainer />,
|
2022-12-10 02:02:22 +00:00
|
|
|
renderLightbox: () => <SmartLightbox />,
|
2022-03-04 21:14:52 +00:00
|
|
|
isShowingStoriesView: shouldShowStoriesView(state),
|
2022-08-19 18:35:40 +00:00
|
|
|
renderStories: (closeView: () => unknown) => (
|
|
|
|
<ErrorBoundary name="App/renderStories" closeView={closeView}>
|
2022-07-29 00:10:07 +00:00
|
|
|
<SmartStories />
|
|
|
|
</ErrorBoundary>
|
|
|
|
),
|
2022-07-29 20:22:55 +00:00
|
|
|
hasSelectedStoryData: hasSelectedStoryData(state),
|
2022-08-19 18:35:40 +00:00
|
|
|
renderStoryViewer: (closeView: () => unknown) => (
|
|
|
|
<ErrorBoundary name="App/renderStoryViewer" closeView={closeView}>
|
2022-07-29 00:10:07 +00:00
|
|
|
<SmartStoryViewer />
|
|
|
|
</ErrorBoundary>
|
|
|
|
),
|
2023-01-02 21:34:41 +00:00
|
|
|
renderInbox,
|
2021-11-30 17:51:53 +00:00
|
|
|
requestVerification: (
|
|
|
|
type: 'sms' | 'voice',
|
|
|
|
number: string,
|
|
|
|
token: string
|
|
|
|
): Promise<void> => {
|
|
|
|
const accountManager = window.getAccountManager();
|
|
|
|
|
|
|
|
if (type === 'sms') {
|
|
|
|
return accountManager.requestSMSVerification(number, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
return accountManager.requestVoiceVerification(number, token);
|
|
|
|
},
|
|
|
|
registerSingleDevice: (number: string, code: string): Promise<void> => {
|
|
|
|
return window.getAccountManager().registerSingleDevice(number, code);
|
|
|
|
},
|
2021-06-17 21:15:09 +00:00
|
|
|
theme: getTheme(state),
|
2022-06-08 22:00:32 +00:00
|
|
|
|
|
|
|
executeMenuRole: (role: MenuItemConstructorOptions['role']): void => {
|
2022-12-21 18:41:48 +00:00
|
|
|
void window.SignalContext.executeMenuRole(role);
|
2022-06-08 22:00:32 +00:00
|
|
|
},
|
|
|
|
executeMenuAction: (action: MenuActionType): void => {
|
2022-12-21 18:41:48 +00:00
|
|
|
void window.SignalContext.executeMenuAction(action);
|
2022-06-08 22:00:32 +00:00
|
|
|
},
|
|
|
|
titleBarDoubleClick: (): void => {
|
2023-01-13 00:24:59 +00:00
|
|
|
window.IPC.titleBarDoubleClick();
|
2022-06-08 22:00:32 +00:00
|
|
|
},
|
2022-09-26 16:24:52 +00:00
|
|
|
toast: state.toast.toast,
|
2021-06-17 21:15:09 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export const SmartApp = smart(App);
|