Skip to content

Commit

Permalink
Fix hiding window on launch and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Apr 1, 2022
1 parent 564b05c commit 3edf3f9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 48 deletions.
18 changes: 9 additions & 9 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
/**
* Refresh settings
*/
const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
if (settings.security.require_password !== null) {
const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

if (settings.security.require_password !== null || settings.security.password !== null) {
clearInterval(settings_refresher)
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
}, 100)
}, 100)
}

/**
* Show quick start div
Expand Down
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.quit()
app.exit()
})
}
} catch (error) {
Expand All @@ -126,7 +126,7 @@ const check_integrity = () => {
shell.openExternal("https://github.com/Levminer/authme/issues")
}

app.quit()
app.exit()
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
/**
* Refresh settings
*/
const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
if (settings.security.require_password !== null) {
const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

if (settings.security.require_password !== null || settings.security.password !== null) {
clearInterval(settings_refresher)
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
}, 500)
}, 500)
}

// Get current window
const currentWindow = BrowserWindow.getFocusedWindow()
Expand Down
18 changes: 9 additions & 9 deletions app/export/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
/**
* Refresh settings
*/
const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
if (settings.security.require_password !== null) {
const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

if (settings.security.require_password !== null || settings.security.password !== null) {
clearInterval(settings_refresher)
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
}, 500)
}, 500)
}

/**
* Process data from saved file
Expand Down
6 changes: 3 additions & 3 deletions app/landing/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const text = document.querySelector("#text")
/**
* Create storage
*/
const storage = {}
let storage = {}

if (dev === false) {
temp_storage = localStorage.getItem("storage")
Expand Down Expand Up @@ -143,7 +143,7 @@ const hashPasswords = async () => {
settings.security.password = hashed
settings.security.key = aes.generateSalt().toString("base64")

const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
/** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))

storage.require_password = settings.security.require_password
storage.password = hashed
Expand Down Expand Up @@ -192,7 +192,7 @@ const noPassword = () => {

settings.security.require_password = false

const /** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))
/** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))

storage.require_password = settings.security.require_password
storage.password = password.toString("base64")
Expand Down
21 changes: 10 additions & 11 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,20 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
/**
* Refresh settings
*/
if (settings.security.require_password !== null) {
const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

const settings_refresher = setInterval(() => {
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
/** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))

/** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))

if (settings.security.require_password !== null || settings.security.password !== null) {
clearInterval(settings_refresher)
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
} catch (error) {
logger.error("Error refreshing settings and storage")
clearInterval(settings_refresher)
}
}, 100)
}, 100)
}

// Get current window
const currentWindow = BrowserWindow.getFocusedWindow()
Expand Down
21 changes: 16 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let edit_shown = false
*/
let authenticated = false
let shortcuts = false
let reload = false
let hidden = false
let tray_minimized = false
let update_seen = false
let manual_update = false
Expand Down Expand Up @@ -784,8 +784,15 @@ const createWindows = () => {
}

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

window_application.hide()

hidden = true

createTray()
createMenu()
}

// Check for manual update
Expand All @@ -801,12 +808,16 @@ const createWindows = () => {
*/
window_confirm.on("show", () => {
// Hide window if launch on startup on
if (reload === false && settings.settings.launch_on_startup === true && args[1] === "--hidden") {
if (hidden === false && settings.settings.launch_on_startup === true && args[1] === "--hidden") {
application_shown = false
confirm_shown = false

window_confirm.hide()

reload = true
hidden = true

createTray()
createMenu()
}
})

Expand Down

0 comments on commit 3edf3f9

Please sign in to comment.