Skip to content

Commit

Permalink
Fixing preload settings folder and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Nov 22, 2021
1 parent e495f2f commit f3701c7
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,70 @@ const path = require("path")
const fs = require("fs")
const ipc = electron.ipcRenderer

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

if (app.isPackaged === false) {
dev = true
integrity = true
}

/**
* Get Authme folder path
*/
const folder_path = dev ? path.join(process.env.APPDATA, "Levminer", "Authme Dev") : path.join(process.env.APPDATA, "Levminer")
const folder_path = dev ? path.join(process.env.APPDATA, "Levminer", "Authme Dev") : path.join(process.env.APPDATA, "Levminer", "Authme")

/**
* Read settings
* @type {LibSettings}
*/
const file = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

// ? local storage
/**
* Load storage
* @type {LibStorage}
*/
let storage

if (integrity === false) {
if (dev === true) {
storage = JSON.parse(localStorage.getItem("dev_storage"))
} else {
storage = JSON.parse(localStorage.getItem("storage"))
}

// ? controller
/**
* App controller
*/
if (file.security.require_password === true && file.security.password !== null) {
ipc.send("to_confirm")
} else if (file.security.require_password === false && file.security.password === null) {
if (integrity === false) {
if (storage === null) {
ipc.send("abort")
if (storage === null) {
ipc.send("abort")

console.error("Authme - Local storage not found in controller")
} else {
console.log("Authme - Local storage found in controller")
}

if (file.security.require_password === storage.require_password) {
console.log("Passwords match")
console.error("Authme - Local storage not found in controller")
} else {
console.log("Authme - Local storage found in controller")
}

ipc.send("to_application1")
} else {
ipc.send("abort")
if (file.security.require_password === storage.require_password) {
console.log("Authme - Local storage passwords match")

console.error("Authme - Local storage not found in controller")
}
} else {
ipc.send("to_application1")
} else {
ipc.send("abort")

console.error("Authme - Local storage not found in controller")
}
} else if (file.security.require_password === null && file.security.password === null) {
console.log("Authme - First restart")
} else {
ipc.send("to_confirm")
}

// ? prevent default shortcuts
/**
* Prevent default shortcuts
*/
document.addEventListener("keydown", (event) => {
if (event.ctrlKey && event.code === "KeyA" && event.target.type !== "text" && event.target.type !== "number" && event.target.type !== "textarea" && event.target.type !== "password") {
event.preventDefault()
Expand All @@ -73,6 +78,8 @@ document.addEventListener("keydown", (event) => {
}
})

// prevent drag and drop
/**
* Prevent drag and drop
*/
document.addEventListener("dragover", (event) => event.preventDefault())
document.addEventListener("drop", (event) => event.preventDefault())

0 comments on commit f3701c7

Please sign in to comment.