Skip to content

Commit

Permalink
Migrate to async ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Feb 7, 2022
1 parent 186deda commit f906b43
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 155 deletions.
33 changes: 17 additions & 16 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,12 @@ const showInfo = () => {
/**
* Save imported codes to disk
*/
const saveCodes = () => {
const saveCodes = async () => {
let password
let key

if (settings.security.require_password === true) {
password = Buffer.from(ipc.sendSync("request_password"))
password = Buffer.from(await ipc.invoke("request_password"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
/**
Expand Down Expand Up @@ -605,12 +605,12 @@ const saveCodes = () => {
/**
* Load saved codes from disk
*/
const loadCodes = () => {
const loadCodes = async () => {
let password
let key

if (settings.security.require_password === true) {
password = Buffer.from(ipc.sendSync("request_password"))
password = Buffer.from(await ipc.invoke("request_password"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
/**
Expand Down Expand Up @@ -751,21 +751,22 @@ const quickCopy = (key) => {
}

/**
* Get app information
* Build number
*/
const res = ipc.sendSync("info")

/**
* Show build number if version is pre release
*/
if (res.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
} else if (res.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
const buildNumber = async () => {
const info = await ipc.invoke("info")

if (info.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
} else if (info.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
}
}

buildNumber()

/**
* Buttons
*/
Expand Down
23 changes: 12 additions & 11 deletions app/confirm/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,22 @@ const folder_path = dev ? path.join(app.getPath("appData"), "Levminer", "Authme
let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

/**
* Get app information
* Build number
*/
const res = ipc.sendSync("info")
const buildNumber = async () => {
const info = await ipc.invoke("info")

/**
* Show build number if version is pre release
*/
if (res.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
} else if (res.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
if (info.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
} else if (info.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
}
}

buildNumber()

/**
* Get info text
*/
Expand Down
145 changes: 71 additions & 74 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,22 @@ const settings_refresher = setInterval(() => {
}, 100)

/**
* Get app information
* Build number
*/
const res = ipc.sendSync("info")

/**
* Show build number if version is pre release
*/
if (res.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
} else if (res.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
const buildNumber = async () => {
const info = await ipc.invoke("info")

if (info.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
} else if (info.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
}
}

buildNumber()

/**
* Check for latest rollback
*/
Expand Down Expand Up @@ -358,12 +359,12 @@ const createSave = () => {
/**
* Saves the modifications made to the codes
*/
const saveModifications = () => {
const saveModifications = async () => {
let password
let key

if (settings.security.require_password === true) {
password = Buffer.from(ipc.sendSync("request_password"))
password = Buffer.from(await ipc.invoke("request_password"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
/**
Expand Down Expand Up @@ -519,78 +520,74 @@ const loadError = () => {
/**
* Loads saved codes from disk
*/
const loadCodes = () => {
const check = () => {}

const loadCodes = async () => {
if (fs.existsSync(path.join(folder_path, "rollbacks", "rollback.authme"))) {
dialog
.showMessageBox({
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: lang.edit_dialog.load_codes,
})
.then((result) => {
if (result.response === 0) {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", (err, data) => {
if (err) {
dialog.showMessageBox({
title: "Authme",
buttons: [lang.button.close],
type: "error",
message: lang.export_dialog.no_save_found,
})
} else {
let password
let key
const result = await dialog.showMessageBox({
title: "Authme",
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: lang.edit_dialog.load_codes,
})

if (settings.security.require_password === true) {
password = Buffer.from(ipc.sendSync("request_password"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
/**
* Load storage
* @type {LibStorage}
*/
let storage

if (dev === false) {
storage = JSON.parse(localStorage.getItem("storage"))
} else {
storage = JSON.parse(localStorage.getItem("dev_storage"))
}
if (result.response === 0) {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", async (err, data) => {
if (err) {
dialog.showMessageBox({
title: "Authme",
buttons: [lang.button.close],
type: "error",
message: lang.export_dialog.no_save_found,
})
} else {
let password
let key

password = Buffer.from(storage.password, "base64")
key = Buffer.from(aes.generateKey(password, Buffer.from(storage.key, "base64")))
}
if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
/**
* Load storage
* @type {LibStorage}
*/
let storage

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

password = Buffer.from(storage.password, "base64")
key = Buffer.from(aes.generateKey(password, Buffer.from(storage.key, "base64")))
}

fs.readFile(path.join(folder_path, "codes", "codes.authme"), (err, content) => {
if (err) {
logger.warn("The file codes.authme don't exists")
fs.readFile(path.join(folder_path, "codes", "codes.authme"), (err, content) => {
if (err) {
logger.warn("The file codes.authme don't exists")

password.fill(0)
key.fill(0)
} else {
const codes_file = JSON.parse(content)
password.fill(0)
key.fill(0)
} else {
const codes_file = JSON.parse(content)

const decrypted = aes.decrypt(Buffer.from(codes_file.codes, "base64"), key)
const decrypted = aes.decrypt(Buffer.from(codes_file.codes, "base64"), key)

processdata(decrypted.toString())
processdata(decrypted.toString())

decrypted.fill(0)
password.fill(0)
key.fill(0)
}
})
decrypted.fill(0)
password.fill(0)
key.fill(0)
}
})
}
})
}
} else {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", (err, data) => {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", async (err, data) => {
if (err) {
dialog.showMessageBox({
title: "Authme",
Expand All @@ -604,7 +601,7 @@ const loadCodes = () => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(ipc.sendSync("request_password"))
password = Buffer.from(await ipc.invoke("request_password"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
/**
Expand Down
29 changes: 15 additions & 14 deletions app/export/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ if (app.isPackaged === false) {
}

/**
* Get app information
* Build number
*/
const res = ipc.sendSync("info")

/**
* Show build number if version is pre release
*/
if (res.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
} else if (res.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
const buildNumber = async () => {
const info = await ipc.invoke("info")

if (info.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
} else if (info.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
}
}

buildNumber()

/**
* Init codes for save to qr codes
*/
Expand Down Expand Up @@ -252,12 +253,12 @@ const error = () => {
/**
* Export codes save to the disk
*/
const exportCodes = () => {
const exportCodes = async () => {
let password
let key

if (settings.security.require_password === true) {
password = Buffer.from(ipc.sendSync("request_password"))
password = Buffer.from(await ipc.invoke("request_password"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
let /** @type {LibStorage} */ storage
Expand Down
25 changes: 13 additions & 12 deletions app/import/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,22 @@ const hide = () => {
}

/**
* Get app information
* Build number
*/
const res = ipc.sendSync("info")

/**
* Show build number if version is pre release
*/
if (res.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
} else if (res.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${res.authme_version} - Build ${res.build_number}`
document.querySelector(".build").style.display = "block"
const buildNumber = async () => {
const info = await ipc.invoke("info")

if (info.build_number.startsWith("alpha")) {
document.querySelector(".build-content").textContent = `You are running an alpha version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
} else if (info.build_number.startsWith("beta")) {
document.querySelector(".build-content").textContent = `You are running a beta version of Authme - Version ${info.authme_version} - Build ${info.build_number}`
document.querySelector(".build").style.display = "block"
}
}

buildNumber()

/**
* Show experimental import screen capture
*/
Expand Down
Loading

0 comments on commit f906b43

Please sign in to comment.