Show warning when opening files externally #2478
2 changed files with 86 additions and 0 deletions
12
src/ui/modal/modalOpenExternalResource/index.js
Normal file
12
src/ui/modal/modalOpenExternalResource/index.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { doHideModal } from 'redux/actions/app';
|
||||
import ModalOpenExternalResource from './view';
|
||||
|
||||
const perform = dispatch => ({
|
||||
closeModal: () => dispatch(doHideModal()),
|
||||
});
|
||||
|
||||
export default connect(
|
||||
null,
|
||||
perform
|
||||
)(ModalOpenExternalResource);
|
74
src/ui/modal/modalOpenExternalResource/view.jsx
Normal file
74
src/ui/modal/modalOpenExternalResource/view.jsx
Normal file
|
@ -0,0 +1,74 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import { Modal } from 'modal/modal';
|
||||
import { formatLbryUriForWeb } from 'util/uri';
|
||||
// @if TARGET='app'
|
||||
import { shell } from 'electron';
|
||||
// @endif
|
||||
|
||||
type Props = {
|
||||
uri: string,
|
||||
path: string,
|
||||
closeModal: () => void,
|
||||
};
|
||||
|
||||
class ModalOpenExternalResource extends React.PureComponent<Props> {
|
||||
openExternalResource() {
|
||||
const { uri, path, closeModal } = this.props;
|
||||
// @if TARGET='app'
|
||||
const { openExternal, openItem, showItemInFolder } = shell;
|
||||
if (uri) {
|
||||
openExternal(uri);
|
||||
} else if(path) {
|
||||
const success = openItem(path);
|
||||
if (!success) {
|
||||
showItemInFolder(path);
|
||||
}
|
||||
}
|
||||
// @endif
|
||||
// @if TARGET='web'
|
||||
if (uri) {
|
||||
window.open(uri);
|
||||
} else if (path) {
|
||||
// Converintg path into uri, like "file://path/to/file"
|
||||
let _uri = path.replace(/\\/g, '/');
|
||||
// Windows drive letter must be prefixed with a slash
|
||||
if (_uri[0] !== '/') {
|
||||
_uri = `/${_uri}`;
|
||||
}
|
||||
_uri = encodeURI(`file://${_uri}`).replace(/[?#]/g, encodeURIComponent);
|
||||
window.open(_uri);
|
||||
}
|
||||
// @endif
|
||||
|
||||
closeModal();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { uri, path, closeModal } = this.props;
|
||||
return (
|
||||
<Modal
|
||||
isOpen
|
||||
title={__('Warning!')}
|
||||
contentLabel={__('Confirm External Resource')}
|
||||
type="confirm"
|
||||
confirmButtonLabel={__('Continue')}
|
||||
onConfirmed={() => this.openExternalResource()}
|
||||
onAborted={closeModal}
|
||||
>
|
||||
<section className="card__content">
|
||||
<p>
|
||||
{
|
||||
(uri && __('This link leads to an external website.')) ||
|
||||
(path && __('This file has been shared with you by other people.'))
|
||||
}
|
||||
</p>
|
||||
<blockquote>{uri || path}</blockquote>
|
||||
<p>{__('LBRY Inc is not responsible for its content, click continue to proceed at your own risk.')}</p>
|
||||
</section>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ModalOpenExternalResource;
|
Loading…
Reference in a new issue