-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (82 loc) · 2.39 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require("fs-extra");
const settings = require("electron-settings");
const ipc = require("electron").ipcRenderer;
let ready = false;
let filelocation = "up";
const debug = true;
function init() {
if (settings.has("path.home") && settings.has("path.away")) {
ready = true;
}
}
init();
// eslint-disable-next-line no-unused-vars
function moveFiles(direction){
let fileArgs = {
up: ["path.home", "path.away"],
down: ["path.away", "path.home"]
};
if (!ready) return;
if (direction != filelocation){
ready = false;
fs.move(settings.get(fileArgs[direction][0]), settings.get(fileArgs[direction][1]), (err) => {
handleCallback(err, direction);
if (!err){
filelocation = direction;
notifyUserNative("The Archiver", "File moving has been completed!");
}
ready = true;
});
} else {
notifyUser(`Files are already ${direction}!`, "#0081ef", 6000);
}
}
function handleCallback(err, direction){
let notifyMessage = {
down: ["The Virtual Machine Has Been Moved Down Onto The Local Drive!", "#0081ef", 7000],
up: ["The Virtual Machine Has Been Moved Up Onto The External Drive!", "#0081ef", 7000]
};
let ifError = false;
if (err) {
// Error callback
if (debug) {
console.error(`Error on moving ${direction} function: ${err}`);
// ipc.send(ipcMessage[direction]);
// ipc.send("error-move", {direction: direction, error: util.inspect(err).split("\n")[0].substring(9)});
ipc.send("error-move", {direction: direction, error: String(err)});
}
ifError = true;
}
else {
if (!ifError) {
notifyUser.apply({}, notifyMessage[direction]);
}
}
}
// Notify users via HTML Functions
let runningNotifications = [];
function notifyUser(content, color, time) {
runningNotifications.push([content, color]);
setTimeout(function() {
runningNotifications.shift();
updateDisplay();
}, time);
updateDisplay();
}
module.exports.notifyUser = notifyUser;
function updateDisplay() {
var notifElem = document.getElementById("userNotification");
if (runningNotifications.length) {
var [content, color] = runningNotifications[0];
notifElem.innerHTML = (`<h5 style = 'margin-top: 5px;font-weight: 300; color:${color}'>${content}</h5>`);
} else {
notifElem.innerHTML = ("");
}
}
// End notify via HTML functions
function notifyUserNative(title, body){
let myNotification = new Notification(title, {body: body});
myNotification.onclick = () => {
ipc.send("show-app");
};
}