Skip to content

Commit

Permalink
Refactor import
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 27, 2021
1 parent 114be52 commit 7fee852
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
10 changes: 5 additions & 5 deletions app/import/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ <h4>
</h4>
</details>
<div class="flex flex-row justify-center gap-3 flex-wrap">
<button class="buttoni mb-5" onclick="qrImport()">
<button class="buttoni mb-8" onclick="qrImport()">
<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="M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z" />
</svg>
Choose image(s)
</button>
<button class="buttoni mb-5" onclick="qrCamera()">
<button class="buttoni mb-8" onclick="qrCamera()">
<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="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 13a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
Use webcam
</button>
<button class="buttoni mb-5 screenCapture hidden" onclick="qrScreen()">
<button class="buttoni mb-8 screenCapture hidden" onclick="qrScreen()">
<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 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
Expand Down Expand Up @@ -98,13 +98,13 @@ <h4>
</h4>
</details>
<div class="flex flex-row justify-center gap-3 flex-wrap">
<button class="buttoni mb-5" onclick="gaImport()">
<button class="buttoni mb-8" onclick="gaImport()">
<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="M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z" />
</svg>
Choose image(s)
</button>
<button class="buttoni mb-5" onclick="gaCamera()">
<button class="buttoni mb-8" onclick="gaCamera()">
<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="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 13a3 3 0 11-6 0 3 3 0 016 0z" />
Expand Down
39 changes: 23 additions & 16 deletions app/import/src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
const { app, dialog, shell, desktopCapturer, BrowserWindow } = require("@electron/remote")
const QrcodeDecoder = require("qrcode-decoder").default
const { qrcodeConverter, time } = require("@levminer/lib")
const logger = require("@levminer/lib/logger/renderer")
const electron = require("electron")
const QrcodeDecoder = require("qrcode-decoder").default
const { ipcRenderer: ipc } = require("electron")
const path = require("path")
const fs = require("fs")
const { qrcodeConverter, time } = require("@levminer/lib")
const ipc = electron.ipcRenderer

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

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

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

if (app.isPackaged === false) {
Expand All @@ -36,7 +41,9 @@ const folder_path = dev ? path.join(app.getPath("appData"), "Levminer", "Authme
*/
const settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

// ? check for webcam
/**
* Check for available webcam
*/
const checkWebcam = (callback) => {
const md = navigator.mediaDevices
if (!md || !md.enumerateDevices) return callback(false)
Expand All @@ -45,20 +52,20 @@ const checkWebcam = (callback) => {
})
}

// ? link
const onlineDocs = () => {
shell.openExternal("https://docs.authme.levminer.com/#/import?id=import")
}

/**
* Links
*/
const qrLink = () => {
shell.openExternal("https://docs.authme.levminer.com/#/import?id=qr-codes")
shell.openExternal("https://docs.authme.levminer.com/#/import?id=import")
}

const gaLink = () => {
shell.openExternal("https://docs.authme.levminer.com/#/import?id=google-authenticator")
shell.openExternal("https://docs.authme.levminer.com/#/import?id=advanced-import")
}

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

0 comments on commit 7fee852

Please sign in to comment.