Skip to content

Commit

Permalink
Remove quick copy shortcuts #201
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Apr 8, 2022
1 parent 6465d6b commit 9342a06
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 187 deletions.
25 changes: 2 additions & 23 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ const showInfo = () => {
* Save imported codes to disk
*/
const saveCodes = async () => {
ipc.send("reloadSettingsWindow")

let password
let key

Expand Down Expand Up @@ -679,29 +681,6 @@ document.querySelector("#checkbox1").addEventListener("click", () => {
}, 100)
})

/**
* Quick copy shortcuts
* @param {string} key
*/
const quickCopy = (key) => {
for (let i = 0; i < name_query.length; i++) {
if (key.toLowerCase() === name_query[i]) {
const input = document.querySelector(`#code${[i]}`).textContent
const time = document.querySelector(`#time${[i]}`).textContent

clipboard.writeText(input)

const notification = new Notification({ title: "Authme", body: `${key} 2FA code copied to the clipboard (${time}s remaining).` })

notification.show()

setTimeout(() => {
notification.close()
}, 3000)
}
}
}

/**
* Build number
*/
Expand Down
10 changes: 2 additions & 8 deletions app/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,6 @@ <h4 data-loc>Reset the search bar after you copied a code. Useful if you copy an

<!-- shortcuts -->
<div id="shortcuts" class="tabcontent part hidden">
<h3 data-loc>Quick copy shortcuts</h3>
<h4 data-loc>You can create a shortcut for your most used codes to copy quickly. Shortcuts not work on this tab, go to any other settings tab to reactivate them!</h4>
<br />
<div class="quickShortcutsDiv">
<!-- quick shortcuts -->
</div>
<hr />
<h3 data-loc>Shortcuts</h3>
<h4 data-loc>You can modify the shortcuts here, read the documentation for more information. Shortcuts not work on this tab, go to any other settings tab to reactivate them!</h4>
<div class="shortcutsDiv">
Expand All @@ -340,6 +333,7 @@ <h4 data-loc>You can modify the global shortcuts here, read the documentation fo
<!-- experimental -->
<div id="experimental" class="tabcontent part hidden">
<div class="mx-auto mt-5 rounded-2xl bg-gray-800 md:w-4/5 lg:w-2/3">
<h3 class="relative top-7">Experimental features</h3>
<h4 class="pt-5" data-loc>These features are under development and can be unstable! Use it at your own risk!</h4>
<button class="buttoni mb-8" onclick="experimentalDocs()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
Expand Down Expand Up @@ -379,7 +373,7 @@ <h4>You can create backup codes and backup files.</h4>
Create backup file
</button>

<button class="buttoni" onclick="loadBackupFile()">
<button class="buttoni" onclick="loadBackupFileDialog()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M14 3v4a1 1 0 0 0 1 1h4"></path>
Expand Down
136 changes: 2 additions & 134 deletions app/settings/src/js/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ const createGlobalShortcuts = () => {

createGlobalShortcuts()

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

/**
* Edit, reset, delete codes
*/
Expand Down Expand Up @@ -472,6 +470,8 @@ const hk_delete = (value) => {
* @param {Number} value
*/
const hk_reset = (value) => {
ipc.send("shortcuts")

id = value
inp_name = document.querySelector(`#hk${value}_input`)
btn_name = document.querySelector(`#hk${value}_button_reset`)
Expand Down Expand Up @@ -586,138 +586,6 @@ const hk_reset = (value) => {
}

fs.writeFileSync(path.join(folder_path, "settings", "settings.json"), convert.fromJSON(settings))
}

/**
* Generate quick shortcut menus
* @param {string[]} issuers
*/
const generateQuickShortcuts = (issuers) => {
for (let i = 0; i < issuers.length; i++) {
let content = "None"

if (settings.quick_shortcuts[issuers[i]] !== undefined) {
content = settings.quick_shortcuts[issuers[i]]
}

const element = `
<div class="flex flex-col md:w-4/5 lg:w-2/3 mx-auto rounded-2xl bg-gray-800 mb-20">
<div class="flex justify-center items-center">
<h3 id="issuers${i}">Shortcut</h3>
</div>
<div class="flex justify-center items-center">
<input class="input" disabled type="text" id="qs${i}_input" value="${content}"/>
</div>
<div class="flex justify-center items-center mb-10 mt-5 gap-2">
<button class="buttonr button" id="qs${i}_button_edit" onclick="qsEdit(${i})">
<svg id="qs${i}_svg_edit" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
</svg>
</button>
<button class="buttonr button" id="qs${i}_button_delete" onclick="qsDelete(${i})">
<svg id="qs${i}_svg_delete" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
</div>
</div>
`

const div = document.createElement("div")
div.innerHTML = element
document.querySelector(".quickShortcutsDiv").appendChild(div)

document.querySelector(`#issuers${i}`).textContent = `${issuers[i]}`
}
}

/**
* Check if codes saved on main page
*/
const checkForIssuers = () => {
storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))

const issuers = storage.issuers

if (issuers !== undefined) {
generateQuickShortcuts(issuers)
} else {
document.querySelector(".quickShortcutsDiv").innerHTML = `
<div class="mx-auto rounded-2xl bg-gray-800 w-2/3 -mt-16">
<h4 class="pt-5">${lang.text.quick_shortcuts}</h4>
<button class="buttoni mb-8" onclick="location.reload()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
</svg>
${lang.text.refresh}
</button>
</div>
`
}
}

/**
* Edit selected quick shortcuts
* @param {number} value
*/
const qsEdit = (value) => {
const issuers = storage.issuers
id = value
inp_name = document.querySelector(`#qs${value}_input`)
btn_name = document.querySelector(`#qs${value}_button_edit`)
svg_name = document.querySelector(`#qs${value}_svg_edit`)

if (modify === true) {
document.addEventListener("keydown", call, true)

inp_name.value = "Press any key combination"
inp_name.style.borderColor = "green"
btn_name.style.borderColor = "green"
svg_name.style.color = "green"

modify = false
} else if (inp_name.value !== "Press any key combination") {
document.removeEventListener("keydown", call, true)
svg_name.style.color = ""
btn_name.style.border = ""
inp_name.style.border = ""

modify = true
} else {
document.removeEventListener("keydown", call, true)
svg_name.style.color = ""
btn_name.style.border = ""
inp_name.style.border = ""

document.querySelector(`#qs${value}_input`).value = "None"
modify = true
}

const input = document.querySelector(`#qs${value}_input`).value

if (input !== "Press any key combination" && input !== "None") {
settings.quick_shortcuts[issuers[id]] = input

save()
} else if (input === "None") {
delete settings.quick_shortcuts[issuers[value]]

save()
}
}

/**
* Delete selected quick shortcut
* @param {number} value
*/
const qsDelete = (value) => {
const issuers = storage.issuers
inp_name = document.querySelector(`#qs${value}_input`)
btn_name = document.querySelector(`#qs${value}_button_delete`)
svg_name = document.querySelector(`#qs${value}_svg_delete`)

inp_name.value = "None"

svg_name.style.color = "red"
btn_name.style.borderColor = "red"

Expand Down
2 changes: 0 additions & 2 deletions languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ module.exports = {
"Save the latest code you searched for. Works even after restart.",
"Reset search after copy",
"Reset the search bar after you copied a code. Useful if you copy and search for a lot of codes.",
"Quick copy shortcuts",
"You can create a shortcut for your most used codes to copy quickly. Shortcuts not work on this tab, go to any other settings tab to reactivate them!",
"Shortcuts",
"You can modify the shortcuts. Shortcuts not work on this tab, go to any other settings tab to reactivate them!",
"Global shortcuts",
Expand Down
2 changes: 0 additions & 2 deletions languages/hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ module.exports = {
"A legutóbbi keresés mentése. Újraindítás után is működik.",
"Keresés törlése másolás után",
"A keresőmező törlése keresés után. Hasznos ha sok kódot másolsz.",
"Gyors másolás gyorsgombok",
"Készíthetsz gyorsgombokat a leggyakrabban használt kódjaidhoz, hogy gyorsan ki tudd másolni azokat. A gyorsgombok nem működnek ezen a lapon, menj át egy mások beállítás lapra hogy aktiváld azokat!",
"Gyorsgombok",
"Itt tudod módosítani a gyorsgombokat. A gyorsgombok nem működnek ezen a lapon, menj át egy mások beállítás lapra hogy aktiváld azokat!",
"Globális gyorsgombok",
Expand Down
17 changes: 0 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ const settings_file = {
settings: "CmdOrCtrl+Shift+s",
exit: "CmdOrCtrl+Shift+d",
},
quick_shortcuts: {},
search_history: {
latest: null,
},
Expand Down Expand Up @@ -1015,7 +1014,6 @@ app.whenReady()

createTray()
createMenu()
quickShortcuts()

/**
* App controller
Expand Down Expand Up @@ -1678,20 +1676,6 @@ const feedback = () => {
})
}

/**
* Register quick shortcuts
*/
const quickShortcuts = () => {
const keys = Object.keys(settings.quick_shortcuts)
const values = Object.values(settings.quick_shortcuts)

for (let i = 0; i < keys.length; i++) {
globalShortcut.register(values[i], () => {
window_application.webContents.executeJavaScript(`quickCopy("${keys[i]}")`)
})
}
}

/**
* Lock Authme when PC goes to sleep or locked
*/
Expand Down Expand Up @@ -2149,7 +2133,6 @@ ipc.on("shortcuts", () => {
})
}

quickShortcuts()
createTray()
createMenu()

Expand Down
2 changes: 1 addition & 1 deletion styles/tailwind.css

Large diffs are not rendered by default.

0 comments on commit 9342a06

Please sign in to comment.