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
+23 -2
View File
@@ -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