Merge pull request #235 from Yocraft-2000/qr-code
Update QR Code Encoder plugin
This commit is contained in:
@@ -30,6 +30,7 @@ Enter your text or URL and click on Generate or press enter to generate the QR c
|
||||
| `generate_button` | `bool` | `true` | Show Generate button, disable will submit on enter. |
|
||||
| `close_on_copy` | `bool` | `false` | Close the panel when copying the QR code. |
|
||||
| `notify` | `select` | `minimal` | Controls the notifications, minimal only notifies when Close on Copy is used. |
|
||||
| `keep_on_close` | `bool` | `false` | Keep the input, QR Code, status etc when closing the panel. |
|
||||
| `size` | `int` | `8` | Specify module size in dots (pixels). |
|
||||
| `correction_level` | `select` | `M` | Specify error correction level. |
|
||||
| `glyph` | `glyph` | `qrcode` | Bar widget icon glyph name. |
|
||||
@@ -38,3 +39,4 @@ Enter your text or URL and click on Generate or press enter to generate the QR c
|
||||
## Notes
|
||||
|
||||
The plugin runs entirely locally and does not require network access.
|
||||
The plugin does not store anyting in files when the panel is closed, except when `keep_on_close` option is enabled.
|
||||
|
||||
+28
-4
@@ -6,8 +6,24 @@ local status = "idle"
|
||||
|
||||
local imageSize = 400
|
||||
|
||||
local generateButton = noctalia.getConfig("generate_button")
|
||||
local keepOnClose = noctalia.getConfig("keep_on_close")
|
||||
local notifyConf = noctalia.getConfig("notify")
|
||||
|
||||
-- when toggling off keep_on_close, the image will not be deleted, so this runs every config change
|
||||
if not keepOnClose then
|
||||
local dir = noctalia.pluginDir()
|
||||
local files = noctalia.listDir(dir)
|
||||
|
||||
if files then
|
||||
for _, name in ipairs(files) do
|
||||
if name:match("^qr-") then
|
||||
noctalia.removeFile(dir .. "/" .. name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function notify(text, error)
|
||||
local cmd = error and noctalia.notifyError or noctalia.notify
|
||||
cmd("QR Code encoder", text)
|
||||
@@ -23,7 +39,7 @@ local function statusText()
|
||||
elseif status == "copied" then
|
||||
return noctalia.tr("panel.status.copied")
|
||||
else
|
||||
return noctalia.tr("panel.status.idle")
|
||||
return noctalia.tr(generateButton and "panel.status.idle" or "panel.status.idlebis")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,10 +51,11 @@ local function render()
|
||||
placeholder = noctalia.tr("panel.placeholder"),
|
||||
onChange = "onTextChange",
|
||||
onSubmit = "onTextSubmit",
|
||||
value = currentText
|
||||
})
|
||||
}
|
||||
|
||||
if noctalia.getConfig("generate_button") then
|
||||
if generateButton then
|
||||
table.insert(
|
||||
rowContent,
|
||||
ui.button({
|
||||
@@ -170,7 +187,9 @@ local function generate(text)
|
||||
end
|
||||
|
||||
function onOpen(_context)
|
||||
status = "idle"
|
||||
if not keepOnClose then
|
||||
status = "idle"
|
||||
end
|
||||
render()
|
||||
end
|
||||
|
||||
@@ -220,7 +239,12 @@ function onCloseClicked()
|
||||
end
|
||||
|
||||
function onClose()
|
||||
if imagePath ~= nil then
|
||||
if not keepOnClose and imagePath ~= nil then
|
||||
noctalia.removeFile(imagePath)
|
||||
imagePath = nil
|
||||
errorMessage = nil
|
||||
currentText = ""
|
||||
render()
|
||||
-- calling render() here so it doesn't try to render the image when opening the panel
|
||||
end
|
||||
end
|
||||
|
||||
+11
-1
@@ -1,6 +1,6 @@
|
||||
id = "yocraft/qrcode"
|
||||
name = "QR Code Encoder"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
plugin_api = 15
|
||||
author = "yocraft"
|
||||
license = "MIT"
|
||||
@@ -14,6 +14,9 @@ dependencies = [ "qrencode" ]
|
||||
id = "widget"
|
||||
entry = "widget.luau"
|
||||
|
||||
[widget.actions]
|
||||
left = "panel-toggle yocraft/qrcode:panel"
|
||||
|
||||
[[widget.setting]]
|
||||
key = "glyph"
|
||||
type = "glyph"
|
||||
@@ -70,6 +73,13 @@ options = [
|
||||
{ value = "none", label_key = "settings.notify.none" },
|
||||
]
|
||||
|
||||
[[setting]]
|
||||
key = "keep_on_close"
|
||||
type = "bool"
|
||||
label_key = "settings.keep_on_close.label"
|
||||
description_key = "settings.keep_on_close.description"
|
||||
default = false
|
||||
|
||||
[[setting]]
|
||||
key = "size"
|
||||
type = "int"
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
"minimal": "Minimal",
|
||||
"none": "None"
|
||||
},
|
||||
"keep_on_close": {
|
||||
"label": "Keep on Close",
|
||||
"description": "Keep the input, QR Code, status etc when closing the panel."
|
||||
},
|
||||
"size": {
|
||||
"label": "QR Code Size",
|
||||
"description": "Specify module size in dots (pixels)."
|
||||
@@ -50,7 +54,8 @@
|
||||
"error": "Error: {message}",
|
||||
"ready": "QR code ready. Scan it here or click it to copy.",
|
||||
"copied": "QR code copied to clipboard.",
|
||||
"idle": "Enter some text, then press Generate."
|
||||
"idle": "Enter some text, then press Generate.",
|
||||
"idlebis": "Enter some text, then press Enter."
|
||||
},
|
||||
"error": {
|
||||
"generate_failed": "failed to generate the QR code.",
|
||||
|
||||
@@ -7,7 +7,3 @@ else
|
||||
end
|
||||
|
||||
barWidget.setTooltip(noctalia.tr("widget.tooltip"))
|
||||
|
||||
function onClick()
|
||||
noctalia.togglePanel("yocraft/qrcode:panel")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user