further tried on read and write the config

This commit is contained in:
PaulaBras 2023-01-01 14:36:22 +01:00
parent 4882b82529
commit dd954dc760
3 changed files with 81 additions and 63 deletions

View File

@ -7,28 +7,36 @@
</head>
<body>
<button id="extract">Extract ZIP</button>
<p>Input URL</p>
<input type="text" id="urlBox" name="name" size="80" readonly />
<p>Input Directory</p>
<input type="text" id="dirBox" name="name" size="80" readonly />
<progress id="progressbar" max="100" value="0"></progress>
<button id="update">Check for update</button>
<select name="Dropme Down" id="gng"></select>
<select name="Dropme Down #2" id="files"></select>
<select id="gng"></select>
<select id="files"></select>
<button id="test">Test BTN</button>
<div id="login">
<div class="tooltip">
<p>Username</p>
<input type="text" id="username" />
<input type="checkbox" id="saveuser" />
<div class="tooltip">
<p>Password</p>
<input type="password" id="password" />
<input type="checkbox" id="savepw" />
<span class="tooltiptext"
>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.</span
>
</div>
<div class="tooltip">
<p>Password Hoppie</p>
<input type="password" id="passwordhoppie" />
<input type="checkbox" id="savepwhoppie" />
@ -42,6 +50,7 @@
account.</span
>
</div>
<button id="savecred">Save your Credentials</button>
</div>
<script src="./renderer.js"></script>

View File

@ -62,7 +62,6 @@ const createWindow = () => {
filepath = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
});
console.log('directories selected', filepath.filePaths);
mainWindow.webContents.send("app-path", filepath.filePaths);
// Save directory to file
});

View File

@ -1,14 +1,14 @@
const { ipcRenderer, dialog, app } = require('electron');
const { ipcRenderer, 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 dirBox = document.getElementById('dirBox');
let usernameInput = document.getElementById('username');
let passwordInput = document.getElementById('password');
let passwordhoppieInput = document.getElementById('passwordhoppie');
let saveCredBtn = document.getElementById('savecred');
// CheckBox Events
let checkBoxUsername = document.getElementById('saveuser');
@ -16,8 +16,6 @@ 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: ""
};
@ -46,13 +44,14 @@ document.addEventListener('DOMContentLoaded', function() { // Seems to work (tm)
firstStart();
}, false);
let systemsettings = "system.json";
let systemsettings = "systemfile.json";
let settings = "settings.json";
var filepath;
var filepath = "F:\\02 Benutzer\\Chef\\Dokumente\\00 Git\\sectorfileupdater\\updater"; // Set to exe path ex: app.getPath('exe') + '\\' + systemsettings;
async function firstStart() {
await ipcRenderer.send('app-path');
await ipcRenderer.on("app-path", async(event, path) => {
filepath = path;
// 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);
@ -61,8 +60,6 @@ async function firstStart() {
} 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) {
@ -74,8 +71,16 @@ async function firstStart() {
if (structure.passwordhoppie.save == true) {
passwordhoppieInput.value = structure.passwordhoppie.pass;
}
if (structure.cid.save == true) {
checkBoxUsername.checked = true;
}
if (structure.password.save == true) {
checkBoxPassword.checked = true;
}
if (structure.passwordhoppie.save == true) {
checkBoxSavepwhoppie.checked = true;
}
dirBox.value = systemstructure.path;
// GET INFO
} else {
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
@ -95,9 +100,9 @@ async function firstStart() {
} else {
files.selectedIndex = structure.file;
}
await removeFileItems();
await getFiles();
save();
});
}
// Save Event
@ -112,7 +117,7 @@ files.addEventListener("change", () => {
function save() {
// WORK HERE, new files
// Read config
structure = JSON.parse(fs.readFileSync(systempath.path + userFile, 'utf8'));
structure = JSON.parse(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8'));
structure.region = gng.selectedIndex;
structure.file = files.selectedIndex;
if (checkBoxUsername.checked == true) {
@ -140,7 +145,7 @@ function save() {
//structure.currentInstalledAirac = currentAirac;
//structure.version = airacversion;
// Save config
fs.writeFileSync(systemstructure.path + "\\" + userFile, JSON.stringify(structure, null, 4), 'utf8');
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
};
// Check update
@ -193,7 +198,7 @@ async function getUpdates() {
}
async function getFiles() {
removeFileItems();
await removeFileItems();
// Get all GNG Package Options
let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text;
let courses = await superagent.get(region);
@ -300,6 +305,7 @@ function changeUserpath() {
ipcRenderer.on("app-path", (event, value) => {
systemstructure.path = value[0];
dirBox.value = value[0];
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
})
@ -310,13 +316,17 @@ ipcRenderer.on("download progress", (event, progress) => {
// 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'));
// var systemReadJson = JSON.parse(fs.readFileSync(systemsettings, 'utf8'));
// var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + settings, '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'));
var systemReadJson = JSON.parse(fs.readFileSync(systemsettings, 'utf8'));
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + settings, 'utf8'));
decompress(files.options[files.selectedIndex].href, systemReadJson.path)
});
saveCredBtn.addEventListener('click', (e) => {
save();
});