From cf6573bb0d9de414347975de0e7d094d50659cf7 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Tue, 28 Feb 2023 12:55:54 +0000 Subject: [PATCH] Prettified Code! --- gui/main.js | 47 +++++++++++------------- gui/preload-chat.js | 79 ++++++++++++++++++---------------------- gui/preload-main.js | 78 +++++++++++++++++++++------------------ gui/src/chat-module.html | 48 +++++++++++------------- gui/src/index.html | 11 ------ 5 files changed, 121 insertions(+), 142 deletions(-) diff --git a/gui/main.js b/gui/main.js index 4eca4750..0913fac5 100644 --- a/gui/main.js +++ b/gui/main.js @@ -547,39 +547,36 @@ ipcMain.on("select-user-image", (event, data) => { }); }); - // read files in folder - use case "shared folder" ipcMain.on("read-files-in-folder", (event, data) => { + let fileList = []; - let fileList = [] - - let folder = data.folder - let files = fs.readdirSync(folder); - console.log(folder) -console.log(files) - files.forEach(file => { - try{ - let filePath = folder + '/' + file; - if(fs.lstatSync(filePath).isFile()){ - let fileSizeInBytes = fs.statSync(filePath).size + let folder = data.folder; + let files = fs.readdirSync(folder); + console.log(folder); + console.log(files); + files.forEach((file) => { + try { + let filePath = folder + "/" + file; + if (fs.lstatSync(filePath).isFile()) { + let fileSizeInBytes = fs.statSync(filePath).size; let extension = path.extname(filePath); - fileList.push({ name: file, extension: extension.substring(1), size: fileSizeInBytes }); - } - } catch(err){ - console.log(err) - } - - - }); - - chat.webContents.send("return-shared-folder-files", { - files: fileList, + fileList.push({ + name: file, + extension: extension.substring(1), + size: fileSizeInBytes, }); + } + } catch (err) { + console.log(err); + } + }); + chat.webContents.send("return-shared-folder-files", { + files: fileList, + }); }); - - //save file to folder ipcMain.on("save-file-to-folder", (event, data) => { console.log(data.file); diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 6df16a85..cfd02116 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -397,14 +397,14 @@ window.addEventListener("DOMContentLoaded", () => { }); }); - // open file selector for shared folder - document.getElementById("sharedFolderButton").addEventListener("click", () => { - ipcRenderer.send("read-files-in-folder", { - folder: config.shared_folder_path, + document + .getElementById("sharedFolderButton") + .addEventListener("click", () => { + ipcRenderer.send("read-files-in-folder", { + folder: config.shared_folder_path, + }); }); - }); - document .getElementById("openSharedFilesFolder") @@ -414,7 +414,6 @@ window.addEventListener("DOMContentLoaded", () => { }); }); - // SEND MSG document.getElementById("sendMessage").addEventListener("click", () => { 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) => { - console.log(arg) + console.log(arg); var tbl = document.getElementById("sharedFolderTable"); tbl.innerHTML = ""; - let counter = 0 - arg.files.forEach(file => { - console.log(file["name"]); - var row = document.createElement("tr"); + let counter = 0; + arg.files.forEach((file) => { + console.log(file["name"]); + var row = document.createElement("tr"); - let id = document.createElement("td"); - let idText = document.createElement("span"); - idText.innerText = counter+=1; - id.appendChild(idText); - row.appendChild(id); + let id = document.createElement("td"); + let idText = document.createElement("span"); + idText.innerText = counter += 1; + id.appendChild(idText); + 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 filenameText = document.createElement("span"); - filenameText.innerText = file["name"]; - filename.appendChild(filenameText); - row.appendChild(filename); - - let filetype = document.createElement("td"); - let filetypeText = document.createElement("span"); - filetypeText.innerHTML = ` - + let filetype = document.createElement("td"); + let filetypeText = document.createElement("span"); + filetypeText.innerHTML = ` + `; - filetype.appendChild(filetypeText); - row.appendChild(filetype); + filetype.appendChild(filetypeText); + row.appendChild(filetype); - let filesize = document.createElement("td"); - let filesizeText = document.createElement("span"); - filesizeText.innerText = file["size"]; - filesize.appendChild(filesizeText); - row.appendChild(filesize); - - - tbl.appendChild(row); + let filesize = document.createElement("td"); + let filesizeText = document.createElement("span"); + filesizeText.innerText = file["size"]; + filesize.appendChild(filesizeText); + row.appendChild(filesize); + tbl.appendChild(row); }); - - }); - ipcRenderer.on("return-select-user-image", (event, arg) => { let imageFiletype = arg.mime; let imageFile = arg.data; @@ -793,11 +786,9 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filetype = "null"; obj.file = "null"; - if(config.enable_request_profile == "True"){ - sendUserData(item.dxcallsign); + if (config.enable_request_profile == "True") { + sendUserData(item.dxcallsign); } - - } else if (splitted_data[1] == "res") { obj.uuid = uuidv4().toString(); obj.timestamp = Math.floor(Date.now() / 1000); diff --git a/gui/preload-main.js b/gui/preload-main.js index c0d10427..b6ac1cef 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -165,12 +165,15 @@ window.addEventListener("DOMContentLoaded", () => { action: "return-folder-paths-received_files_folder", }); - ipcRenderer.on("return-folder-paths-received_files_folder", (event, data) => { - document.getElementById("received_files_folder").value = - data.path.filePaths[0]; - config.received_files_folder = data.path.filePaths[0]; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); + ipcRenderer.on( + "return-folder-paths-received_files_folder", + (event, data) => { + document.getElementById("received_files_folder").value = + data.path.filePaths[0]; + config.received_files_folder = data.path.filePaths[0]; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + } + ); }); document @@ -181,15 +184,17 @@ window.addEventListener("DOMContentLoaded", () => { action: "return-folder-paths-shared_folder_path", }); - ipcRenderer.on("return-folder-paths-shared_folder_path", (event, data) => { - document.getElementById("shared_folder_path").value = - data.path.filePaths[0]; - config.shared_folder_path = data.path.filePaths[0]; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); + ipcRenderer.on( + "return-folder-paths-shared_folder_path", + (event, data) => { + document.getElementById("shared_folder_path").value = + data.path.filePaths[0]; + config.shared_folder_path = data.path.filePaths[0]; + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + } + ); }); - document .getElementById("openReceivedFilesFolder") .addEventListener("click", () => { @@ -198,8 +203,6 @@ window.addEventListener("DOMContentLoaded", () => { }); }); - - /* // ENABLE BOOTSTRAP 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 = config.shared_folder_path; - if (config.enable_request_profile == "True") { + if (config.enable_request_profile == "True") { document.getElementById("enable_request_profile").checked = true; } else { 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; } else { document.getElementById("enable_request_shared_folder").checked = false; } - if (config.enable_is_writing == "True") { document.getElementById("enable_is_writing").checked = true; } else { @@ -591,7 +593,7 @@ window.addEventListener("DOMContentLoaded", () => { .addEventListener("click", () => { ipcRenderer.send("get-file-path", { 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) => { @@ -1070,24 +1072,30 @@ window.addEventListener("DOMContentLoaded", () => { }); // enable enable_request_shared_folder switch clicked - document.getElementById("enable_request_shared_folder").addEventListener("click", () => { - if (document.getElementById("enable_request_shared_folder").checked == true) { - config.enable_request_shared_folder = "True"; - } else { - config.enable_request_shared_folder = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); + document + .getElementById("enable_request_shared_folder") + .addEventListener("click", () => { + if ( + document.getElementById("enable_request_shared_folder").checked == true + ) { + 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 - document.getElementById("enable_request_profile").addEventListener("click", () => { - if (document.getElementById("enable_request_profile").checked == true) { - config.enable_request_profile = "True"; - } else { - config.enable_request_profile = "False"; - } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - }); + document + .getElementById("enable_request_profile") + .addEventListener("click", () => { + if (document.getElementById("enable_request_profile").checked == true) { + config.enable_request_profile = "True"; + } else { + config.enable_request_profile = "False"; + } + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + }); // Tuning range clicked document.getElementById("tuning_range_fmin").addEventListener("click", () => { diff --git a/gui/src/chat-module.html b/gui/src/chat-module.html index 6a67cf10..7e152c15 100644 --- a/gui/src/chat-module.html +++ b/gui/src/chat-module.html @@ -582,7 +582,7 @@ diff --git a/gui/src/index.html b/gui/src/index.html index efea2e60..a7e3ab80 100644 --- a/gui/src/index.html +++ b/gui/src/index.html @@ -1870,7 +1870,6 @@ -
-
- - - - - - - - -