Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit d27ae49

Browse files
committed
Closed #37 : mod_clipboardButtons
1 parent 1092c8f commit d27ae49

File tree

10 files changed

+144
-6
lines changed

10 files changed

+144
-6
lines changed

src/_boot.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const ipc = electron.ipcMain;
2020
const path = require("path");
2121
const url = require("url");
2222
const fs = require("fs");
23+
const clip = require("clipboardy");
2324
const Terminal = require("./classes/terminal.class.js").Terminal;
2425

2526
ipc.on("log", (e, type, content) => {
@@ -108,6 +109,19 @@ app.on('ready', () => {
108109
signale.watch("Waiting for frontend connection...");
109110
};
110111

112+
// Clipboard backend access
113+
ipc.on("clipboard", (e, arg) => {
114+
switch(arg) {
115+
case "read":
116+
clip.read().then(text => {
117+
e.sender.send("clipboard-reply", text);
118+
});
119+
break;
120+
default:
121+
throw new Error("Illegal clipboard access request");
122+
}
123+
});
124+
111125
signale.info("Creating window...");
112126
let {x, y, width, height} = electron.screen.getPrimaryDisplay().bounds;
113127
width++; height++;

src/_renderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ initMods = () => {
223223
window.mods.sysinfo = new Sysinfo("mod_column_left");
224224
window.mods.cpuinfo = new Cpuinfo("mod_column_left");
225225
window.mods.ramwatcher = new RAMwatcher("mod_column_left");
226+
window.mods.clipboardButtons = new ClipboardButtons("mod_column_left");
226227

227228
// Right column
228229
window.mods.netstat = new Netstat("mod_column_right");
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
div#mod_clipboardButtons {
2+
border-top: 0.092vh solid rgba(var(--color_r), var(--color_g), var(--color_b), 0.3);
3+
font-family: var(--font_main_light);
4+
letter-spacing: 0.092vh;
5+
padding: 0.645vh 0vh;
6+
display: flex;
7+
}
8+
9+
div#mod_clipboardButtons::before {
10+
content: "";
11+
border-left: 0.092vh solid rgba(var(--color_r), var(--color_g), var(--color_b), 0.3);
12+
align-self: flex-start;
13+
position: relative;
14+
left: -0.092vh;
15+
top: -1.111vh;
16+
height: 0.833vh;
17+
}
18+
19+
div#mod_clipboardButtons::after {
20+
content: "";
21+
border-right: 0.092vh solid rgba(var(--color_r), var(--color_g), var(--color_b), 0.3);
22+
position: relative;
23+
right: -0.092vh;
24+
top: -1.111vh;
25+
height: 0.833vh;
26+
}
27+
28+
div#mod_clipboardButtons_inner {
29+
display: flex;
30+
flex-direction: row;
31+
align-items: center;
32+
justify-content: space-evenly;
33+
flex-wrap: wrap;
34+
width: 100%;
35+
}
36+
37+
div#mod_clipboardButtons h1 {
38+
font-size: 1.48vh;
39+
margin: 0vh;
40+
margin-bottom: -1vh;
41+
width: 98%;
42+
}
43+
44+
div#mod_clipboardButtons_inner div {
45+
margin-top: 1.2vh;
46+
background: rgba(var(--color_r), var(--color_g), var(--color_b), 0.1);
47+
height: 3.8vh;
48+
width: 45%;
49+
display: flex;
50+
align-items: center;
51+
justify-content: center;
52+
box-sizing: border-box;
53+
border: 2px solid rgba(var(--color_r), var(--color_g), var(--color_b), 0.5);
54+
border-radius: 2px;
55+
font-family: var(--font_main);
56+
font-weight: bold;
57+
font-size: 1.5vh;
58+
cursor: pointer;
59+
}
60+
61+
div#mod_clipboardButtons_inner div:active {
62+
background: rgba(var(--color_r), var(--color_g), var(--color_b), 0.8);
63+
}

src/assets/css/mod_ramwatcher.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ div#mod_ramwatcher_pointmap {
5858
grid-gap: 0.23vh;
5959
padding-top: 0.5vh;
6060
padding-left: 0.5vh;
61+
margin-bottom: 0.8vh;
6162
}
6263

6364
div.mod_ramwatcher_point {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class ClipboardButtons {
2+
constructor(parentId) {
3+
if (!parentId) throw "Missing parameters";
4+
5+
// Create DOM
6+
this.parent = document.getElementById(parentId);
7+
this._element = document.createElement("div");
8+
this._element.setAttribute("id", "mod_clipboardButtons");
9+
this._element.innerHTML = `<div id="mod_clipboardButtons_inner">
10+
<h1>CLIPBOARD ACCESS</h1>
11+
<div>COPY</div>
12+
<div>PASTE</div>
13+
</div>`;
14+
15+
this.parent.append(this._element);
16+
17+
document.querySelector("div#mod_clipboardButtons_inner > div:nth-child(2)").addEventListener("click", e => {
18+
window.term.clipboard.copy();
19+
});
20+
document.querySelector("div#mod_clipboardButtons_inner > div:last-child").addEventListener("click", e => {
21+
window.term.clipboard.paste();
22+
});
23+
}
24+
}
25+
26+
module.exports = {
27+
ClipboardButtons
28+
};

src/classes/keyboard.class.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ class Keyboard {
195195
} else if (cmd === "\n") {
196196
term.writelr("");
197197
} else if (cmd === ctrlseq[19] && window.term.term.hasSelection()) {
198-
window.term.copy();
198+
window.term.clipboard.copy();
199+
} else if (cmd === ctrlseq[20] && window.term.clipboard.didCopy) {
200+
window.term.clipboard.paste();
199201
} else {
200202
term.write(cmd);
201203
}

src/classes/terminal.class.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,23 @@ class Terminal {
166166
this.socket.send(cmd+"\r");
167167
};
168168

169-
this.copy = () => {
170-
if (!this.term.hasSelection()) return false;
171-
document.execCommand("copy");
172-
this.term.clearSelection();
173-
};
169+
this.clipboard = {
170+
copy: () => {
171+
if (!this.term.hasSelection()) return false;
172+
document.execCommand("copy");
173+
this.term.clearSelection();
174+
this.clipboard.didCopy = true;
175+
},
176+
paste: () => {
177+
this.Ipc.once("clipboard-reply", (e, txt) => {
178+
this.write(txt);
179+
this.clipboard.didCopy = false;
180+
});
181+
this.Ipc.send("clipboard", "read");
182+
},
183+
didCopy: false
184+
}
185+
174186
} else if (opts.role === "server") {
175187

176188
this.Pty = require("node-pty");

src/package-lock.json

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

src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"homepage": "https://github.com/GitSquared/edex-ui#readme",
2525
"dependencies": {
2626
"battery-level": "3.0.0",
27+
"clipboardy": "1.2.3",
2728
"color": "3.0.0",
2829
"node-pty": "0.7.6",
2930
"pretty-bytes": "5.1.0",

src/ui.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<link rel="stylesheet" href="assets/css/mod_conninfo.css" />
2424
<link rel="stylesheet" href="assets/css/mod_globe.css" />
2525
<link rel="stylesheet" href="assets/css/mod_ramwatcher.css" />
26+
<link rel="stylesheet" href="assets/css/mod_clipboardButtons.css" />
2627

2728
<!-- Load main modules classes -->
2829
<script src="classes/modal.class.js"></script>
@@ -38,6 +39,7 @@
3839
<script src="classes/conninfo.class.js"></script>
3940
<script src="classes/locationGlobe.class.js"></script>
4041
<script src="classes/ramwatcher.class.js"></script>
42+
<script src="classes/clipboardButtons.class.js"></script>
4143
</head>
4244
<body class="solidBackground">
4345
<section id="boot_screen">

0 commit comments

Comments
 (0)