aboutsummaryrefslogtreecommitdiff
path: root/src/app/main.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-02-19 14:25:18 +0100
committerGitHub <noreply@github.com>2022-02-19 14:25:18 +0100
commit39da6eeecdb184e05f93ad1a8aaa1a2a95df333a (patch)
tree74b6be3a0edebe8df31c95d337ec63a64433f053 /src/app/main.js
parentee7dab5b056e254bff828a9b9f6d77be2287b935 (diff)
parent9e539d3d3df62df39b9a67ecf1c24734d6f8779b (diff)
downloadViper-39da6eeecdb184e05f93ad1a8aaa1a2a95df333a.tar.gz
Viper-39da6eeecdb184e05f93ad1a8aaa1a2a95df333a.zip
Merge pull request #81 from 0neGal/drag-drop
feat: drag and drop to install mods
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();