mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -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-is-dev": "2.0.0",
|
||||
"electron-store": "8.0.0",
|
||||
"file-uri-to-path": "2.0.0",
|
||||
"fs-extra": "10.0.0",
|
||||
"git-describe": "4.0.4",
|
||||
"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 {parse as parseUrl} from 'url';
|
||||
import {URL, fileURLToPath} from 'url';
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
import fileUriToPath from 'file-uri-to-path';
|
||||
import isDev from 'electron-is-dev';
|
||||
import updater from '../updater';
|
||||
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
|
||||
// and his path is added to active session.
|
||||
window.webContents.on('will-navigate', (event, url) => {
|
||||
const protocol = typeof url === 'string' && parseUrl(url).protocol;
|
||||
const handleDrop = (event: Event, url: string) => {
|
||||
const protocol = typeof url === 'string' && new URL(url).protocol;
|
||||
if (protocol === 'file:') {
|
||||
event.preventDefault();
|
||||
|
||||
const path = fileUriToPath(url);
|
||||
|
||||
const path = fileURLToPath(url);
|
||||
rpc.emit('session data send', {data: path, escaped: true});
|
||||
} else if (protocol === 'http:' || protocol === 'https:') {
|
||||
event.preventDefault();
|
||||
rpc.emit('session data send', {data: url});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// xterm makes link clickable
|
||||
window.webContents.on('new-window', (event, url) => {
|
||||
const protocol = typeof url === 'string' && parseUrl(url).protocol;
|
||||
if (protocol === 'http:' || protocol === 'https:') {
|
||||
event.preventDefault();
|
||||
void shell.openExternal(url);
|
||||
}
|
||||
});
|
||||
// If file is dropped onto the terminal window, navigate and new-window events are prevented
|
||||
// and his path is added to active session.
|
||||
window.webContents.on('will-navigate', handleDrop);
|
||||
window.webContents.on('new-window', handleDrop);
|
||||
|
||||
// expose internals to extension authors
|
||||
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"
|
||||
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:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
|
||||
|
|
|
|||
Loading…
Reference in a new issue