feat: add keep_on_close option
This commit is contained in:
+23
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user