Prettified Code!

This commit is contained in:
DJ2LS 2023-02-28 12:55:54 +00:00 committed by GitHub Action
parent 90ce4acfce
commit cf6573bb0d
5 changed files with 121 additions and 142 deletions

View file

@ -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 folder = data.folder
let files = fs.readdirSync(folder); let files = fs.readdirSync(folder);
console.log(folder) console.log(folder);
console.log(files) console.log(files);
files.forEach(file => { files.forEach((file) => {
try { try {
let filePath = folder + '/' + file; let filePath = folder + "/" + file;
if (fs.lstatSync(filePath).isFile()) { if (fs.lstatSync(filePath).isFile()) {
let fileSizeInBytes = fs.statSync(filePath).size 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,
extension: extension.substring(1),
size: fileSizeInBytes,
});
} }
} catch (err) { } catch (err) {
console.log(err) console.log(err);
} }
}); });
chat.webContents.send("return-shared-folder-files", { chat.webContents.send("return-shared-folder-files", {
files: fileList, 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);

View file

@ -397,15 +397,15 @@ window.addEventListener("DOMContentLoaded", () => {
}); });
}); });
// open file selector for shared folder // open file selector for shared folder
document.getElementById("sharedFolderButton").addEventListener("click", () => { document
.getElementById("sharedFolderButton")
.addEventListener("click", () => {
ipcRenderer.send("read-files-in-folder", { ipcRenderer.send("read-files-in-folder", {
folder: config.shared_folder_path, folder: config.shared_folder_path,
}); });
}); });
document document
.getElementById("openSharedFilesFolder") .getElementById("openSharedFilesFolder")
.addEventListener("click", () => { .addEventListener("click", () => {
@ -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,12 +528,12 @@ 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");
@ -544,7 +543,6 @@ ipcRenderer.on("return-shared-folder-files", (event, arg) => {
id.appendChild(idText); id.appendChild(idText);
row.appendChild(id); row.appendChild(id);
let filename = document.createElement("td"); let filename = document.createElement("td");
let filenameText = document.createElement("span"); let filenameText = document.createElement("span");
filenameText.innerText = file["name"]; filenameText.innerText = file["name"];
@ -554,7 +552,7 @@ ipcRenderer.on("return-shared-folder-files", (event, arg) => {
let filetype = document.createElement("td"); let filetype = document.createElement("td");
let filetypeText = document.createElement("span"); let filetypeText = document.createElement("span");
filetypeText.innerHTML = ` filetypeText.innerHTML = `
<i class="bi bi-filetype-${file['extension']}" style="font-size: 1.8rem"></i> <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);
@ -565,15 +563,10 @@ ipcRenderer.on("return-shared-folder-files", (event, arg) => {
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;
@ -796,8 +789,6 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
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);

View file

@ -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(
"return-folder-paths-received_files_folder",
(event, data) => {
document.getElementById("received_files_folder").value = document.getElementById("received_files_folder").value =
data.path.filePaths[0]; data.path.filePaths[0];
config.received_files_folder = data.path.filePaths[0]; config.received_files_folder = data.path.filePaths[0];
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}); }
);
}); });
document document
@ -181,14 +184,16 @@ 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(
"return-folder-paths-shared_folder_path",
(event, data) => {
document.getElementById("shared_folder_path").value = document.getElementById("shared_folder_path").value =
data.path.filePaths[0]; data.path.filePaths[0];
config.shared_folder_path = data.path.filePaths[0]; config.shared_folder_path = data.path.filePaths[0];
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}
);
}); });
});
document document
.getElementById("openReceivedFilesFolder") .getElementById("openReceivedFilesFolder")
@ -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
@ -276,7 +279,6 @@ window.addEventListener("DOMContentLoaded", () => {
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,8 +1072,12 @@ 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")
.addEventListener("click", () => {
if (
document.getElementById("enable_request_shared_folder").checked == true
) {
config.enable_request_shared_folder = "True"; config.enable_request_shared_folder = "True";
} else { } else {
config.enable_request_shared_folder = "False"; config.enable_request_shared_folder = "False";
@ -1080,7 +1086,9 @@ window.addEventListener("DOMContentLoaded", () => {
}); });
// enable enable_request_profile switch clicked // enable enable_request_profile switch clicked
document.getElementById("enable_request_profile").addEventListener("click", () => { document
.getElementById("enable_request_profile")
.addEventListener("click", () => {
if (document.getElementById("enable_request_profile").checked == true) { if (document.getElementById("enable_request_profile").checked == true) {
config.enable_request_profile = "True"; config.enable_request_profile = "True";
} else { } else {

View file

@ -597,14 +597,11 @@
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,7 +611,6 @@
</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">
@ -626,9 +622,7 @@
<th scope="col">Size</th> <th scope="col">Size</th>
</tr> </tr>
</thead> </thead>
<tbody id="sharedFolderTable"> <tbody id="sharedFolderTable"></tbody>
</tbody>
</table> </table>
</div> </div>
</div> </div>

View file

@ -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