Upload most recent update of standard plugin prior to any personal tweaks

This commit is contained in:
2026-01-31 14:07:48 -07:00
commit 89d0f2d8ed
12 changed files with 1369 additions and 0 deletions

View File

@@ -0,0 +1,135 @@
--[[
Author: Lena2309
Description: Displays items in the Screen Menu Entry to manage the plugin
]]
local PinPadMenuEntry = require("menu/pinpadmenuentry")
local _ = require("gettext")
return {
text = _("PIN Pad Lock"),
sorting_hint = "screen",
sub_item_table = {
{
text = _("Activated"),
checked_func = function()
return PinPadMenuEntry:pinPadEnabled()
end,
callback = function()
G_reader_settings:toggle("pinpadlock_activated")
end,
separator = true,
},
{
text = _("Manage PIN Code"),
keep_menu_open = true,
sub_item_table = {
{
text = _("Change PIN Code"),
callback = function()
PinPadMenuEntry:changePinCode()
end
},
{
text = _("Reset PIN Code"),
callback = function()
PinPadMenuEntry:resetPinCode()
end,
},
}
},
{
text = _("PIN pad lock message"),
separator = true,
sub_item_table = {
{
text = _("Add custom message to lock"),
checked_func = function()
return PinPadMenuEntry:showMessageEnabled()
end,
callback = function()
G_reader_settings:toggle("pinpadlock_show_message")
end,
separator = true,
},
{
text = _("Edit PIN pad lock message"),
enabled_func = function()
return PinPadMenuEntry:showMessageEnabled()
end,
keep_menu_open = true,
callback = function()
PinPadMenuEntry:setMessage()
end,
},
{
text = _("Message position"),
enabled_func = function()
return PinPadMenuEntry:showMessageEnabled()
end,
sub_item_table = {
PinPadMenuEntry:genRadioMenuItem(_("Top"), "pinpadlock_message_position", "top"),
PinPadMenuEntry:genRadioMenuItem(_("Middle"), "pinpadlock_message_position", "middle"),
PinPadMenuEntry:genRadioMenuItem(_("Bottom"), "pinpadlock_message_position", "bottom"),
},
},
{
text = _("Message alignment"),
enabled_func = function()
return PinPadMenuEntry:showMessageEnabled()
end,
sub_item_table = {
PinPadMenuEntry:genRadioMenuItem(_("Left"), "pinpadlock_message_alignment", "left"),
PinPadMenuEntry:genRadioMenuItem(_("Center"), "pinpadlock_message_alignment", "center"),
PinPadMenuEntry:genRadioMenuItem(_("Right"), "pinpadlock_message_alignment", "right"),
},
},
}
},
{
text = _("Advanced Settings"),
sub_item_table = {
{
text = _("Activate correct PIN pop-up"),
checked_func = function()
return PinPadMenuEntry:correctPinMessageEnabled()
end,
callback = function()
G_reader_settings:toggle("pinpadlock_correct_pin_message_activated")
end,
},
{
text = _("Display entered digit before hiding it"),
checked_func = function()
return PinPadMenuEntry:displayDigitEnabled()
end,
callback = function()
G_reader_settings:toggle("pinpadlock_display_digit_activated")
end,
},
{
text = _("Set Timeout time"),
sub_item_table = {
PinPadMenuEntry:genRadioMenuItem(_("10 seconds"), "pinpadlock_timeout_time", "10"),
PinPadMenuEntry:genRadioMenuItem(_("30 seconds"), "pinpadlock_timeout_time", "30"),
PinPadMenuEntry:genRadioMenuItem(_("60 seconds"), "pinpadlock_timeout_time", "60"),
},
},
{
text = _("Set max tries before timeout"),
sub_item_table = {
PinPadMenuEntry:genRadioMenuItem(_("1"), "pinpadlock_max_tries", "1"),
PinPadMenuEntry:genRadioMenuItem(_("3"), "pinpadlock_max_tries", "3"),
PinPadMenuEntry:genRadioMenuItem(_("6"), "pinpadlock_max_tries", "6"),
},
},
},
},
{
text = _("Check for updates"),
callback = function()
PinPadMenuEntry:checkForUpdates()
end,
}
}
}

View File

@@ -0,0 +1,187 @@
--[[
Author: Lena2309
Description: Execute actions when tapping on a menu entry item
]]
local ConfirmBox = require("ui/widget/confirmbox")
local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog")
local PinPadDialog = require("ui/pinpaddialog")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local http = require("socket.http")
local ltn12 = require("ltn12")
local json = require("dkjson")
local PinPadMenuEntry = {}
function PinPadMenuEntry:setMessage()
local lock_message = G_reader_settings:readSetting("pinpadlock_message")
local input_dialog
input_dialog = InputDialog:new {
title = _("PIN pad lock message"),
description = _("Enter a custom message to be displayed on the PIN pad lock."),
input = lock_message,
buttons = {
{
{
text = _("Cancel"),
id = "close",
callback = function()
UIManager:close(input_dialog)
end,
},
{
text = _("Set message"),
is_enter_default = true,
callback = function()
G_reader_settings:saveSetting("pinpadlock_message", input_dialog:getInputText())
UIManager:close(input_dialog)
end,
},
},
},
}
UIManager:show(input_dialog)
input_dialog:onShowKeyboard()
end
function PinPadMenuEntry:showMessageEnabled()
return G_reader_settings:isTrue("pinpadlock_show_message")
end
function PinPadMenuEntry:pinPadEnabled()
return G_reader_settings:isTrue("pinpadlock_activated")
end
function PinPadMenuEntry:correctPinMessageEnabled()
return G_reader_settings:isTrue("pinpadlock_correct_pin_message_activated")
end
function PinPadMenuEntry:displayDigitEnabled()
return G_reader_settings:isTrue("pinpadlock_display_digit_activated")
end
function PinPadMenuEntry:genRadioMenuItem(text, setting, value)
return {
text = text,
checked_func = function()
return G_reader_settings:readSetting(setting) == value
end,
callback = function()
G_reader_settings:saveSetting(setting, value)
end,
radio = true,
}
end
function PinPadMenuEntry:changePinCode()
local confirmCurrentCode = PinPadDialog:new { stage = "confirm_current_code" }
confirmCurrentCode:showPinPad()
end
function PinPadMenuEntry:resetPinCode()
local confirmBox
confirmBox = ConfirmBox:new {
text = _("Do you really want to reset the PIN code to \"1234\" ?"),
ok_text = _("Yes"),
ok_callback = function()
G_reader_settings:saveSetting("pinpadlock_pin_code", "1234")
UIManager:close(confirmBox)
UIManager:show(InfoMessage:new { text = _("PIN Code resetted successfully."), timeout = 1 })
end,
cancel_callback = function()
UIManager:close(confirmBox)
end
}
UIManager:show(confirmBox)
end
-- Parse a version string like "v1.2.3"
local function parseVersion(version)
local major, minor, patch = version:match("^v(%d+)%.(%d+)%.(%d+)$")
return {
major = tonumber(major) or 0,
minor = tonumber(minor) or 0,
patch = tonumber(patch) or 0
}
end
-- Returns -1 if a < b, 0 if equal, 1 if a > b
local function compareVersions(local_version, remote_version)
if local_version.major ~= remote_version.major then
if local_version.major > remote_version.major then
return 1
else
return -1
end
elseif local_version.minor ~= remote_version.minor then
if local_version.minor > remote_version.minor then
return 1
else
return -1
end
elseif local_version.patch ~= remote_version.patch then
if local_version.patch > remote_version.patch then
return 1
else
return -1
end
end
return 0
end
function PinPadMenuEntry:checkForUpdates()
local meta = dofile("plugins/pinpadlockscreen.koplugin/_meta.lua")
local local_version = meta.version or "unknown"
local response_body = {}
local ok, status = http.request {
url = "https://api.github.com/repos/Lena2309/pinpad_screenlock_plugin/releases/latest",
sink = ltn12.sink.table(response_body),
redirect = true
}
if not ok or status ~= 200 then
UIManager:show(InfoMessage:new {
text = _("Unable to check for updates. Make sure your device is connected to the Internet."),
timeout = 3,
})
return
end
local body = table.concat(response_body)
local data, pos, err = json.decode(body, 1, nil)
if not data or not data.tag_name then
UIManager:show(InfoMessage:new {
text = _("Error parsing GitHub release info."),
timeout = 3,
})
return
end
local remote_version = data.tag_name
local cmp = compareVersions(parseVersion(local_version), parseVersion(remote_version))
if cmp < 0 then
UIManager:show(InfoMessage:new {
text = _("New version available: ") .. remote_version ..
_("\nYou are running: ") .. local_version,
timeout = 5,
})
else
if cmp > 0 then
UIManager:show(InfoMessage:new {
text = _("Youre ahead of the official release.\nLatest official version: " .. remote_version),
timeout = 5,
})
else
UIManager:show(InfoMessage:new {
text = _("You are up to date!"),
timeout = 3,
})
end
end
end
return PinPadMenuEntry