Skip to content

Commit

Permalink
Fix app exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Mar 31, 2022
1 parent b69d3ce commit 564b05c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 38 deletions.
87 changes: 51 additions & 36 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ if (dev === false) {
if (lock === false) {
logger.log("Already running, shutting down")

app.quit()
app.exit()
} else {
app.on("second-instance", () => {
logger.log("Already running, focusing window")
Expand Down Expand Up @@ -384,10 +384,26 @@ const settingsFromTray = () => {
* Exit app from tray
*/
const exitFromTray = () => {
tray_minimized = false
saveWindowPosition()

try {
password_buffer.fill(0)
} catch (error) {}

app.exit()

logger.log("Exited from tray")
app.quit()
logger.log("App exited from tray")
}

/**
* Save window position
*/
const saveWindowPosition = () => {
const window_position = settings.window
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
settings.window = window_position

saveSettings()
}

/**
Expand Down Expand Up @@ -639,23 +655,21 @@ const createWindows = () => {
* Window states
*/
window_landing.on("close", () => {
app.quit()
app.exit()

logger.log("Application exited from landing window")
})

window_confirm.on("close", () => {
app.quit()
app.exit()

logger.log("Application exited from confirm window")
})

window_application.on("close", async (event) => {
if (dev === true) {
try {
password_buffer.fill(0)
} catch (error) {}
saveWindowPosition()

if (dev === true) {
app.quit()
} else {
if (tray_minimized === false) {
Expand All @@ -668,9 +682,8 @@ const createWindows = () => {
logger.log("Application exited from application window")
} else {
event.preventDefault()
setTimeout(() => {
window_application.hide()
}, 100)

window_application.hide()

application_shown = false

Expand All @@ -679,12 +692,6 @@ const createWindows = () => {
}
}

const window_position = settings.window
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
settings.window = window_position

saveSettings()

logger.log("Application closed")
})

Expand All @@ -693,9 +700,8 @@ const createWindows = () => {
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
window_settings.hide()
}, 100)

window_settings.hide()

settings_shown = false
}
Expand All @@ -708,9 +714,8 @@ const createWindows = () => {
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
window_import.hide()
}, 100)

window_import.hide()

import_shown = false
}
Expand All @@ -723,9 +728,8 @@ const createWindows = () => {
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
window_export.hide()
}, 100)

window_export.hide()

export_shown = false
}
Expand All @@ -738,9 +742,8 @@ const createWindows = () => {
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
window_edit.hide()
}, 100)

window_edit.hide()

edit_shown = false
}
Expand Down Expand Up @@ -976,7 +979,7 @@ app.whenReady()
if (result.response === 0) {
shell.openExternal("https://github.com/Levminer/authme/issues/")
} else if (result.response === 2) {
app.quit()
app.exit()
}
})

Expand Down Expand Up @@ -1085,7 +1088,7 @@ app.whenReady()
if (result.response === 0) {
shell.openExternal("https://github.com/Levminer/authme/issues/")
} else if (result.response === 2) {
app.quit()
app.exit()
}
})
})
Expand Down Expand Up @@ -1491,7 +1494,7 @@ ipc.on("rendererError", async (event, data) => {
shell.openExternal("https://github.com/Levminer/authme/issues/")
} else if (result.response === 2) {
app.relaunch()
app.quit()
app.exit()
}
}
})
Expand Down Expand Up @@ -1547,6 +1550,13 @@ ipc.handle("importExistingCodes", (event, codes) => {
}, 150)
})

/**
* Save window position
*/
ipc.handle("saveWindowPosition", () => {
saveWindowPosition()
})

/**
* Logger path
*/
Expand Down Expand Up @@ -1799,8 +1809,13 @@ const createMenu = () => {
label: lang.menu.exit,
accelerator: shortcuts ? "" : settings.shortcuts.exit,
click: () => {
tray_minimized = false
app.quit()
saveWindowPosition()

try {
password_buffer.fill(0)
} catch (error) {}

app.exit()

logger.log("App exited from menu")
},
Expand Down
6 changes: 4 additions & 2 deletions preload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Menu, getCurrentWindow } = require("@electron/remote")
const { Menu, getCurrentWindow, app } = require("@electron/remote")
const Titlebar = require("@6c65726f79/custom-titlebar")
const { ipcRenderer: ipc } = require("electron")

Expand All @@ -12,7 +12,9 @@ document.addEventListener("keydown", (event) => {
}

if (event.altKey && event.code === "F4") {
event.preventDefault()
ipc.invoke("saveWindowPosition")

app.exit()
}
})

Expand Down

0 comments on commit 564b05c

Please sign in to comment.