From 4882b825297e171df51721e0ec015644359e1c81 Mon Sep 17 00:00:00 2001 From: PaulaBras <68814660+PaulaBras@users.noreply.github.com> Date: Fri, 30 Dec 2022 18:13:11 +0100 Subject: [PATCH] changed systemsettings, WIP still, new structure --- updater/.gitignore | 4 + updater/package.json | 21 ++-- updater/src/index.css | 23 ++++ updater/src/index.html | 28 ++++- updater/src/index.js | 4 +- updater/src/renderer.js | 236 ++++++++++++++++++++++++---------------- updater/systemfile.json | 2 +- 7 files changed, 204 insertions(+), 114 deletions(-) diff --git a/updater/.gitignore b/updater/.gitignore index 8e3a106..307273c 100644 --- a/updater/.gitignore +++ b/updater/.gitignore @@ -1,3 +1,7 @@ +# Programm JSON files +systemfile.json +settings.json + # Logs logs *.log diff --git a/updater/package.json b/updater/package.json index 4af065b..460455f 100644 --- a/updater/package.json +++ b/updater/package.json @@ -1,8 +1,8 @@ { - "name": "updater", - "productName": "updater", - "version": "1.0.0", - "description": "My Electron application description", + "name": "sectorfile_updater", + "productName": "Sectorfile Updater", + "version": "0.0.1", + "description": "This application allows users to easily update and maintain their sector files. It offers a simple, intuitive interface for downloading and installing the latest version of sector files, ensuring that users have access to the most accurate and up-to-date data. With automatic update checks and notifications, users can rest assured that their sector files are always up-to-date and ready for use.", "main": "src/index.js", "scripts": { "start": "electron-forge start", @@ -12,16 +12,15 @@ "lint": "echo \"No linting configured\"" }, "keywords": [], - "author": { - "name": "Julian", - "email": "JustusPlays78@gmail.com" - }, + "authors": [ + "Julian ", + "Paul " + ], "license": "MIT", "config": { "forge": { "packagerConfig": {}, - "makers": [ - { + "makers": [{ "name": "@electron-forge/maker-squirrel", "config": { "name": "updater" @@ -61,4 +60,4 @@ "@electron-forge/maker-zip": "^6.0.0-beta.66", "electron": "^21.0.1" } -} +} \ No newline at end of file diff --git a/updater/src/index.css b/updater/src/index.css index 6a4607d..2bea3ee 100644 --- a/updater/src/index.css +++ b/updater/src/index.css @@ -3,4 +3,27 @@ body { margin: auto; max-width: 38rem; padding: 2rem; +} + +.tooltip { + position: relative; + display: inline-block; + border-bottom: 1px dotted black; +} + +.tooltip .tooltiptext { + visibility: hidden; + width: 450px; + background-color: black; + color: #fff; + text-align: center; + border-radius: 6px; + padding: 5px 0; + /* Position the tooltip */ + position: absolute; + z-index: 1; +} + +.tooltip:hover .tooltiptext { + visibility: visible; } \ No newline at end of file diff --git a/updater/src/index.html b/updater/src/index.html index c7bc71c..6ff6f71 100644 --- a/updater/src/index.html +++ b/updater/src/index.html @@ -6,10 +6,7 @@ - - -

Output Test here

Input URL

@@ -20,10 +17,33 @@ - + +
+
+

Username

+ + +

Password

+ + +

Password Hoppie

+ + + Please be aware that the password you enter will be stored in plain + text in our system. This means that it will not be encrypted or + otherwise secured. We recommend that you do not use a password that + you also use for other important accounts, such as your email or + banking. Please use caution when entering your password and consider + using a unique and strong password specifically for this + account. +
+
+ diff --git a/updater/src/index.js b/updater/src/index.js index 6039d47..af61c05 100644 --- a/updater/src/index.js +++ b/updater/src/index.js @@ -58,12 +58,12 @@ const createWindow = () => { }*/ // Select Directory - ipcMain.on('select-dirs', async(event, arg) => { + ipcMain.on('app-path', async(event, arg) => { filepath = await dialog.showOpenDialog(mainWindow, { properties: ['openDirectory'] }); console.log('directories selected', filepath.filePaths); - mainWindow.webContents.send("path selected", filepath.filePaths); + mainWindow.webContents.send("app-path", filepath.filePaths); // Save directory to file }); diff --git a/updater/src/renderer.js b/updater/src/renderer.js index c0e180f..21f163f 100644 --- a/updater/src/renderer.js +++ b/updater/src/renderer.js @@ -1,104 +1,104 @@ -const { ipcRenderer, dialog } = require('electron'); +const { ipcRenderer, dialog, app } = require('electron'); const superagent = require('superagent').agent(); var fs = require('fs'); var DecompressZip = require('decompress-zip'); +const { version } = require('os'); // Global Variabels +let dirBox = document.getElementById('dirs'); +let usernameInput = document.getElementById('username'); +let passwordInput = document.getElementById('password'); +let passwordhoppieInput = document.getElementById('passwordhoppie'); -let systempath = "systemfile.json"; -let userFile = "\\userfile.json"; -var userjson = { +// CheckBox Events +let checkBoxUsername = document.getElementById('saveuser'); +let checkBoxPassword = document.getElementById('savepw'); +let checkBoxSavepwhoppie = document.getElementById('savepwhoppie'); + +const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); +let systempath = "systemfile.json"; // soll weg +let userFile = "userfile.json"; // soll weg +var systemstructure = { + path: "" +}; +var structure = { region: 0, file: 0, + installcreds: false, // Not yet implemented + installhoppie: false, // Not yet implemented cid: { save: true, - id: 0 + id: -1 }, password: { save: true, - pass: "NaN" + pass: "" }, - currentInstalledAirac: 0 -}; - -var systemJson = { - userpath: "" + passwordhoppie: { + save: true, + pass: "" + }, + currentInstalledAirac: 0, + version: "v1" }; document.addEventListener('DOMContentLoaded', function() { // Seems to work (tm) firstStart(); - save(); }, false); +let systemsettings = "system.json"; +let settings = "settings.json"; +var filepath; +async function firstStart() { + await ipcRenderer.send('app-path'); + await ipcRenderer.on("app-path", async(event, path) => { + filepath = path; + // await delay(2000); // Not the best solution + // filepath = await app.getPath('home') + '\\' + systemsettings; + await console.log(filepath + "\\" + systemsettings); + if (await fs.existsSync(filepath + "\\" + systemsettings)) { + systemstructure = JSON.parse(fs.readFileSync(filepath + "\\" + systemsettings, 'utf8')); + } else { + await changeUserpath(); + } + await console.log(systemstructure); + await console.log("test"); + if (await fs.existsSync(systemstructure.path + "\\" + settings)) { + structure = JSON.parse(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8')); + if (structure.cid.save == true) { + usernameInput.value = structure.cid.id; + } + if (structure.password.save == true) { + passwordInput.value = structure.password.pass; + } + if (structure.passwordhoppie.save == true) { + passwordhoppieInput.value = structure.passwordhoppie.pass; + } + dirBox.value = systemstructure.path; + // GET INFO -let firstStart = () => { - try { - const data = fs.readFileSync(systempath, 'utf8'); - } catch (err) { - // Create file - fs.writeFile(systempath, JSON.stringify(systemJson), { flag: 'wx' }, function(err) { - if (err) throw err; - }); - } + } else { + fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8'); + gng.selectedIndex = structure.region; + if (files.selectedIndex < 0) { + files.selectedIndex = 0; + } else { + files.selectedIndex = structure.file; + } + // Broken - var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8')); - - try { - const data = fs.readFileSync(systemReadJson.userpath + userFile, 'utf8'); - userjson = data; - } catch (err) { - // Create file - changeUserpath(); - } finally { - var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8')); - getUpdates(); - // Set from file does not work - gng.selectedIndex = userReadJson.region; + } + await getUpdates(); + gng.selectedIndex = structure.region; if (files.selectedIndex < 0) { files.selectedIndex = 0; } else { - files.selectedIndex = userReadJson.file; + files.selectedIndex = structure.file; } + await getFiles(); save(); - } -} -let changeUserpath = () => { - ipcRenderer.send('select-dirs'); // DOES NOT WORK! -} -ipcRenderer.on("path selected", (event, value) => { - var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8')); - systemReadJson.userpath = value[0]; - fs.writeFile(systemReadJson.userpath + userFile, JSON.stringify(userjson), function(err) { - if (err) throw err; }); - fs.writeFile(systempath, JSON.stringify(systemReadJson), function(err) { - if (err) throw err; - }); -}) - -ipcRenderer.on("download progress", (event, progress) => { - const cleanProgressInPercentages = Math.floor(progress.percent * 100); // Without decimal point - document.getElementById('progressbar').value = cleanProgressInPercentages; -}); - -let downloadBtn = document.getElementById('download'); -downloadBtn.addEventListener('click', (e) => { - var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8')); - var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8')); - downloadFile(files.options[files.selectedIndex].href, systemReadJson.userpath); -}); -let directoryBtn = document.getElementById('dirs'); -directoryBtn.addEventListener('click', (e) => {}); -ipcRenderer.on("filepath", (event, file) => { - document.getElementById('dirBox').value = file; -}); - -let testBtn = document.getElementById('test'); -testBtn.addEventListener('click', (e) => { - var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8')); - var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8')); - decompress(files.options[files.selectedIndex].href, systemReadJson.userpath) -}); +} // Save Event gng.addEventListener("change", () => { @@ -109,14 +109,38 @@ files.addEventListener("change", () => { save(); }); -let save = () => { - var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8')); - var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8')); - userReadJson.region = gng.selectedIndex; - userReadJson.file = files.selectedIndex; - fs.writeFile(systemReadJson.userpath + userFile, JSON.stringify(userReadJson), function(err) { - if (err) throw err; - }); +function save() { + // WORK HERE, new files + // Read config + structure = JSON.parse(fs.readFileSync(systempath.path + userFile, 'utf8')); + structure.region = gng.selectedIndex; + structure.file = files.selectedIndex; + if (checkBoxUsername.checked == true) { + structure.cid.id = usernameInput.value; + structure.cid.save = true; + } else { + structure.cid.id = -1; + structure.cid.save = false; + } + if (checkBoxPassword.checked == true) { + structure.password.pass = passwordInput.value; + structure.password.save = true; + } else { + structure.password.pass = ""; + structure.password.save = false; + } + if (checkBoxSavepwhoppie.checked == true) { + structure.passwordhoppie.pass = passwordhoppieInput.value; + structure.passwordhoppie.save = true; + } else { + structure.passwordhoppie.pass = ""; + structure.passwordhoppie.save = false; + } + // WIP + //structure.currentInstalledAirac = currentAirac; + //structure.version = airacversion; + // Save config + fs.writeFileSync(systemstructure.path + "\\" + userFile, JSON.stringify(structure, null, 4), 'utf8'); }; // Check update @@ -130,16 +154,14 @@ updateBtn.addEventListener('click', () => { }); // Remove all files when changing Region --> WIP no nicht -const removeFileItems = () => { +function removeFileItems() { var i, L = dropDownFiles.options.length - 1; for (i = L; i >= 0; i--) { dropDownFiles.remove(i); } } -const getUpdates = async() => { - - +async function getUpdates() { // Get all GNG Options const courses = await superagent.get('https://files.aero-nav.com/'); let text = courses.text.split("Download Pages").pop(); @@ -170,14 +192,7 @@ const getUpdates = async() => { getFiles(); } -// Check Files -let getFilesBtn = document.getElementById('getFiles'); -getFilesBtn.addEventListener('click', (e) => { - hrefLinks = getFiles(); - console.log("leaveme alone " + hrefLinks); -}); - -const getFiles = async() => { +async function getFiles() { removeFileItems(); // Get all GNG Package Options let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text; @@ -232,7 +247,7 @@ const getFiles = async() => { } -let downloadFile = (source, path) => { +function downloadFile(source, path) { console.log(source) const zipFile = source.split('/').pop(); @@ -248,7 +263,7 @@ let downloadFile = (source, path) => { } // Unzip file -let decompress = (url, DESTINATION_PATH) => { +function decompress(url, DESTINATION_PATH) { let file = url.split('/').pop() var ZIP_FILE_PATH = DESTINATION_PATH + "\\" + file; DESTINATION_PATH += "\\" + file.split('.')[0]; @@ -275,4 +290,33 @@ let decompress = (url, DESTINATION_PATH) => { unzipper.extract({ path: DESTINATION_PATH }); -} \ No newline at end of file +} + + + +function changeUserpath() { + ipcRenderer.send('app-path'); +} + +ipcRenderer.on("app-path", (event, value) => { + systemstructure.path = value[0]; + fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8'); +}) + +ipcRenderer.on("download progress", (event, progress) => { + const cleanProgressInPercentages = Math.floor(progress.percent * 100); // Without decimal point + document.getElementById('progressbar').value = cleanProgressInPercentages; +}); + +// let downloadBtn = document.getElementById('download'); +// downloadBtn.addEventListener('click', (e) => { +// var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8')); +// var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + userFile, 'utf8')); +// downloadFile(files.options[files.selectedIndex].href, systemReadJson.path); +// }); +let testBtn = document.getElementById('test'); +testBtn.addEventListener('click', (e) => { + var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8')); + var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + userFile, 'utf8')); + decompress(files.options[files.selectedIndex].href, systemReadJson.path) +}); \ No newline at end of file diff --git a/updater/systemfile.json b/updater/systemfile.json index 41ce199..d7e76f3 100644 --- a/updater/systemfile.json +++ b/updater/systemfile.json @@ -1 +1 @@ -{"userpath":"F:\\02 Benutzer\\Chef\\Desktop"} \ No newline at end of file +{ "path": "F:\\02 Benutzer\\Chef\\Dokumente\\00 Git\\sectorfileupdater\\updater" } \ No newline at end of file