Fixed an issue where clicking on a file:// protocol path does not open windows explorer since version 3.5.0.
This commit is contained in:
parent
dcc7819dea
commit
267b8780cf
|
@ -15,6 +15,25 @@ const ErrorView = require('./ErrorView.jsx');
|
||||||
|
|
||||||
const preloadJS = `file://${remote.app.getAppPath()}/browser/webview/mattermost_bundle.js`;
|
const preloadJS = `file://${remote.app.getAppPath()}/browser/webview/mattermost_bundle.js`;
|
||||||
|
|
||||||
|
function extractFileURL(message) {
|
||||||
|
const matched = message.match(/Not allowed to load local resource:\s*(.+)/);
|
||||||
|
if (matched) {
|
||||||
|
return matched[1];
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function isNetworkDrive(fileURL) {
|
||||||
|
const u = url.parse(fileURL);
|
||||||
|
if (u.protocol === 'file:' && u.host) {
|
||||||
|
// Disallow localhost, 127.0.0.1, ::1.
|
||||||
|
if (!u.host.match(/^localhost$|^127\.0\.0\.1$|^\[::1\]$/)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const MattermostView = createReactClass({
|
const MattermostView = createReactClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
|
@ -156,9 +175,9 @@ const MattermostView = createReactClass({
|
||||||
case 1:
|
case 1:
|
||||||
console.warn(message);
|
console.warn(message);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2: {
|
||||||
const fileURL = this.extractFileURL(e.message);
|
const fileURL = extractFileURL(e.message);
|
||||||
if (this.isNetworkDrive(fileURL)) {
|
if (isNetworkDrive(fileURL)) {
|
||||||
// Network drive: Should be allowed.
|
// Network drive: Should be allowed.
|
||||||
if (!shell.openExternal(decodeURI(fileURL))) {
|
if (!shell.openExternal(decodeURI(fileURL))) {
|
||||||
console.log(`[${this.props.name}] shell.openExternal failed: ${fileURL}`);
|
console.log(`[${this.props.name}] shell.openExternal failed: ${fileURL}`);
|
||||||
|
@ -168,6 +187,7 @@ const MattermostView = createReactClass({
|
||||||
console.error(message);
|
console.error(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
console.log(message);
|
console.log(message);
|
||||||
break;
|
break;
|
||||||
|
@ -239,22 +259,6 @@ const MattermostView = createReactClass({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
extractFileURL(message) {
|
|
||||||
const matched = message.match(/Not allowed to load local resource:\s*(.+)/);
|
|
||||||
if (matched) {
|
|
||||||
return matched[1];
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
},
|
|
||||||
|
|
||||||
isNetworkDrive(fileURL) {
|
|
||||||
const u = url.parse(fileURL);
|
|
||||||
if (u.protocol === 'file:' && u.host) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const errorView = this.state.errorInfo ? (
|
const errorView = this.state.errorInfo ? (
|
||||||
<ErrorView
|
<ErrorView
|
||||||
|
|
Loading…
Reference in a new issue