Skip to content

Commit

Permalink
Refactor edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 28, 2021
1 parent c393e6c commit 32d4c28
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
12 changes: 6 additions & 6 deletions app/edit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ <h4>You can edit or delete your existing codes and you can add more codes.</h4>
<div class="bg-gray-700 w-3/5 m-auto mt-20 mb-60 rounded-2xl relative text-center p-1">
<!-- rollback -->
<div class="mx-auto rounded-2xl hidden bg-gray-800 w-2/3 rollback mt-20">
<h2 id="rollbackText" class="pt-5">Rollback</h2>
<h3>You can rollback to the latest save. If you load your codes below it will overwrite the current save!</h3>
<h3 id="rollbackText" class="pt-5">Rollback</h3>
<h4>You can rollback to the latest save. If you load your codes below it will overwrite the current save!</h4>
<button class="buttoni mb-5" onclick="loadRollback()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
Expand All @@ -48,8 +48,8 @@ <h3>You can rollback to the latest save. If you load your codes below it will ov
</div>
<!-- load codes -->
<div class="mx-auto rounded-2xl bg-gray-800 w-2/3 mb-20 mt-20 beforeLoad">
<h2 id="rollbackBut" class="pt-5">Load saved codes</h2>
<h3>You can load the 2FA codes you saved. After that you can edit or delete them and you can add more codes.</h3>
<h3 id="rollbackBut" class="pt-5">Load saved codes</h3>
<h4>You can load the 2FA codes you saved. After that you can edit or delete them and you can add more codes.</h4>
<button class="buttoni mb-5" onclick="loadCodes()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" />
Expand All @@ -60,8 +60,8 @@ <h3>You can load the 2FA codes you saved. After that you can edit or delete them
<!-- save codes and add codes -->
<div class="afterLoad hidden">
<div class="mx-auto rounded-2xl bg-gray-800 w-2/3 mt-20 mb-20">
<h2 id="rollbackBut" class="pt-5">Edit mode</h2>
<h3>Now you can modify existing codes or add more codes.</h3>
<h3 id="rollbackBut" class="pt-5">Edit mode</h3>
<h4>Now you can modify existing codes or add more codes.</h4>
<div class="flex flex-row justify-center gap-3 flex-wrap pb-5">
<button class="buttoni" onclick="createSave()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
Expand Down
54 changes: 38 additions & 16 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
const { app, dialog } = require("@electron/remote")
const { aes, convert, time } = require("@levminer/lib")
const logger = require("@levminer/lib/logger/renderer")
const fs = require("fs")
const electron = require("electron")
const ipc = electron.ipcRenderer
const { app, dialog } = require("@electron/remote")
const { ipcRenderer: ipc } = require("electron")
const path = require("path")
const fs = require("fs")

// ? error in window
/**
* Send error to main process
*/
window.onerror = (error) => {
ipc.send("rendererError", { renderer: "edit", error: error })
}

// ? logger
/**
* Start logger
*/
logger.getWindow("edit")

// ? if development
/**
* Check if running in development
*/
let dev = false

if (app.isPackaged === false) {
Expand Down Expand Up @@ -61,7 +66,9 @@ if (res.build_number.startsWith("alpha")) {
document.querySelector(".build").style.display = "block"
}

// ? rollback
/**
* Check for latest rollback
*/
const cache_path = path.join(folder_path, "rollbacks")
const rollback_con = document.querySelector(".rollback")
const rollback_text = document.querySelector("#rollbackText")
Expand Down Expand Up @@ -131,7 +138,9 @@ const loadRollback = () => {
})
}

// ? separate value
/**
* Init arrays
*/
const names = []
const secrets = []
const issuers = []
Expand Down Expand Up @@ -178,7 +187,7 @@ const go = () => {
div.innerHTML = `
<div id="grid${[counter]}" class="flex flex-col md:w-4/5 lg:w-2/3 mx-auto rounded-2xl bg-gray-800 mb-20">
<div class="flex justify-center items-center">
<h2 id="names${[counter]}">Name</h2>
<h3 id="names${[counter]}">Name</h3>
</div>
<div class="flex justify-center items-center">
<input class="input w-[320px]" type="text" id="edit_inp_${[counter]}" value="${names[counter]}" readonly/>
Expand Down Expand Up @@ -209,8 +218,11 @@ const go = () => {
save_text = ""
}

// ? edit
/**
* Edit mode
*/
let edit_mode = false

const edit = (number) => {
const edit_but = document.querySelector(`#edit_but_${number}`)
const edit_inp = document.querySelector(`#edit_inp_${number}`)
Expand Down Expand Up @@ -242,7 +254,9 @@ const edit = (number) => {
}
}

// ? delete
/**
* Delete specified code
*/
const del = (number) => {
const del_but = document.querySelector(`#del_but_${number}`)

Expand Down Expand Up @@ -278,7 +292,9 @@ const del = (number) => {
})
}

// ? create save
/**
* Confirm saving modifications
*/
let save_text = ""

const createSave = () => {
Expand Down Expand Up @@ -471,7 +487,9 @@ const createRollback = () => {
})
}

// ? error handling
/**
* No saved codes found
*/
const loadError = () => {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", (err, data) => {
if (err) {
Expand Down Expand Up @@ -614,12 +632,16 @@ const loadCodes = () => {
}
}

// ? hide window
/**
* Hide window
*/
const hide = () => {
ipc.send("toggleEdit")
}

// ? reloads
/**
* Send reload events
*/
const reloadApplication = () => {
ipc.send("reloadApplicationWindow")
}
Expand Down

0 comments on commit 32d4c28

Please sign in to comment.