mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 21:58:39 -09:00
Fix file/directory drag and drop
This commit is contained in:
parent
71c95b5bbd
commit
dd0ae33dda
3 changed files with 10 additions and 25 deletions
|
|
@ -18,7 +18,6 @@
|
||||||
"electron-fetch": "1.7.3",
|
"electron-fetch": "1.7.3",
|
||||||
"electron-is-dev": "2.0.0",
|
"electron-is-dev": "2.0.0",
|
||||||
"electron-store": "8.0.0",
|
"electron-store": "8.0.0",
|
||||||
"file-uri-to-path": "2.0.0",
|
|
||||||
"fs-extra": "10.0.0",
|
"fs-extra": "10.0.0",
|
||||||
"git-describe": "4.0.4",
|
"git-describe": "4.0.4",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions} from 'electron';
|
import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions, Event} from 'electron';
|
||||||
import {isAbsolute, normalize, sep} from 'path';
|
import {isAbsolute, normalize, sep} from 'path';
|
||||||
import {parse as parseUrl} from 'url';
|
import {URL, fileURLToPath} from 'url';
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
import fileUriToPath from 'file-uri-to-path';
|
|
||||||
import isDev from 'electron-is-dev';
|
import isDev from 'electron-is-dev';
|
||||||
import updater from '../updater';
|
import updater from '../updater';
|
||||||
import toElectronBackgroundColor from '../utils/to-electron-background-color';
|
import toElectronBackgroundColor from '../utils/to-electron-background-color';
|
||||||
|
|
@ -259,30 +258,22 @@ export function newWindow(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// If file is dropped onto the terminal window, navigate event is prevented
|
const handleDrop = (event: Event, url: string) => {
|
||||||
// and his path is added to active session.
|
const protocol = typeof url === 'string' && new URL(url).protocol;
|
||||||
window.webContents.on('will-navigate', (event, url) => {
|
|
||||||
const protocol = typeof url === 'string' && parseUrl(url).protocol;
|
|
||||||
if (protocol === 'file:') {
|
if (protocol === 'file:') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const path = fileURLToPath(url);
|
||||||
const path = fileUriToPath(url);
|
|
||||||
|
|
||||||
rpc.emit('session data send', {data: path, escaped: true});
|
rpc.emit('session data send', {data: path, escaped: true});
|
||||||
} else if (protocol === 'http:' || protocol === 'https:') {
|
} else if (protocol === 'http:' || protocol === 'https:') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
rpc.emit('session data send', {data: url});
|
rpc.emit('session data send', {data: url});
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
// xterm makes link clickable
|
// If file is dropped onto the terminal window, navigate and new-window events are prevented
|
||||||
window.webContents.on('new-window', (event, url) => {
|
// and his path is added to active session.
|
||||||
const protocol = typeof url === 'string' && parseUrl(url).protocol;
|
window.webContents.on('will-navigate', handleDrop);
|
||||||
if (protocol === 'http:' || protocol === 'https:') {
|
window.webContents.on('new-window', handleDrop);
|
||||||
event.preventDefault();
|
|
||||||
void shell.openExternal(url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// expose internals to extension authors
|
// expose internals to extension authors
|
||||||
window.rpc = rpc;
|
window.rpc = rpc;
|
||||||
|
|
|
||||||
|
|
@ -244,11 +244,6 @@ fast-deep-equal@^3.1.1:
|
||||||
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
|
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
|
||||||
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
|
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
|
||||||
|
|
||||||
file-uri-to-path@2.0.0:
|
|
||||||
version "2.0.0"
|
|
||||||
resolved "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-2.0.0.tgz#7b415aeba227d575851e0a5b0c640d7656403fba"
|
|
||||||
integrity sha512-hjPFI8oE/2iQPVe4gbrJ73Pp+Xfub2+WI2LlXDbsaJBwT5wuMh35WNWVYYTpnz895shtwfyutMFLFywpQAFdLg==
|
|
||||||
|
|
||||||
fill-range@^7.0.1:
|
fill-range@^7.0.1:
|
||||||
version "7.0.1"
|
version "7.0.1"
|
||||||
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
|
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue