mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Prettified Code!
This commit is contained in:
parent
90ce4acfce
commit
cf6573bb0d
5 changed files with 121 additions and 142 deletions
47
gui/main.js
47
gui/main.js
|
@ -547,39 +547,36 @@ ipcMain.on("select-user-image", (event, data) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// read files in folder - use case "shared folder"
|
// read files in folder - use case "shared folder"
|
||||||
ipcMain.on("read-files-in-folder", (event, data) => {
|
ipcMain.on("read-files-in-folder", (event, data) => {
|
||||||
|
let fileList = [];
|
||||||
|
|
||||||
let fileList = []
|
let folder = data.folder;
|
||||||
|
let files = fs.readdirSync(folder);
|
||||||
let folder = data.folder
|
console.log(folder);
|
||||||
let files = fs.readdirSync(folder);
|
console.log(files);
|
||||||
console.log(folder)
|
files.forEach((file) => {
|
||||||
console.log(files)
|
try {
|
||||||
files.forEach(file => {
|
let filePath = folder + "/" + file;
|
||||||
try{
|
if (fs.lstatSync(filePath).isFile()) {
|
||||||
let filePath = folder + '/' + file;
|
let fileSizeInBytes = fs.statSync(filePath).size;
|
||||||
if(fs.lstatSync(filePath).isFile()){
|
|
||||||
let fileSizeInBytes = fs.statSync(filePath).size
|
|
||||||
let extension = path.extname(filePath);
|
let extension = path.extname(filePath);
|
||||||
fileList.push({ name: file, extension: extension.substring(1), size: fileSizeInBytes });
|
fileList.push({
|
||||||
}
|
name: file,
|
||||||
} catch(err){
|
extension: extension.substring(1),
|
||||||
console.log(err)
|
size: fileSizeInBytes,
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
chat.webContents.send("return-shared-folder-files", {
|
|
||||||
files: fileList,
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chat.webContents.send("return-shared-folder-files", {
|
||||||
|
files: fileList,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//save file to folder
|
//save file to folder
|
||||||
ipcMain.on("save-file-to-folder", (event, data) => {
|
ipcMain.on("save-file-to-folder", (event, data) => {
|
||||||
console.log(data.file);
|
console.log(data.file);
|
||||||
|
|
|
@ -397,14 +397,14 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// open file selector for shared folder
|
// open file selector for shared folder
|
||||||
document.getElementById("sharedFolderButton").addEventListener("click", () => {
|
document
|
||||||
ipcRenderer.send("read-files-in-folder", {
|
.getElementById("sharedFolderButton")
|
||||||
folder: config.shared_folder_path,
|
.addEventListener("click", () => {
|
||||||
|
ipcRenderer.send("read-files-in-folder", {
|
||||||
|
folder: config.shared_folder_path,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById("openSharedFilesFolder")
|
.getElementById("openSharedFilesFolder")
|
||||||
|
@ -414,7 +414,6 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// SEND MSG
|
// SEND MSG
|
||||||
document.getElementById("sendMessage").addEventListener("click", () => {
|
document.getElementById("sendMessage").addEventListener("click", () => {
|
||||||
document.getElementById("emojipickercontainer").style.display = "none";
|
document.getElementById("emojipickercontainer").style.display = "none";
|
||||||
|
@ -529,51 +528,45 @@ ipcRenderer.on("return-selected-files", (event, arg) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("return-shared-folder-files", (event, arg) => {
|
ipcRenderer.on("return-shared-folder-files", (event, arg) => {
|
||||||
console.log(arg)
|
console.log(arg);
|
||||||
|
|
||||||
var tbl = document.getElementById("sharedFolderTable");
|
var tbl = document.getElementById("sharedFolderTable");
|
||||||
tbl.innerHTML = "";
|
tbl.innerHTML = "";
|
||||||
let counter = 0
|
let counter = 0;
|
||||||
arg.files.forEach(file => {
|
arg.files.forEach((file) => {
|
||||||
console.log(file["name"]);
|
console.log(file["name"]);
|
||||||
var row = document.createElement("tr");
|
var row = document.createElement("tr");
|
||||||
|
|
||||||
let id = document.createElement("td");
|
let id = document.createElement("td");
|
||||||
let idText = document.createElement("span");
|
let idText = document.createElement("span");
|
||||||
idText.innerText = counter+=1;
|
idText.innerText = counter += 1;
|
||||||
id.appendChild(idText);
|
id.appendChild(idText);
|
||||||
row.appendChild(id);
|
row.appendChild(id);
|
||||||
|
|
||||||
|
let filename = document.createElement("td");
|
||||||
|
let filenameText = document.createElement("span");
|
||||||
|
filenameText.innerText = file["name"];
|
||||||
|
filename.appendChild(filenameText);
|
||||||
|
row.appendChild(filename);
|
||||||
|
|
||||||
let filename = document.createElement("td");
|
let filetype = document.createElement("td");
|
||||||
let filenameText = document.createElement("span");
|
let filetypeText = document.createElement("span");
|
||||||
filenameText.innerText = file["name"];
|
filetypeText.innerHTML = `
|
||||||
filename.appendChild(filenameText);
|
<i class="bi bi-filetype-${file["extension"]}" style="font-size: 1.8rem"></i>
|
||||||
row.appendChild(filename);
|
|
||||||
|
|
||||||
let filetype = document.createElement("td");
|
|
||||||
let filetypeText = document.createElement("span");
|
|
||||||
filetypeText.innerHTML = `
|
|
||||||
<i class="bi bi-filetype-${file['extension']}" style="font-size: 1.8rem"></i>
|
|
||||||
`;
|
`;
|
||||||
filetype.appendChild(filetypeText);
|
filetype.appendChild(filetypeText);
|
||||||
row.appendChild(filetype);
|
row.appendChild(filetype);
|
||||||
|
|
||||||
let filesize = document.createElement("td");
|
let filesize = document.createElement("td");
|
||||||
let filesizeText = document.createElement("span");
|
let filesizeText = document.createElement("span");
|
||||||
filesizeText.innerText = file["size"];
|
filesizeText.innerText = file["size"];
|
||||||
filesize.appendChild(filesizeText);
|
filesize.appendChild(filesizeText);
|
||||||
row.appendChild(filesize);
|
row.appendChild(filesize);
|
||||||
|
|
||||||
|
|
||||||
tbl.appendChild(row);
|
|
||||||
|
|
||||||
|
tbl.appendChild(row);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ipcRenderer.on("return-select-user-image", (event, arg) => {
|
ipcRenderer.on("return-select-user-image", (event, arg) => {
|
||||||
let imageFiletype = arg.mime;
|
let imageFiletype = arg.mime;
|
||||||
let imageFile = arg.data;
|
let imageFile = arg.data;
|
||||||
|
@ -793,11 +786,9 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
|
||||||
obj.filetype = "null";
|
obj.filetype = "null";
|
||||||
obj.file = "null";
|
obj.file = "null";
|
||||||
|
|
||||||
if(config.enable_request_profile == "True"){
|
if (config.enable_request_profile == "True") {
|
||||||
sendUserData(item.dxcallsign);
|
sendUserData(item.dxcallsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (splitted_data[1] == "res") {
|
} else if (splitted_data[1] == "res") {
|
||||||
obj.uuid = uuidv4().toString();
|
obj.uuid = uuidv4().toString();
|
||||||
obj.timestamp = Math.floor(Date.now() / 1000);
|
obj.timestamp = Math.floor(Date.now() / 1000);
|
||||||
|
|
|
@ -165,12 +165,15 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
action: "return-folder-paths-received_files_folder",
|
action: "return-folder-paths-received_files_folder",
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("return-folder-paths-received_files_folder", (event, data) => {
|
ipcRenderer.on(
|
||||||
document.getElementById("received_files_folder").value =
|
"return-folder-paths-received_files_folder",
|
||||||
data.path.filePaths[0];
|
(event, data) => {
|
||||||
config.received_files_folder = data.path.filePaths[0];
|
document.getElementById("received_files_folder").value =
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
data.path.filePaths[0];
|
||||||
});
|
config.received_files_folder = data.path.filePaths[0];
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
document
|
document
|
||||||
|
@ -181,15 +184,17 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
action: "return-folder-paths-shared_folder_path",
|
action: "return-folder-paths-shared_folder_path",
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("return-folder-paths-shared_folder_path", (event, data) => {
|
ipcRenderer.on(
|
||||||
document.getElementById("shared_folder_path").value =
|
"return-folder-paths-shared_folder_path",
|
||||||
data.path.filePaths[0];
|
(event, data) => {
|
||||||
config.shared_folder_path = data.path.filePaths[0];
|
document.getElementById("shared_folder_path").value =
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
data.path.filePaths[0];
|
||||||
});
|
config.shared_folder_path = data.path.filePaths[0];
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById("openReceivedFilesFolder")
|
.getElementById("openReceivedFilesFolder")
|
||||||
.addEventListener("click", () => {
|
.addEventListener("click", () => {
|
||||||
|
@ -198,8 +203,6 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// ENABLE BOOTSTRAP POPOVERS EVERYWHERE
|
// ENABLE BOOTSTRAP POPOVERS EVERYWHERE
|
||||||
// https://getbootstrap.com/docs/5.0/components/popovers/#example-enable-popovers-everywhere
|
// https://getbootstrap.com/docs/5.0/components/popovers/#example-enable-popovers-everywhere
|
||||||
|
@ -265,18 +268,17 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
document.getElementById("shared_folder_path").value =
|
document.getElementById("shared_folder_path").value =
|
||||||
config.shared_folder_path;
|
config.shared_folder_path;
|
||||||
|
|
||||||
if (config.enable_request_profile == "True") {
|
if (config.enable_request_profile == "True") {
|
||||||
document.getElementById("enable_request_profile").checked = true;
|
document.getElementById("enable_request_profile").checked = true;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("enable_request_profile").checked = false;
|
document.getElementById("enable_request_profile").checked = false;
|
||||||
}
|
}
|
||||||
if (config.enable_request_shared_folder == "True") {
|
if (config.enable_request_shared_folder == "True") {
|
||||||
document.getElementById("enable_request_shared_folder").checked = true;
|
document.getElementById("enable_request_shared_folder").checked = true;
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("enable_request_shared_folder").checked = false;
|
document.getElementById("enable_request_shared_folder").checked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (config.enable_is_writing == "True") {
|
if (config.enable_is_writing == "True") {
|
||||||
document.getElementById("enable_is_writing").checked = true;
|
document.getElementById("enable_is_writing").checked = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -591,7 +593,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
.addEventListener("click", () => {
|
.addEventListener("click", () => {
|
||||||
ipcRenderer.send("get-file-path", {
|
ipcRenderer.send("get-file-path", {
|
||||||
title: "Title",
|
title: "Title",
|
||||||
action : "return-file-path-hamlib_rigctld_path"
|
action: "return-file-path-hamlib_rigctld_path",
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("return-file-path-hamlib_rigctld_path", (event, data) => {
|
ipcRenderer.on("return-file-path-hamlib_rigctld_path", (event, data) => {
|
||||||
|
@ -1070,24 +1072,30 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// enable enable_request_shared_folder switch clicked
|
// enable enable_request_shared_folder switch clicked
|
||||||
document.getElementById("enable_request_shared_folder").addEventListener("click", () => {
|
document
|
||||||
if (document.getElementById("enable_request_shared_folder").checked == true) {
|
.getElementById("enable_request_shared_folder")
|
||||||
config.enable_request_shared_folder = "True";
|
.addEventListener("click", () => {
|
||||||
} else {
|
if (
|
||||||
config.enable_request_shared_folder = "False";
|
document.getElementById("enable_request_shared_folder").checked == true
|
||||||
}
|
) {
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
config.enable_request_shared_folder = "True";
|
||||||
});
|
} else {
|
||||||
|
config.enable_request_shared_folder = "False";
|
||||||
|
}
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
});
|
||||||
|
|
||||||
// enable enable_request_profile switch clicked
|
// enable enable_request_profile switch clicked
|
||||||
document.getElementById("enable_request_profile").addEventListener("click", () => {
|
document
|
||||||
if (document.getElementById("enable_request_profile").checked == true) {
|
.getElementById("enable_request_profile")
|
||||||
config.enable_request_profile = "True";
|
.addEventListener("click", () => {
|
||||||
} else {
|
if (document.getElementById("enable_request_profile").checked == true) {
|
||||||
config.enable_request_profile = "False";
|
config.enable_request_profile = "True";
|
||||||
}
|
} else {
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
config.enable_request_profile = "False";
|
||||||
});
|
}
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
});
|
||||||
|
|
||||||
// Tuning range clicked
|
// Tuning range clicked
|
||||||
document.getElementById("tuning_range_fmin").addEventListener("click", () => {
|
document.getElementById("tuning_range_fmin").addEventListener("click", () => {
|
||||||
|
|
|
@ -582,7 +582,7 @@
|
||||||
|
|
||||||
<!-- user shared folder -->
|
<!-- user shared folder -->
|
||||||
<div
|
<div
|
||||||
class="modal fade "
|
class="modal fade"
|
||||||
id="sharedFolderModal"
|
id="sharedFolderModal"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
aria-labelledby="sharedFolderModalLabel"
|
aria-labelledby="sharedFolderModalLabel"
|
||||||
|
@ -593,18 +593,15 @@
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h1 class="modal-title fs-5" id="sharedFolderModalLabel">
|
<h1 class="modal-title fs-5" id="sharedFolderModalLabel">
|
||||||
My Shared folder
|
My Shared folder
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
id="openSharedFilesFolder"
|
id="openSharedFilesFolder"
|
||||||
><i class="bi bi-archive"></i></button>
|
>
|
||||||
|
<i class="bi bi-archive"></i>
|
||||||
|
</button>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn-close"
|
class="btn-close"
|
||||||
|
@ -614,23 +611,20 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<!-- START OF TABLE FOR HEARD STATIONS -->
|
<!-- START OF TABLE FOR HEARD STATIONS -->
|
||||||
<table class="table table-sm">
|
<table class="table table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">#</th>
|
<th scope="col">#</th>
|
||||||
<th scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th scope="col">Type</th>
|
<th scope="col">Type</th>
|
||||||
<th scope="col">Size</th>
|
<th scope="col">Size</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="sharedFolderTable">
|
<tbody id="sharedFolderTable"></tbody>
|
||||||
|
</table>
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1870,7 +1870,6 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="input-group input-group-sm mb-1">
|
<div class="input-group input-group-sm mb-1">
|
||||||
<label class="input-group-text w-50"
|
<label class="input-group-text w-50"
|
||||||
>Allow requesting "shared folder"</label
|
>Allow requesting "shared folder"</label
|
||||||
|
@ -1886,7 +1885,6 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="input-group input-group-sm mb-1">
|
<div class="input-group input-group-sm mb-1">
|
||||||
<label class="input-group-text w-50"
|
<label class="input-group-text w-50"
|
||||||
>Shared folder path</label
|
>Shared folder path</label
|
||||||
|
@ -1897,15 +1895,6 @@
|
||||||
id="shared_folder_path"
|
id="shared_folder_path"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!--Rigctl tab contents-->
|
<!--Rigctl tab contents-->
|
||||||
<div
|
<div
|
||||||
|
|
Loading…
Reference in a new issue