Skip to content

Commit

Permalink
Fix sort codes breaking settings page #199
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Mar 30, 2022
1 parent b36a7b7 commit 65b7a95
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
15 changes: 12 additions & 3 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
* Refresh settings
*/
const settings_refresher = setInterval(() => {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
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) {
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)
}
}, 100)
Expand Down Expand Up @@ -367,7 +372,11 @@ const generateCodeElements = (data) => {
generate()

setInterval(() => {
refreshCodes(secrets)
try {
refreshCodes(secrets)
} catch (error) {
logger.error("Error refreshing codes")
}
}, 500)

// search history
Expand Down
11 changes: 8 additions & 3 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ const folder_path = dev ? path.join(app.getPath("appData"), "Levminer", "Authme
* Read settings
* @type {LibSettings}
*/
const settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

/**
* Refresh settings
*/
const settings_refresher = setInterval(() => {
file = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
try {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))

if (file.security.require_password !== null || file.security.password !== null) {
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)
}
}, 500)
Expand Down
9 changes: 7 additions & 2 deletions app/export/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
* Refresh settings
*/
const settings_refresher = setInterval(() => {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
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) {
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)
}
}, 500)
Expand Down
8 changes: 4 additions & 4 deletions app/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ <h4 data-loc>Choose which language should Authme use by default. The translation
<svg xmlns="http://www.w3.org/2000/svg" class="pointer-events-none relative top-1 h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 9l4-4 4 4m0 6l-4 4-4-4" />
</svg>
<span class="languageContentDefault pointer-events-none">Default</span>
<span class="pointer-events-none">Default</span>
</button>

<div id="languageContent" class="animation absolute right-0 z-20 mt-2 hidden w-72 overflow-hidden rounded-2xl border-2 border-white bg-white">
<a href="#" onclick="languageDropdownChoose('default')" class="block transform px-2 py-2 text-xl text-black no-underline duration-200 ease-in hover:bg-gray-600 hover:text-white">
<svg xmlns="http://www.w3.org/2000/svg" class="pointer-events-none relative top-1 h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 9l4-4 4 4m0 6l-4 4-4-4" />
</svg>
<span data-loc class="languageContentDefault">Default</span>
<span data-loc>Default</span>
</a>
<a href="#" onclick="languageDropdownChoose('en')" class="block transform px-2 py-2 text-xl text-black no-underline duration-200 ease-in hover:bg-gray-600 hover:text-white">
<svg xmlns="http://www.w3.org/2000/svg" class="pointer-events-none relative top-1 h-6 w-6" viewBox="0 0 36 36">
Expand Down Expand Up @@ -253,15 +253,15 @@ <h4 data-loc>You can choose how to sort the codes. By default codes are sorted b
<svg xmlns="http://www.w3.org/2000/svg" class="pointer-events-none relative top-1 h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 9l4-4 4 4m0 6l-4 4-4-4" />
</svg>
<span data-loc class="sortDefault pointer-events-none">Default</span>
<span class="pointer-events-none">Default</span>
</button>

<div id="sortContent" class="animation absolute right-0 z-20 mt-2 hidden w-72 overflow-hidden rounded-2xl border-2 border-white bg-white">
<a href="#" onclick="sortDropdownChoose(0)" class="block transform px-2 py-2 text-xl text-black no-underline duration-200 ease-in hover:bg-gray-600 hover:text-white">
<svg xmlns="http://www.w3.org/2000/svg" class="pointer-events-none relative top-1 h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 9l4-4 4 4m0 6l-4 4-4-4" />
</svg>
<span class="sortContentDefault">Default</span>
<span data-loc>Default</span>
</a>
<a href="#" onclick="sortDropdownChoose(1)" class="block transform px-2 py-2 text-xl text-black no-underline duration-200 ease-in hover:bg-gray-600 hover:text-white">
<svg xmlns="http://www.w3.org/2000/svg" class="pointer-events-none relative top-1 h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
Expand Down
26 changes: 18 additions & 8 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
/**
* Refresh settings
*/

const settings_refresher = setInterval(() => {
settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "settings.json"), "utf-8"))
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) {
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)
}
}, 100)
Expand Down Expand Up @@ -185,11 +191,18 @@ const sort_number = settings.settings.sort
if (sort_number === 1) {
drp0.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" class="relative top-1 h-6 w-6 pointer-events-none" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4h13M3 8h9m-9 4h9m5-4v12m0 0l-4-4m4 4l4-4" />
</svg> A-Z`
</svg>
<span class="pointer-events-none">A-Z</span>`
} else if (sort_number === 2) {
drp0.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" class="relative top-1 h-6 w-6 pointer-events-none" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4h13M3 8h9m-9 4h6m4 0l4-4m0 0l4 4m-4-4v12" />
</svg> Z-A`
</svg>
<span class="pointer-events-none">Z-A</span>`
} else {
drp0.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" class="pointer-events-none relative top-1 h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 9l4-4 4 4m0 6l-4 4-4-4" />
</svg>
<span class="pointer-events-none">${lang.text.default}</span>`
}

// language
Expand Down Expand Up @@ -554,9 +567,6 @@ const hardwareAcceleration = () => {
*/
let sort_shown = false

document.querySelector(".sortDefault").textContent = lang.text.default
document.querySelector(".sortContentDefault").textContent = lang.text.default

// show dropdown
const sortDropdown = () => {
const sort_content = document.querySelector("#sortContent")
Expand Down

0 comments on commit 65b7a95

Please sign in to comment.