Skip to content

Commit

Permalink
Remember window position #197
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Mar 29, 2022
1 parent 32eef35 commit c914a2c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/confirm/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const check_integrity = () => {
shell.openExternal("https://github.com/Levminer/authme/issues")
}

app.exit()
app.quit()
})
}
} catch (error) {
Expand All @@ -126,7 +126,7 @@ const check_integrity = () => {
shell.openExternal("https://github.com/Levminer/authme/issues")
}

app.exit()
app.quit()
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ const clearData = () => {

// exit aoo
setTimeout(() => {
app.exit()
app.quit()
}, 300)
}
})
Expand Down Expand Up @@ -926,7 +926,7 @@ if (storage.settings_page !== "general" && storage.settings_page !== undefined)
const restart = () => {
setTimeout(() => {
app.relaunch()
app.exit()
app.quit()
}, 300)
}

Expand Down
3 changes: 2 additions & 1 deletion lib/typedef.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* @property {object} settings.search_filter - Filter search results
* @property {boolean} settings.search_filter.name - Filter for names
* @property {boolean} settings.search_filter.description - Filter for description
* @property {number} settings.default_display - Default display
* @property {null|string} settings.language - Change language
* @property {null|string} settings.sort - Sort codes
*
Expand Down Expand Up @@ -61,6 +60,8 @@
* @property {null|number} statistics.opens - Number of opens
* @property {null|boolean} statistics.rated - Rated Authme
* @property {null|boolean} statistics.feedback - Sent feedback
*
* @property {import("electron").Rectangle} window - Windows bounds
*/

/**
Expand Down
89 changes: 75 additions & 14 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.exit()
app.quit()
} else {
app.on("second-instance", () => {
logger.log("Already running, focusing window")
Expand Down Expand Up @@ -238,6 +238,12 @@ const settings_file = {
rated: null,
feedback: null,
},
window: {
x: 0,
y: 0,
height: 1900,
width: 1000,
},
}

// Create settings if not exists
Expand Down Expand Up @@ -271,6 +277,17 @@ if (settings.settings.sort === undefined) {
saveSettings()
}

if (settings.window === undefined) {
settings.window = {
x: 0,
y: 0,
height: 1900,
width: 1000,
}

saveSettings()
}

/**
* Force dark mode
*/
Expand Down Expand Up @@ -370,7 +387,7 @@ const exitFromTray = () => {
tray_minimized = false

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

/**
Expand Down Expand Up @@ -412,6 +429,29 @@ const createWindows = () => {
wco = true
}

/**
* Listen to app quit
*/
app.on("quit", (event) => {
event.preventDefault()

saveSettings()

app.exit()
})

/**
* Set window bounds
*/
const positionWindow = () => {
settings.window = window_application.getBounds()

window_settings.setBounds(settings.window)
window_import.setBounds(settings.window)
window_export.setBounds(settings.window)
window_edit.setBounds(settings.window)
}

/**
* Create windows
*/
Expand Down Expand Up @@ -439,6 +479,8 @@ const createWindows = () => {

window_confirm = new BrowserWindow({
title: `Authme (${authme_version})`,
x: settings.window.x,
y: settings.window.y,
width: 1900,
height: 1000,
minWidth: 1000,
Expand All @@ -461,6 +503,8 @@ const createWindows = () => {

window_application = new BrowserWindow({
title: `Authme (${authme_version})`,
x: settings.window.x,
y: settings.window.y,
width: 1900,
height: 1000,
minWidth: 1000,
Expand All @@ -483,6 +527,8 @@ const createWindows = () => {

window_settings = new BrowserWindow({
title: "Authme Settings",
x: settings.window.x,
y: settings.window.y,
width: 1900,
height: 1000,
minWidth: 1000,
Expand All @@ -505,6 +551,8 @@ const createWindows = () => {

window_import = new BrowserWindow({
title: "Authme Import",
x: settings.window.x,
y: settings.window.y,
width: 1900,
height: 1000,
minWidth: 1000,
Expand All @@ -527,6 +575,8 @@ const createWindows = () => {

window_export = new BrowserWindow({
title: "Authme Export",
x: settings.window.x,
y: settings.window.y,
width: 1900,
height: 1000,
minWidth: 1000,
Expand All @@ -549,6 +599,8 @@ const createWindows = () => {

window_edit = new BrowserWindow({
title: "Authme Edit codes",
x: settings.window.x,
y: settings.window.y,
width: 1900,
height: 1000,
minWidth: 1000,
Expand All @@ -569,6 +621,13 @@ const createWindows = () => {
},
})

/**
* Window moved
*/
window_application.on("move", () => {
positionWindow()
})

// Enable remote module
remote.enable(window_landing.webContents)
remote.enable(window_confirm.webContents)
Expand All @@ -591,13 +650,13 @@ const createWindows = () => {
* Window states
*/
window_landing.on("close", () => {
app.exit()
app.quit()

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

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

logger.log("Application exited from confirm window")
})
Expand All @@ -608,14 +667,14 @@ const createWindows = () => {
password_buffer.fill(0)
} catch (error) {}

app.exit()
app.quit()
} else {
if (tray_minimized === false) {
try {
password_buffer.fill(0)
} catch (error) {}

app.exit()
app.quit()

logger.log("Application exited from application window")
} else {
Expand All @@ -631,12 +690,14 @@ const createWindows = () => {
}
}

saveSettings()

logger.log("Application closed")
})

window_settings.on("close", (event) => {
if (dev === true) {
app.exit()
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
Expand All @@ -651,7 +712,7 @@ const createWindows = () => {

window_import.on("close", (event) => {
if (dev === true) {
app.exit()
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
Expand All @@ -666,7 +727,7 @@ const createWindows = () => {

window_export.on("close", (event) => {
if (dev === true) {
app.exit()
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
Expand All @@ -681,7 +742,7 @@ const createWindows = () => {

window_edit.on("close", (event) => {
if (dev === true) {
app.exit()
app.quit()
} else {
event.preventDefault()
setTimeout(() => {
Expand Down Expand Up @@ -929,7 +990,7 @@ app.whenReady()
if (result.response === 0) {
shell.openExternal("https://github.com/Levminer/authme/issues/")
} else if (result.response === 2) {
app.exit()
app.quit()
}
})

Expand Down Expand Up @@ -1038,7 +1099,7 @@ app.whenReady()
if (result.response === 0) {
shell.openExternal("https://github.com/Levminer/authme/issues/")
} else if (result.response === 2) {
app.exit()
app.quit()
}
})
})
Expand Down Expand Up @@ -1476,7 +1537,7 @@ ipc.on("rendererError", async (event, data) => {
shell.openExternal("https://github.com/Levminer/authme/issues/")
} else if (result.response === 2) {
app.relaunch()
app.exit()
app.quit()
}
}
})
Expand Down Expand Up @@ -1785,7 +1846,7 @@ const createMenu = () => {
accelerator: shortcuts ? "" : settings.shortcuts.exit,
click: () => {
tray_minimized = false
app.exit()
app.quit()

logger.log("App exited from menu")
},
Expand Down

0 comments on commit c914a2c

Please sign in to comment.