Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Search history and codes description
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Aug 10, 2022
1 parent 534956a commit a6fe59e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 28 deletions.
4 changes: 4 additions & 0 deletions interface/libraries/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ declare global {
searchHistory: boolean
sortCodes: null | number
}

searchHistory: {
latest: string
}
}

/** Query selector element types */
Expand Down
6 changes: 5 additions & 1 deletion interface/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ const defaultSettings: LibSettings = {
codesDescription: false,
blurCodes: false,
searchHistory: true,
sortCodes: null,
sortCodes: 0,
},

searchHistory: {
latest: null,
},
}

Expand Down
105 changes: 78 additions & 27 deletions interface/windows/codes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getSettings, setSettings } from "../../stores/settings"
import { generateTimestamp } from "../../libraries/time"
import { getState, setState } from "../../stores/state"

const settings = getSettings()
let codesRefresher: NodeJS.Timer
let searchQuery: string[] = []
let saveText: string = ""
Expand All @@ -27,31 +28,60 @@ export const generateCodeElements = (data: LibImportFile) => {
const element = document.createElement("div")

// set div content
element.innerHTML = `
<div class="mt-5 flex flex-row px-5">
<div class="flex flex-1 justify-start">
<h3 id="name${i}" tabindex="0" class="mt-3 text-3xl font-normal focusRing rounded-2xl">-</h3>
if (settings.settings.codesDescription === false) {
element.innerHTML = `
<div class="mt-5 flex flex-row px-5">
<div class="flex flex-1 justify-start">
<h3 id="name${i}" tabindex="0" class="mt-3 text-3xl font-normal focusRing rounded-2xl">-</h3>
</div>
<div class="flex flex-1 justify-center">
<p id="code${i}" tabindex="0" class="transparent-900 relative mt-1.5 w-[140px] select-all rounded-2xl py-3 px-5 text-2xl focusRing">-</p>
</div>
<div class="flex flex-1 justify-end">
<h3 id="time${i}" tabindex="0" class="mt-3 text-3xl font-normal focusRing rounded-2xl">-</h3>
</div>
</div>
<div class="flex flex-1 justify-center">
<p id="code${i}" tabindex="0" class="transparent-900 relative mt-1.5 w-[140px] select-all rounded-2xl py-3 px-5 text-2xl focusRing">-</p>
<div class="mt-5 flex flex-col items-center justify-center">
<div class="progress">
<div id="progress${i}" class="progressFill" />
</div>
</div>
<div class="flex flex-1 justify-end">
<h3 id="time${i}" tabindex="0" class="mt-3 text-3xl font-normal focusRing rounded-2xl">-</h3>
<div class="mb-5 mt-5 flex items-center justify-center">
<button id="button${i}" class="button w-[140px] py-3 px-5">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
</svg>
Copy
</button>
</div>`
} else {
element.innerHTML = `
<div class="mt-5 flex flex-row px-5">
<div class="flex flex-1 justify-start">
<h3 id="name${i}" tabindex="0" class="mt-3 text-3xl font-normal focusRing rounded-2xl">-</h3>
</div>
<div class="flex flex-1 justify-center">
<p id="code${i}" tabindex="0" class="transparent-900 relative mt-1.5 w-[140px] select-all rounded-2xl py-3 px-5 text-2xl focusRing">-</p>
</div>
<div class="flex flex-1 justify-end">
<h3 id="time${i}" tabindex="0" class="mt-3 text-3xl font-normal focusRing rounded-2xl">-</h3>
</div>
</div>
</div>
<div class="mt-5 flex flex-col items-center justify-center">
<div class="progress">
<div id="progress${i}" class="progressFill" />
<div class="mt-5 flex flex-col items-center justify-center">
<div class="progress">
<div id="progress${i}" class="progressFill" />
</div>
</div>
</div>
<div class="mb-5 mt-5 flex items-center justify-center">
<button id="button${i}" class="button w-[140px] py-3 px-5">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
</svg>
Copy
</button>
</div>`
<p tabindex="0" class="text-2xl transparent-900 py-3 px-5 rounded-2xl select-all mt-5" id="description${i}">Description</p>
<div class="mb-5 mt-5 flex items-center justify-center">
<button id="button${i}" class="button w-[140px] py-3 px-5">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
</svg>
Copy
</button>
</div>`
}

// add div
element.classList.add("code")
Expand All @@ -72,6 +102,11 @@ export const generateCodeElements = (data: LibImportFile) => {
code.classList.add("blurCodes")
}

// description
if (settings.settings.codesDescription === true) {
description.textContent = names[i]
}

// add to query
searchQuery.push(`${issuers[i].toLowerCase().trim()}`)

Expand Down Expand Up @@ -128,6 +163,16 @@ export const generateCodeElements = (data: LibImportFile) => {
console.error("Error refreshing codes")
}
}, 500)

// latest search from history
const latestSearch = settings.searchHistory.latest

if (latestSearch !== null && latestSearch.trim() !== "" && settings.settings.searchHistory === true) {
const searchBar: HTMLInputElement = document.querySelector(".search")
searchBar.value = settings.searchHistory.latest

search()
}
}

const refreshCodes = (secrets: string[]) => {
Expand Down Expand Up @@ -163,6 +208,13 @@ export const search = () => {
const input = searchBar.value.toLowerCase()
let noResults = 0

// save results
if (settings.settings.searchHistory === true) {
settings.searchHistory.latest = input

setSettings(settings)
}

// restart
for (let i = 0; i < searchQuery.length; i++) {
const div = document.querySelector(`#codes${[i]}`)
Expand Down Expand Up @@ -209,8 +261,6 @@ export const chooseImportFile = async () => {
}

const saveCodes = async () => {
const settings = getSettings()

const password = Buffer.from(settings.security.password, "base64")
const key = Buffer.from(settings.security.key, "base64")

Expand All @@ -237,7 +287,6 @@ const saveCodes = async () => {
}

export const loadCodes = async () => {
const settings = getSettings()
const state = getState()
const filePath = await path.join(await path.configDir(), "Levminer", "Authme 4", "codes", "codes.authme")

Expand Down Expand Up @@ -265,15 +314,17 @@ export const loadCodes = async () => {
if (state.importData !== null) {
savedCodes = false

generateCodeElements(textConverter(state.importData + decrypted, 0))
generateCodeElements(textConverter(state.importData + decrypted, settings.settings.sortCodes))

saveText = state.importData + decrypted
} else {
generateCodeElements(textConverter(decrypted, 0))
generateCodeElements(textConverter(decrypted, settings.settings.sortCodes))
}

document.querySelector<HTMLInputElement>(".search").focus()
} else {
if (state.importData !== null) {
generateCodeElements(textConverter(state.importData, 0))
generateCodeElements(textConverter(state.importData, settings.settings.sortCodes))

saveText = state.importData
}
Expand Down

0 comments on commit a6fe59e

Please sign in to comment.