aboutsummaryrefslogtreecommitdiff
path: root/src/app/main.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-02-18 22:13:08 +0100
committer0neGal <mail@0negal.com>2022-02-18 22:14:56 +0100
commit78a83334f42294fdc0e36c2c44e1fbff7369fd7c (patch)
tree8d141f0d2d98d69a263b047122751ac7143724c8 /src/app/main.js
parentee7dab5b056e254bff828a9b9f6d77be2287b935 (diff)
downloadViper-78a83334f42294fdc0e36c2c44e1fbff7369fd7c.tar.gz
Viper-78a83334f42294fdc0e36c2c44e1fbff7369fd7c.zip
basic drag and drop support
Since apparently dragleave and dragenter don't quite work as intended we have to resort to this obscure method which should work just fine on the user's end.
Diffstat (limited to 'src/app/main.js')
-rw-r--r--src/app/main.js33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/app/main.js b/src/app/main.js
index 7c71c9d..97937a9 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -158,12 +158,18 @@ function selected(all) {
}
}
-// Tells the main process to install a mod
+// Tells the main process to install a mod through the file selector
function installmod() {
setButtons(false);
ipcRenderer.send("installmod")
}
+// Tells the main process to directly install a mod from this path
+function installFromPath(path) {
+ setButtons(false);
+ ipcRenderer.send("installfrompath", path)
+}
+
// Tells the main process to install a mod from a URL
function installFromURL(url) {
setButtons(false);
@@ -244,6 +250,31 @@ ipcRenderer.on("wrongpath", () => {
setlang();
+let dragtimer;
+document.addEventListener("dragover", (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ dragUI.classList.add("shown");
+
+ clearTimeout(dragtimer);
+ dragtimer = setTimeout(() => {
+ dragUI.classList.remove("shown");
+ }, 5000)
+});
+
+document.addEventListener("mouseover", (e) => {
+ clearTimeout(dragtimer);
+ dragUI.classList.remove("shown");
+});
+
+document.addEventListener("drop", (e) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ dragUI.classList.remove("shown");
+ installFromPath(event.dataTransfer.files[0].path)
+});
+
document.body.addEventListener("click", event => {
if (event.target.tagName.toLowerCase() === "a" && event.target.protocol != "file:") {
event.preventDefault();