diff --git a/qrcode/README.md b/qrcode/README.md index d066eb0..3e4d7c3 100644 --- a/qrcode/README.md +++ b/qrcode/README.md @@ -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. diff --git a/qrcode/panel.luau b/qrcode/panel.luau index bbab2b4..7fe9c78 100644 --- a/qrcode/panel.luau +++ b/qrcode/panel.luau @@ -7,8 +7,23 @@ 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) @@ -36,6 +51,7 @@ local function render() placeholder = noctalia.tr("panel.placeholder"), onChange = "onTextChange", onSubmit = "onTextSubmit", + value = keepOnClose and currentText or "" }) } @@ -171,7 +187,9 @@ local function generate(text) end function onOpen(_context) - status = "idle" + if not keepOnClose then + status = "idle" + end render() end @@ -221,7 +239,10 @@ function onCloseClicked() end function onClose() - if imagePath ~= nil then + if not keepOnClose and imagePath ~= nil then noctalia.removeFile(imagePath) + imagePath = nil + render() + -- calling render() here so it doesn't try to render the image when opening the panel end end diff --git a/qrcode/plugin.toml b/qrcode/plugin.toml index 9955908..20df948 100644 --- a/qrcode/plugin.toml +++ b/qrcode/plugin.toml @@ -73,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" diff --git a/qrcode/translations/en.json b/qrcode/translations/en.json index 225fc3d..42707bf 100644 --- a/qrcode/translations/en.json +++ b/qrcode/translations/en.json @@ -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)."