Skip to content

Commit

Permalink
Fix showing window and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Mar 28, 2022
1 parent 77a4117 commit 32eef35
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 63 deletions.
6 changes: 3 additions & 3 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const importExistingCodes = async (res) => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
password = Buffer.from(await ipc.invoke("requestPassword"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
Expand Down Expand Up @@ -579,7 +579,7 @@ const saveCodes = async () => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
password = Buffer.from(await ipc.invoke("requestPassword"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
Expand Down Expand Up @@ -628,7 +628,7 @@ const loadCodes = async () => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
password = Buffer.from(await ipc.invoke("requestPassword"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
Expand Down
2 changes: 1 addition & 1 deletion app/confirm/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const unhashPassword = async () => {
const compare = await bcrypt.compare(password_input.toString(), settings.security.password).then(logger.log("Passwords compared!"))

if (compare == true) {
ipc.send("send_password", password_input)
ipc.invoke("sendPassword", password_input)

text.style.color = "#28A443"
text.textContent = lang.landing_text.passwords_match
Expand Down
6 changes: 3 additions & 3 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const saveModifications = async () => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
password = Buffer.from(await ipc.invoke("requestPassword"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
Expand Down Expand Up @@ -544,7 +544,7 @@ const loadCodes = async () => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
password = Buffer.from(await ipc.invoke("requestPassword"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
Expand Down Expand Up @@ -589,7 +589,7 @@ const loadCodes = async () => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
password = Buffer.from(await ipc.invoke("requestPassword"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
Expand Down
2 changes: 1 addition & 1 deletion app/export/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const exportCodes = async () => {
let key

if (settings.security.require_password === true) {
password = Buffer.from(await ipc.invoke("request_password"))
password = Buffer.from(await ipc.invoke("requestPassword"))
key = Buffer.from(aes.generateKey(password, Buffer.from(settings.security.key, "base64")))
} else {
const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
Expand Down
69 changes: 14 additions & 55 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const release_date = date
const build_number = number

// Send Authme info to renderer
ipc.handle("info", (event) => {
ipc.handle("info", () => {
return { authme_version, release_date, build_number }
})

Expand Down Expand Up @@ -176,6 +176,7 @@ if (dev === false) {

/**
* Settings
* @type{LibSettings}
*/
const settings_file = {
info: {
Expand Down Expand Up @@ -322,17 +323,16 @@ const showAppFromTray = () => {

confirm_shown = true
application_shown = true

createTray()
} else {
window_confirm.hide()

confirm_shown = false
application_shown = false

createTray()
}
}

createTray()
createMenu()
}

/**
Expand Down Expand Up @@ -732,11 +732,7 @@ const createWindows = () => {

// Hide window if launch on startup on
if (reload === false && settings.settings.launch_on_startup === true && args[1] === "--hidden") {
application_shown = false

window_application.hide()

reload = true
showAppFromTray()
}

// Check for manual update
Expand Down Expand Up @@ -841,7 +837,7 @@ const createWindows = () => {
const download_transferred = Math.trunc(progress.transferred / 1000000)
const download_total = Math.trunc(progress.total / 1000000)

logger.log(`Downloading auto update: ${download_percent}% - ${download_speed}MB/s (${download_transferred}MB/${download_total}MB)`)
logger.log(`Downloading update: ${download_percent}% - ${download_speed}MB/s (${download_transferred}MB/${download_total}MB)`)

window_application.webContents.send("updateInfo", {
download_percent,
Expand Down Expand Up @@ -1086,10 +1082,6 @@ contextmenu({
visible: dev === true,
},
actions.separator(),
actions.copyImage({
transform: (content) => content,
}),
actions.separator(),
actions.copy({
transform: (content) => content,
}),
Expand Down Expand Up @@ -1343,39 +1335,6 @@ ipc.on("about", () => {
version()
})

/**
* Abort execution
*/
ipc.on("abort", () => {
dialog
.showMessageBox({
title: "Authme",
buttons: [lang.button.help, lang.button.close],
type: "error",
defaultId: 0,
cancelId: 1,
noLink: true,
message: lang.dialog.integrity,
})
.then((result) => {
if (result.response === 0) {
shell.openExternal("https://github.com/Levminer/authme/issues")
} else if (result.response === 1) {
app.exit()
}
})

window_application.destroy()
window_settings.destroy()
window_import.destroy()
window_export.destroy()
window_edit.destroy()

process.on("uncaughtException", (error) => {
logger.error("Execution aborted", error.stack)
})
})

/**
* Display release notes
*/
Expand Down Expand Up @@ -1458,7 +1417,7 @@ ipc.on("provideFeedback", () => {
/**
* Receive password from confirm page
*/
ipc.on("send_password", (event, data) => {
ipc.handle("sendPassword", (event, data) => {
password_buffer = Buffer.from(data)

window_application.webContents.executeJavaScript("loadCodes()")
Expand All @@ -1467,7 +1426,7 @@ ipc.on("send_password", (event, data) => {
/**
* Send password to requesting page
*/
ipc.handle("request_password", (event) => {
ipc.handle("requestPassword", () => {
return password_buffer
})

Expand All @@ -1492,7 +1451,7 @@ ipc.on("reloadSettingsWindow", () => {
/**
* Reload export window
*/
ipc.on("reloadSettingsWindow", () => {
ipc.on("reloadExportWindow", () => {
window_export.reload()
})

Expand Down Expand Up @@ -1554,22 +1513,22 @@ ipc.handle("statistics", () => {
/**
* Receive imported codes and send to application
*/
ipc.handle("importCodes", (event, res) => {
ipc.handle("importCodes", (event, codes) => {
window_application.webContents.executeJavaScript("location.reload()")

setTimeout(() => {
window_application.webContents.executeJavaScript(`importCodes("${res}")`)
window_application.webContents.executeJavaScript(`importCodes("${codes}")`)
}, 150)
})

/**
* Receive imported codes and send to application
*/
ipc.handle("importExistingCodes", (event, res) => {
ipc.handle("importExistingCodes", (event, codes) => {
window_application.webContents.executeJavaScript("location.reload()")

setTimeout(() => {
window_application.webContents.executeJavaScript(`importExistingCodes("${res}")`)
window_application.webContents.executeJavaScript(`importExistingCodes("${codes}")`)
}, 150)
})

Expand Down

0 comments on commit 32eef35

Please sign in to comment.