feat: add keep_on_close option

This commit is contained in:
Yocraft-2000
2026-08-04 22:33:47 +02:00
parent a490b35068
commit 91a3778a6e
4 changed files with 36 additions and 2 deletions
+2
View File
@@ -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. | | `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. | | `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. | | `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). | | `size` | `int` | `8` | Specify module size in dots (pixels). |
| `correction_level` | `select` | `M` | Specify error correction level. | | `correction_level` | `select` | `M` | Specify error correction level. |
| `glyph` | `glyph` | `qrcode` | Bar widget icon glyph name. | | `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 ## Notes
The plugin runs entirely locally and does not require network access. 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.
+22 -1
View File
@@ -7,8 +7,23 @@ local status = "idle"
local imageSize = 400 local imageSize = 400
local generateButton = noctalia.getConfig("generate_button") local generateButton = noctalia.getConfig("generate_button")
local keepOnClose = noctalia.getConfig("keep_on_close")
local notifyConf = noctalia.getConfig("notify") 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 function notify(text, error)
local cmd = error and noctalia.notifyError or noctalia.notify local cmd = error and noctalia.notifyError or noctalia.notify
cmd("QR Code encoder", text) cmd("QR Code encoder", text)
@@ -36,6 +51,7 @@ local function render()
placeholder = noctalia.tr("panel.placeholder"), placeholder = noctalia.tr("panel.placeholder"),
onChange = "onTextChange", onChange = "onTextChange",
onSubmit = "onTextSubmit", onSubmit = "onTextSubmit",
value = keepOnClose and currentText or ""
}) })
} }
@@ -171,7 +187,9 @@ local function generate(text)
end end
function onOpen(_context) function onOpen(_context)
if not keepOnClose then
status = "idle" status = "idle"
end
render() render()
end end
@@ -221,7 +239,10 @@ function onCloseClicked()
end end
function onClose() function onClose()
if imagePath ~= nil then if not keepOnClose and imagePath ~= nil then
noctalia.removeFile(imagePath) noctalia.removeFile(imagePath)
imagePath = nil
render()
-- calling render() here so it doesn't try to render the image when opening the panel
end end
end end
+7
View File
@@ -73,6 +73,13 @@ options = [
{ value = "none", label_key = "settings.notify.none" }, { 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]] [[setting]]
key = "size" key = "size"
type = "int" type = "int"
+4
View File
@@ -19,6 +19,10 @@
"minimal": "Minimal", "minimal": "Minimal",
"none": "None" "none": "None"
}, },
"keep_on_close": {
"label": "Keep on Close",
"description": "Keep the input, QR Code, status etc when closing the panel."
},
"size": { "size": {
"label": "QR Code Size", "label": "QR Code Size",
"description": "Specify module size in dots (pixels)." "description": "Specify module size in dots (pixels)."