Merge and migrate locally-trusted preload scripts to contextBridge API (#2553)

* Migrate intl_provider to contextBridge

* Migrate modalPreload to contextBridge

* Migrate loadingScreenPreload to contextBridge

* Migrate downloadDropdown preloads to contextBridge

* Migrate server dropdown preload to contextBridge

* Migrate urlView preload to contextBridge

* Merge all desktop API scripts into one

* Remove unused communication channel constants
This commit is contained in:
Devin Binnie
2023-02-15 13:42:53 -05:00
committed by GitHub
parent 1c0aeae118
commit 5cc2e98a1d
44 changed files with 438 additions and 821 deletions

View File

@@ -5,27 +5,21 @@ import React from 'react';
import {Modal, Button} from 'react-bootstrap';
import {FormattedMessage, injectIntl, IntlShape} from 'react-intl';
import {PermissionType} from 'types/trustedOrigin';
import {ModalMessage} from 'types/modals';
import {PermissionModalInfo} from 'types/modals';
import urlUtil from 'common/utils/url';
import {t} from 'common/utils/util';
import {MODAL_INFO} from 'common/communication';
import {PERMISSION_DESCRIPTION} from 'common/permissions';
type Props = {
handleDeny: React.MouseEventHandler<HTMLButtonElement>;
handleGrant: React.MouseEventHandler<HTMLButtonElement>;
getPermissionInfo: () => void;
getPermissionInfo: () => Promise<PermissionModalInfo>;
openExternalLink: (protocol: string, url: string) => void;
intl: IntlShape;
};
type State = {
url?: string;
permission?: PermissionType;
}
type State = Partial<PermissionModalInfo>;
class PermissionModal extends React.PureComponent<Props, State> {
constructor(props: Props) {
@@ -33,26 +27,13 @@ class PermissionModal extends React.PureComponent<Props, State> {
this.state = {};
}
componentDidMount() {
window.addEventListener('message', this.handlePermissionInfoMessage);
this.props.getPermissionInfo();
getPermissionInfo = async () => {
const {url, permission} = await this.props.getPermissionInfo();
this.setState({url, permission});
}
componentWillUnmount() {
window.removeEventListener('message', this.handlePermissionInfoMessage);
}
handlePermissionInfoMessage = (event: {data: ModalMessage<{url: string; permission: PermissionType}>}) => {
switch (event.data.type) {
case MODAL_INFO: {
const {url, permission} = event.data.data;
this.setState({url, permission});
break;
}
default:
break;
}
async componentDidMount() {
await this.getPermissionInfo();
}
getModalTitle() {