Skip to content

Commit

Permalink
Refactor export
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 27, 2021
1 parent 7fee852 commit c393e6c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
16 changes: 8 additions & 8 deletions app/export/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h5 class="mx-3 flex flex-row m-0 font-bold build-content text-center">You are r
<div class="mx-auto rounded-2xl bg-gray-700 w-3/5 mt-40 text-center">
<img src="../../img/header.png" class="h-16 w-16 relative top-5" />
<h2>Export</h2>
<h4>You can export the codes you saved.</h4>
<h4>You can export the 2FA codes you saved.</h4>
<button class="buttoni mb-6" onclick="hide()">
<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="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
Expand All @@ -37,8 +37,8 @@ <h4>You can export the codes you saved.</h4>
<div class="bg-gray-700 w-3/5 m-auto mt-20 mb-60 rounded-2xl relative text-center p-1">
<!-- before export -->
<div class="before_export mx-auto rounded-2xl bg-gray-800 w-2/3 mt-20 mb-20">
<h2 class="pt-5">Export codes</h2>
<h3>If you saved your codes you can export the secrets and the saved QR codes.</h3>
<h3 class="pt-5">Export codes</h3>
<h4>If you saved your codes you can export the secrets and the saved QR codes.</h4>
<button class="buttoni but1 mb-5" id="but0" onclick="exportCodes()">
<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="M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4" />
Expand All @@ -49,8 +49,8 @@ <h3>If you saved your codes you can export the secrets and the saved QR codes.</
<!-- after export -->
<div class="after_export hidden">
<div class="mx-auto rounded-2xl bg-gray-800 w-2/3 mt-20 mb-20">
<h2 class="pt-5">Save exported codes</h2>
<h3>Save your exported 2FA codes to use it elsewhere.</h3>
<h3 class="pt-5">Save exported codes</h3>
<h4>Save your exported 2FA codes to use it elsewhere.</h4>
<div class="flex flex-row justify-center gap-3 flex-wrap">
<div>
<button class="buttoni" id="but1" onclick="newSaveFile()">
Expand All @@ -59,7 +59,7 @@ <h3>Save your exported 2FA codes to use it elsewhere.</h3>
</svg>
Export .authme file
</button>
<h5 class="m-3">Ideal to import for Authme or for Authme Web.</h5>
<h5 class="m-3">Ideal to import for Authme or other Authme apps.</h5>
</div>
<div>
<button class="buttoni" id="but2" onclick="saveQrCodes()">
Expand All @@ -68,7 +68,7 @@ <h5 class="m-3">Ideal to import for Authme or for Authme Web.</h5>
</svg>
Export .html file
</button>
<h5 class="m-3">Ideal for scanning QR codes or for security backup.</h5>
<h5 class="m-3">Ideal for scanning the QR codes or for security backup.</h5>
</div>
</div>

Expand All @@ -83,7 +83,7 @@ <h5 class="m-3">Ideal for scanning QR codes or for security backup.</h5>
</svg>
Export .txt file
</button>
<h5 class="m-3">The old way to import for Authme or for Authme Web.</h5>
<h5 class="m-3">The old way to import for Authme or other Authme apps.</h5>
</div>
</details>
</div>
Expand Down
45 changes: 31 additions & 14 deletions app/export/src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
const electron = require("electron")
const { app, dialog, shell } = require("@electron/remote")
const { aes, convert, time } = require("@levminer/lib")
const logger = require("@levminer/lib/logger/renderer")
const fs = require("fs")
const path = require("path")
const { app, dialog } = require("@electron/remote")
const { ipcRenderer: ipc } = require("electron")
const qrcode = require("qrcode-generator")
const ipc = electron.ipcRenderer
const path = require("path")
const fs = require("fs")

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

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

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

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

// ? init codes for save to qr codes
/**
* Init codes for save to qr codes
*/
const codes = []
let file

Expand Down Expand Up @@ -106,7 +113,9 @@ const go = (data) => {
}
}

// ? save file
/**
* Save .txt file
*/
const saveFile = () => {
dialog
.showSaveDialog({
Expand All @@ -133,7 +142,9 @@ const saveFile = () => {
})
}

// ? new save file
/**
* Save .authme file
*/
const newSaveFile = () => {
dialog
.showSaveDialog({
Expand Down Expand Up @@ -172,7 +183,9 @@ const newSaveFile = () => {
})
}

// ? save qr codes
/**
* Save .html file
*/
const saveQrCodes = () => {
dialog
.showSaveDialog({
Expand Down Expand Up @@ -205,12 +218,16 @@ const saveQrCodes = () => {
})
}

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

// ? error handling
/**
* No saved codes found
*/
const error = () => {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", (err, content) => {
if (err) {
Expand Down

0 comments on commit c393e6c

Please sign in to comment.