Skip to content

Commit f97d4d0

Browse files
committed
Merge branch 'main' of https://github.com/GameGodS3/DropPoint into main
2 parents 27bb152 + b9e0626 commit f97d4d0

24 files changed

+610
-4093
lines changed

package-lock.json

Lines changed: 302 additions & 4079 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "droppoint",
33
"productName": "DropPoint",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"description": "Drag-and-drop assist",
6-
"main": "index.js",
6+
"main": "./src/App.js",
77
"scripts": {
88
"start": "electron .",
99
"build": "electron-builder",

renderer.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function clearDrag() {
1717
}
1818
dragicons[0].removeAttribute("style");
1919
}
20+
2021
(function () {
2122
holder.ondragover = (e) => {
2223
e.preventDefault;
@@ -59,13 +60,13 @@ function clearDrag() {
5960
}
6061
// If the filetype does not belong to the available JavaScript filetypes
6162
if (filetype === "") {
62-
document.querySelector("#drag img").src = "./media/png/file.png";
63+
document.querySelector("#drag img").src = "./media/file.png";
6364
filetype = "application";
6465
} else if (filetype != "application") {
6566
document.querySelector("#drag img").src =
66-
"./media/png/" + filetype + ".png";
67+
"./media/" + filetype + ".png";
6768
} else {
68-
document.querySelector("#drag img").src = "./media/png/file.png";
69+
document.querySelector("#drag img").src = "./media/file.png";
6970
}
7071
filepath = f.path.toString();
7172
let filedict = {
@@ -82,22 +83,22 @@ function clearDrag() {
8283
// Animations for multiple file input
8384
dragicons = document.getElementsByClassName("files");
8485
if (filelist.length == 2) {
85-
dragicons[0].src = "./media/png/file.png";
86+
dragicons[0].src = "./media/file.png";
8687
let newimg = document.createElement("img");
87-
newimg.src = "./media/png/file.png";
88+
newimg.src = "./media/file.png";
8889
newimg.className = "files";
8990
fileicons.appendChild(newimg);
9091
dragicons[0].style = "animation: tilt 0.5s forwards";
9192
newimg.style = "filter: drop-shadow(3px 3px 5px #0a0a0942);";
9293
} else if (filelist.length > 2) {
93-
dragicons[0].src = "./media/png/file.png";
94+
dragicons[0].src = "./media/file.png";
9495
// ProtoImg and NewImg are required in case user drags in more than 2 files initially itself
9596
let protoimg = document.createElement("img");
96-
protoimg.src = "./media/png/file.png";
97+
protoimg.src = "./media/file.png";
9798
protoimg.className = "files";
9899
fileicons.appendChild(protoimg);
99100
let newimg = document.createElement("img");
100-
newimg.src = "./media/png/file.png";
101+
newimg.src = "./media/file.png";
101102
newimg.className = "files";
102103
fileicons.appendChild(newimg);
103104
dragicons[0].style = "animation: tiltmore 0.5s forwards";
@@ -112,7 +113,7 @@ function clearDrag() {
112113
// Drag out request to electron
113114
document.getElementById("drag").ondragstart = (event) => {
114115
event.preventDefault();
115-
window.electron.startDrag(filelist);
116+
window.electron.dragOutListener(filelist);
116117
dragin.style.display = "flex";
117118
dragout.style.display = "none";
118119
clearDrag();

src/App.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { app, BrowserWindow, nativeImage } = require("electron");
2+
const path = require("path");
3+
const { autoUpdater } = require("electron-updater");
4+
const { createMainWindow } = require("./Window");
5+
const { setShortcut } = require("./Shortcut");
6+
const { droppointDefaultIcon } = require("./Icons");
7+
const { setTray } = require("./Tray");
8+
9+
app
10+
.on("ready", () => {
11+
// Splash screen to run in background and keep app alive
12+
let splashScreen = new BrowserWindow({
13+
width: 400,
14+
height: 200,
15+
frame: false,
16+
titleBarStyle: "hidden",
17+
transparent: true,
18+
icon: nativeImage.createFromPath(droppointDefaultIcon),
19+
});
20+
splashScreen.loadFile(path.join(__dirname, "../static/media/splash.jpeg"));
21+
splashScreen.removeMenu();
22+
setTimeout(() => {
23+
splashScreen.hide();
24+
}, 3000);
25+
26+
if (createMainWindow()) {
27+
setTray();
28+
setShortcut();
29+
}
30+
})
31+
.on("activate", () => {
32+
autoUpdater.checkForUpdatesAndNotify();
33+
if (BrowserWindow.getAllWindows.length === 0) {
34+
createMainWindow();
35+
}
36+
})
37+
.on("will-quit", () => {
38+
globalShortcut.unregisterAll();
39+
});
40+
module.exports = { whenReady: app.whenReady };

src/Icons.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const path = require("path");
2+
3+
let convertToNative = (imageName) => {
4+
let icon = path.join(__dirname, "../static/media/", imageName);
5+
return icon;
6+
};
7+
8+
let droppointDefaultIcon = convertToNative("droppoint.ico");
9+
let droppointMacIcon = convertToNative("droppoint.icns");
10+
let audio = convertToNative("audio.png");
11+
let file = convertToNative("file.png");
12+
let folder = convertToNative("folder.png");
13+
let image = convertToNative("image.png");
14+
let multifile = convertToNative("multifile.png");
15+
let text = convertToNative("text.png");
16+
let video = convertToNative("video.png");
17+
18+
module.exports = {
19+
droppointDefaultIcon: droppointDefaultIcon,
20+
droppointMacIcon: droppointMacIcon,
21+
audio: audio,
22+
file: file,
23+
folder: folder,
24+
image: image,
25+
multifile: multifile,
26+
text: text,
27+
video: video,
28+
};

src/RequestHandlers.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const { ipcMain, nativeImage } = require("electron");
2+
global.share = { ipcMain };
3+
4+
const {
5+
audio,
6+
file,
7+
folder,
8+
image,
9+
multifile,
10+
text,
11+
video,
12+
} = require("./Icons");
13+
14+
/**
15+
* Assigns file icons according to type. If multiple files, use multifile icon.
16+
* @param {Array} fileList The collection of files currently dragged into the window
17+
* @return {String} Name of icon according to filetype
18+
*/
19+
let getFileTypeIcons = (fileList) => {
20+
let fileType;
21+
if (fileList.length <= 1) {
22+
fileType = fileList[0]["fileType"];
23+
if (fileType != "application") {
24+
fileType = eval(fileType); //eval is used for using the string value in fileType as a variable
25+
} else {
26+
fileType = file;
27+
}
28+
} else {
29+
fileType = multifile;
30+
}
31+
return fileType;
32+
};
33+
34+
/**
35+
* Returns list of file paths of all the files in filelist.
36+
* Necessary for startDrag API of electron
37+
*
38+
* @param {Array} fileList - List of files
39+
* @return {Array} List of paths of files in fileList
40+
*/
41+
let getFilePathList = (fileList) => {
42+
let filePathList = [];
43+
fileList.forEach((element) => {
44+
filePathList.push(element["filePath"]);
45+
});
46+
return filePathList;
47+
};
48+
49+
/**
50+
* Activates Drag-and-Drop API of electron. Handles drag icon attributes.
51+
* Minimises instance after operation
52+
*
53+
* @param {Array} fileList - List of files
54+
*/
55+
let dragHandler = ipcMain.on("ondragstart", (event, fileList) => {
56+
let fileType = getFileTypeIcons(fileList);
57+
let filePathList = getFilePathList(fileList);
58+
let flag = false;
59+
event.sender.startDrag({
60+
files: filePathList,
61+
icon: nativeImage.createFromPath(fileType).resize({ width: 64 }),
62+
});
63+
DROPPOINT_MAIN.close();
64+
});
65+
66+
/**
67+
* For minimising instance on clicking the button
68+
*/
69+
let minimiseHandler = ipcMain.on("minimise", () => {
70+
DROPPOINT_MAIN.close();
71+
});
72+
73+
module.exports = {
74+
dragHandler: dragHandler,
75+
minimiseHandler: minimiseHandler,
76+
};

src/Shortcut.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { globalShortcut, BrowserWindow } = require("electron");
2+
const { createMainWindow } = require("./Window");
3+
4+
/**
5+
* Sets Shift + Caps Lock as Shortcut. Change to convenience
6+
*/
7+
const setShortcut = () => {
8+
let visible = true;
9+
const ret = globalShortcut.register("Shift+Capslock", () => {
10+
if (DROPPOINT_MAIN) {
11+
DROPPOINT_MAIN.close();
12+
} else {
13+
createMainWindow();
14+
}
15+
});
16+
17+
if (!ret) {
18+
console.log("KeyboardShorcutError");
19+
}
20+
};
21+
22+
module.exports = {
23+
setShortcut: setShortcut,
24+
};

src/Tray.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const { Tray, Menu, nativeImage, app } = require("electron");
2+
const { droppointDefaultIcon } = require("./Icons");
3+
const { createMainWindow } = require("./Window");
4+
5+
let trayIcon = nativeImage
6+
.createFromPath(droppointDefaultIcon)
7+
.resize({ width: 16 });
8+
9+
let tray;
10+
11+
/**
12+
* Sets system tray
13+
*/
14+
const setTray = () => {
15+
tray = new Tray(trayIcon);
16+
tray.setContextMenu(
17+
Menu.buildFromTemplate([
18+
{
19+
label: "New Instance",
20+
click: function () {
21+
if (!DROPPOINT_MAIN) {
22+
createMainWindow();
23+
} else {
24+
tray.displayBalloon({
25+
title: "DropPoint",
26+
content: "Instance already exists!",
27+
icon: nativeImage
28+
.createFromPath(droppointDefaultIcon)
29+
.resize({ width: 64 }),
30+
});
31+
}
32+
},
33+
},
34+
{
35+
label: "Quit",
36+
click: function () {
37+
app.quit();
38+
},
39+
},
40+
])
41+
);
42+
tray.setToolTip("DropPoint");
43+
tray.on("double-click", () => {
44+
if (!DROPPOINT_MAIN) {
45+
createMainWindow();
46+
} else {
47+
DROPPOINT_MAIN.close();
48+
}
49+
});
50+
};
51+
52+
module.exports = {
53+
setTray: setTray,
54+
};

src/Window.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
global.DROPPOINT_MAIN = null;
2+
3+
const { BrowserWindow, screen, nativeImage } = require("electron");
4+
const path = require("path");
5+
6+
const { droppointDefaultIcon } = require("./Icons");
7+
require("./RequestHandlers"); // For Drag and Drop and Minimise handling
8+
9+
let defaultWindowConfig = {
10+
width: 200,
11+
height: 200,
12+
x: 0, // For creating a session at the top middle of the screen
13+
y: 0,
14+
frame: false,
15+
titleBarStyle: "hidden",
16+
transparent: true,
17+
resizable: false,
18+
alwaysOnTop: true,
19+
webPreferences: {
20+
nodeIntegration: true,
21+
preload: path.join(__dirname, "preload.js"),
22+
},
23+
24+
icon: nativeImage.createFromPath(droppointDefaultIcon),
25+
};
26+
27+
function devConfig() {
28+
defaultWindowConfig.frame = true;
29+
defaultWindowConfig.titleBarStyle = "default";
30+
defaultWindowConfig.resizable = true;
31+
defaultWindowConfig.width = null;
32+
defaultWindowConfig.height = null;
33+
}
34+
35+
/**
36+
* Creates a global instance of DropPoint when called.
37+
* Only one instance of DropPoint at a time will be stable.
38+
* Multiple instances may cause errors
39+
*
40+
* @param {Boolean} debug - pass "true" to get Debug settings
41+
* @returns {Boolean} true if successful
42+
*/
43+
function createMainWindow(debug = false) {
44+
let width = screen.getPrimaryDisplay().bounds.width;
45+
defaultWindowConfig.x = width / 2 - 100;
46+
47+
if (debug) {
48+
devConfig();
49+
DROPPOINT_MAIN = new BrowserWindow(defaultWindowConfig);
50+
DROPPOINT_MAIN.webContents.openDevTools();
51+
} else {
52+
DROPPOINT_MAIN = new BrowserWindow(defaultWindowConfig);
53+
}
54+
55+
DROPPOINT_MAIN.loadFile(path.join(__dirname, "../static/index.html"));
56+
DROPPOINT_MAIN.setVisibleOnAllWorkspaces(true);
57+
DROPPOINT_MAIN.shadow = true;
58+
DROPPOINT_MAIN.removeMenu();
59+
60+
DROPPOINT_MAIN.on("closed", () => {
61+
DROPPOINT_MAIN = null;
62+
});
63+
if (DROPPOINT_MAIN) {
64+
return true;
65+
}
66+
return false;
67+
}
68+
69+
module.exports = {
70+
createMainWindow: createMainWindow,
71+
};
File renamed without changes.

0 commit comments

Comments
 (0)