Skip to content

Commit

Permalink
Fix shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Dec 18, 2021
1 parent 0eb781e commit 739ea9d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ <h4 class="text-popup-yellow font-bold mb-0">This feature is WIP! It might be un

<div class="relative inline-block">
<h3>Import screen capture</h3>
<h4>You can choose how to sort the codes. By default codes are sorted by importing order.</h4>
<h4>You can turn on Import screen capture. You can scan QR codes from your screen.</h4>
</div>

<div class="flex justify-center items-center w-72 h-[68px] bg-white mx-auto rounded-full">
Expand Down
12 changes: 6 additions & 6 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const { shell, app, dialog, BrowserWindow, screen } = require("@electron/remote")
const fs = require("fs")
const electron = require("electron")
const ipc = electron.ipcRenderer
const path = require("path")
const dns = require("dns")
const { typedef } = require("@levminer/lib")
const logger = require("@levminer/lib/logger/renderer")
const { ipcRenderer: ipc } = require("electron")
const { convert } = require("@levminer/lib")
const path = require("path")
const fs = require("fs")

// ? logger
logger.getWindow("settings")
Expand Down Expand Up @@ -684,6 +682,8 @@ const menu = (evt, name) => {

shortcut = true

checkForIssuers()

ipc.send("shortcuts")
} else if (name === "setting") {
removeButtonStyles()
Expand Down
98 changes: 67 additions & 31 deletions app/settings/src/js/shortcuts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// ? settings
/**
* Default shortcuts
*/
const default_shortcuts = {
shortcuts: {
show: "CmdOrCtrl+q",
Expand Down Expand Up @@ -30,15 +32,16 @@ const default_shortcuts = {
*/
let storage

if (dev === false) {
storage = JSON.parse(localStorage.getItem("storage"))
} else {
storage = JSON.parse(localStorage.getItem("dev_storage"))
}
/**
* Get issuers
* @type {string[]}
*/
let issuers

// ? shortcuts
/**
* Edit, reset, delete codes
*/
let modify = true

let inp_name
let svg_name
let id
Expand Down Expand Up @@ -81,6 +84,10 @@ hk100.value = settings.global_shortcuts.show
hk101.value = settings.global_shortcuts.settings
hk102.value = settings.global_shortcuts.exit

/**
* Detect pressed keys
* @param {KeyboardEvent} event
*/
const call = (event) => {
if (event.ctrlKey === true) {
inp_name.value = `CmdOrCtrl+${event.key.toLowerCase()}`
Expand All @@ -107,6 +114,10 @@ const call = (event) => {
}
}

/**
* Edit selected shortcut
* @param {Number} value
*/
const hk_edit = (value) => {
id = value
inp_name = document.querySelector(`#hk${value}_input`)
Expand Down Expand Up @@ -228,7 +239,7 @@ const hk_edit = (value) => {
break
}

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

modify = true
} else {
Expand All @@ -242,7 +253,10 @@ const hk_edit = (value) => {
}
}

// ? delete shortcut
/**
* Delete selected shortcut
* @param {Number} value
*/
const hk_delete = (value) => {
id = value
inp_name = document.querySelector(`#hk${value}_input`)
Expand Down Expand Up @@ -359,10 +373,13 @@ const hk_delete = (value) => {
break
}

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

// ? reset shortcut
/**
* Reset selected shortcut to its default value
* @param {Number} value
*/
const hk_reset = (value) => {
id = value
inp_name = document.querySelector(`#hk${value}_input`)
Expand Down Expand Up @@ -477,13 +494,13 @@ const hk_reset = (value) => {
break
}

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

// ? quick shortcuts
const issuers = storage.issuers

const generateCodes = () => {
/**
* Generate quick shortcut menus
*/
const generateQuickShortcuts = () => {
for (let i = 0; i < issuers.length; i++) {
let content = "None"

Expand Down Expand Up @@ -522,22 +539,37 @@ const generateCodes = () => {
}
}

if (issuers !== undefined) {
generateCodes()
} else {
document.querySelector(".quick").innerHTML = `
<div class="mx-auto rounded-2xl bg-gray-800 w-2/3">
<h3 class="pt-5">Please save your codes on the main page and click reload to be able to create quick shortcuts!</h3>
<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>
Reload
</button>
</div>
`
/**
* Check if codes saved on main page
*/
const checkForIssuers = () => {
if (dev === false) {
storage = JSON.parse(localStorage.getItem("storage"))
} else {
storage = JSON.parse(localStorage.getItem("dev_storage"))
}

if (issuers !== undefined) {
generateQuickShortcuts()
} else {
document.querySelector(".quick").innerHTML = `
<div class="mx-auto rounded-2xl bg-gray-800 w-2/3">
<h3 class="pt-5">Please save your codes on the main page and click reload to be able to create quick shortcuts!</h3>
<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>
Reload
</button>
</div>
`
}
}

/**
* Edit selected quick shortcuts
* @param {Number} value
*/
const qsEdit = (value) => {
id = value
inp_name = document.querySelector(`#qs${value}_input`)
Expand Down Expand Up @@ -583,6 +615,10 @@ const qsEdit = (value) => {
}
}

/**
* Delete selected quick shortcut
* @param {Number} value
*/
const qsDelete = (value) => {
inp_name = document.querySelector(`#qs${value}_input`)
btn_name = document.querySelector(`#qs${value}_button_delete`)
Expand Down

0 comments on commit 739ea9d

Please sign in to comment.