Skip to content

Commit

Permalink
Settings refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 15, 2021
1 parent b8bd9b6 commit 9f22896
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 54 deletions.
26 changes: 13 additions & 13 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ const description_query = []
const name_query = []
let clear

const name_state = settings.settings.show_2fa_names
const name_state = settings.settings.code_description
const copy_state = settings.settings.reset_after_copy
const reveal_state = settings.settings.click_to_reveal
const search_state = settings.settings.save_search_results
const reveal_state = settings.settings.blur_codes
const search_state = settings.settings.search_history

const sort_number = settings.experimental.sort

Expand Down Expand Up @@ -554,7 +554,7 @@ const search = () => {

// search algorithm
name_query.forEach((result) => {
if (settings.settings.search_bar_filter.name === true && settings.settings.search_bar_filter.description === false) {
if (settings.settings.search_filter.name === true && settings.settings.search_filter.description === false) {
if (!result.startsWith(input)) {
const div = document.querySelector(`#grid${[i]}`)
div.style.display = "none"
Expand All @@ -563,7 +563,7 @@ const search = () => {
no_results++
}
}
} else if (settings.settings.search_bar_filter.description === true && settings.settings.search_bar_filter.name === false) {
} else if (settings.settings.search_filter.description === true && settings.settings.search_filter.name === false) {
if (!description_query[i].startsWith(input)) {
const div = document.querySelector(`#grid${[i]}`)
div.style.display = "none"
Expand Down Expand Up @@ -780,25 +780,25 @@ const dropdown = () => {
}
}

document.querySelector("#checkbox0").checked = settings.settings.search_bar_filter.name
document.querySelector("#checkbox1").checked = settings.settings.search_bar_filter.description
document.querySelector("#checkbox0").checked = settings.settings.search_filter.name
document.querySelector("#checkbox1").checked = settings.settings.search_filter.description

// ? dropdown checkboxes
document.querySelector("#checkbox0").addEventListener("click", () => {
if (settings.settings.search_bar_filter.name === true) {
settings.settings.search_bar_filter.name = false
if (settings.settings.search_filter.name === true) {
settings.settings.search_filter.name = false
} else {
settings.settings.search_bar_filter.name = true
settings.settings.search_filter.name = true
}

fs.writeFileSync(path.join(folder_path, "settings", "settings.json"), JSON.stringify(settings, null, "\t"))
})

document.querySelector("#checkbox1").addEventListener("click", () => {
if (settings.settings.search_bar_filter.description === true) {
settings.settings.search_bar_filter.description = false
if (settings.settings.search_filter.description === true) {
settings.settings.search_filter.description = false
} else {
settings.settings.search_bar_filter.description = true
settings.settings.search_filter.description = true
}

fs.writeFileSync(path.join(folder_path, "settings", "settings.json"), JSON.stringify(settings, null, "\t"))
Expand Down
20 changes: 10 additions & 10 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,6 @@ const addCodes = () => {
const /** @type{LibAuthmeFile} */ loaded = JSON.parse(input.toString())

if (loaded.role === "import" || loaded.role === "export") {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
defaultId: 0,
cancelId: 0,
type: "info",
noLink: true,
message: "Code(s) added! \n\nScroll down to view them!",
})

data = []

const container = document.querySelector(".codes_container")
Expand Down Expand Up @@ -439,6 +429,16 @@ const addCodes = () => {
}
})
}

dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
defaultId: 0,
cancelId: 0,
type: "info",
noLink: true,
message: "Code(s) added! \n\nScroll down to view them!",
})
}
})
}
Expand Down
10 changes: 5 additions & 5 deletions app/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ <h4>Your current Authme version. Click for more info about Authme.</h4>

<!-- codes -->
<div id="codes" class="tabcontent part hidden">
<h3>Show 2FA descriptions</h3>
<h4>The saved 2FA descriptions will be visible. You can copy it after clicking it.</h4>
<h3>Codes description</h3>
<h4>The saved codes description will be visible. You can copy it after clicking it.</h4>
<div class="flex justify-center items-center w-72 h-[68px] bg-white mx-auto rounded-full">
<a href="#" onclick="names()">
<div class="pointer-events-none relative inline-block w-10 mr-2 align-middle select-none bg-gray-900 border-2 border-gray-900 rounded-full">
Expand All @@ -323,7 +323,7 @@ <h4>The saved 2FA descriptions will be visible. You can copy it after clicking i
<br />
<hr />
<h3>Blur codes</h3>
<h4>Blurs the 2FA codes. You can still copy it or hover over it to reveal.</h4>
<h4>Blur the saved codes. You can still copy it or hover over it to reveal.</h4>
<div class="flex justify-center items-center w-72 h-[68px] bg-white mx-auto rounded-full">
<a href="#" onclick="reveal()">
<div class="pointer-events-none relative inline-block w-10 mr-2 align-middle select-none bg-gray-900 border-2 border-gray-900 rounded-full">
Expand All @@ -334,8 +334,8 @@ <h4>Blurs the 2FA codes. You can still copy it or hover over it to reveal.</h4>
</div>
<br />
<hr />
<h3>Save search history</h3>
<h4>Keep your search history. Works even after restart.</h4>
<h3>Search history</h3>
<h4>Save the latest code you searched for. Works even after restart.</h4>
<div class="flex justify-center items-center w-72 h-[68px] bg-white mx-auto rounded-full">
<a href="#" onclick="results()">
<div class="pointer-events-none relative inline-block w-10 mr-2 align-middle select-none bg-gray-900 border-2 border-gray-900 rounded-full">
Expand Down
24 changes: 12 additions & 12 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ if (tray_state === true) {
}

// names
let names_state = settings.settings.show_2fa_names
let names_state = settings.settings.code_description
if (names_state === true) {
tgt3.textContent = "On"
tgl3.checked = true
Expand All @@ -147,7 +147,7 @@ if (names_state === true) {
}

// reveal
let reveal_state = settings.settings.click_to_reveal
let reveal_state = settings.settings.blur_codes
if (reveal_state === true) {
tgt4.textContent = "On"
tgl4.checked = true
Expand All @@ -157,7 +157,7 @@ if (reveal_state === true) {
}

// search
let search_state = settings.settings.save_search_results
let search_state = settings.settings.search_history
if (search_state === true) {
tgt5.textContent = "On"
tgl5.checked = true
Expand Down Expand Up @@ -198,7 +198,7 @@ drp1.innerHTML = `
`

// hardware
let hardware_state = settings.settings.disable_hardware_acceleration
let hardware_state = settings.settings.hardware_acceleration
if (hardware_state === true) {
tgt7.textContent = "Off"
tgl7.checked = false
Expand Down Expand Up @@ -354,7 +354,7 @@ const clearData = () => {
const names = () => {
const toggle = () => {
if (names_state === true) {
settings.settings.show_2fa_names = false
settings.settings.code_description = false

save()

Expand All @@ -363,7 +363,7 @@ const names = () => {

names_state = false
} else {
settings.settings.show_2fa_names = true
settings.settings.code_description = true

save()

Expand All @@ -382,7 +382,7 @@ const names = () => {
const reveal = () => {
const toggle = () => {
if (reveal_state === true) {
settings.settings.click_to_reveal = false
settings.settings.blur_codes = false

save()

Expand All @@ -391,7 +391,7 @@ const reveal = () => {

reveal_state = false
} else {
settings.settings.click_to_reveal = true
settings.settings.blur_codes = true

save()

Expand All @@ -410,7 +410,7 @@ const reveal = () => {
const results = () => {
const toggle = () => {
if (search_state === true) {
settings.settings.save_search_results = false
settings.settings.search_history = false

save()

Expand All @@ -419,7 +419,7 @@ const results = () => {

search_state = false
} else {
settings.settings.save_search_results = true
settings.settings.search_history = true

save()

Expand Down Expand Up @@ -466,7 +466,7 @@ const copy = () => {
const hardware = () => {
const toggle = () => {
if (hardware_state === true) {
settings.settings.disable_hardware_acceleration = false
settings.settings.hardware_acceleration = false

save()

Expand All @@ -475,7 +475,7 @@ const hardware = () => {

hardware_state = false
} else {
settings.settings.disable_hardware_acceleration = true
settings.settings.hardware_acceleration = true

save()

Expand Down
14 changes: 7 additions & 7 deletions lib/typedef.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* @property {Object} settings - Settings
* @property {Boolean} settings.launch_on_startup - Launch On startup
* @property {Boolean} settings.close_to_tray - Close app to tray
* @property {Boolean} settings.show_2fa_names - Show 2FA names
* @property {Boolean} settings.click_to_reveal - Reveal codes on hover
* @property {Boolean} settings.code_description - Show 2FA names
* @property {Boolean} settings.blur_codes - Reveal codes on hover
* @property {Boolean} settings.reset_after_copy - Reset searchbar after copy
* @property {Boolean} settings.save_search_results - Save search results
* @property {Boolean} settings.search_history - Save search results
* @property {Boolean} settings.disable_window_capture - Disable screen capture
* @property {Boolean} settings.disable_hardware_acceleration - Disable hardware acceleration
* @property {Object} settings.search_bar_filter - Filter search results
* @property {Boolean} settings.search_bar_filter.name - Filter for names
* @property {Boolean} settings.search_bar_filter.description - Filter for description
* @property {Boolean} settings.hardware_acceleration - Disable hardware acceleration
* @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 {Object} experimental - Experimental
Expand Down
13 changes: 6 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ let edit_shown = false

// ? other states
let authenticated = false
let offline = false
let shortcuts = false
let reload = false
let tray_minimized = false
Expand Down Expand Up @@ -178,12 +177,12 @@ const settings_file = {
settings: {
launch_on_startup: true,
close_to_tray: true,
show_2fa_names: false,
click_to_reveal: false,
code_description: false,
blur_codes: false,
reset_after_copy: false,
save_search_results: true,
disable_hardware_acceleration: true,
search_bar_filter: {
search_history: true,
hardware_acceleration: true,
search_filter: {
name: true,
description: false,
},
Expand Down Expand Up @@ -246,7 +245,7 @@ let settings = JSON.parse(fs.readFileSync(path.join(folder_path, "settings", "se
nativeTheme.themeSource = "dark"

// ? disable hardware acceleration
if (settings.settings.disable_hardware_acceleration === true) {
if (settings.settings.hardware_acceleration === true) {
app.disableHardwareAcceleration()
}

Expand Down

0 comments on commit 9f22896

Please sign in to comment.