Skip to content

Commit

Permalink
Android: Fix settings not saving when closing app via "Recents" screen
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Jan 17, 2024
1 parent e7dd973 commit 551de9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions builtin/mainmenu/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@
function core.sound_stop(handle, ...)
return handle:stop(...)
end

-- On Android, closing the app via the "Recents" screen won't result in a clean
-- shutdown, discarding any setting changes made by the user.
-- To avoid that, we write the settings file in more cases on Android.
-- We don't do this on desktop platforms because you can have multiple
-- instances of Minetest running at the same time there.
function write_settings_if_android()
if PLATFORM == "Android" then
core.settings:write()
end
end

local old_core_start = core.start
core.start = function()
-- Necessary for saving the selected world, server address, player name, etc.
write_settings_if_android()
old_core_start()
end
6 changes: 6 additions & 0 deletions builtin/mainmenu/settings/dlg_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,15 @@ local function buttonhandler(this, fields)
if fields.show_technical_names ~= nil then
local value = core.is_yes(fields.show_technical_names)
core.settings:set_bool("show_technical_names", value)
write_settings_if_android()

return true
end

if fields.show_advanced ~= nil then
local value = core.is_yes(fields.show_advanced)
core.settings:set_bool("show_advanced", value)
write_settings_if_android()

local suggested_page_id = update_filtered_pages(dialogdata.query)

Expand Down Expand Up @@ -672,12 +675,15 @@ local function buttonhandler(this, fields)

for i, comp in ipairs(dialogdata.components) do
if comp.on_submit and comp:on_submit(fields, this) then
write_settings_if_android()

-- Clear components so they regenerate
dialogdata.components = nil
return true
end
if comp.setting and fields["reset_" .. i] then
core.settings:remove(comp.setting.name)
write_settings_if_android()

-- Clear components so they regenerate
dialogdata.components = nil
Expand Down

0 comments on commit 551de9d

Please sign in to comment.