launcher_settings_app.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. laptop.register_app("launcher_settings", {
  2. app_name = "Settings",
  3. app_icon = "laptop_setting_wrench.png",
  4. app_info = "Desktop settings.",
  5. os_min_version = '5.00',
  6. formspec_func = function(app, mtos)
  7. local settings_data = mtos.bdev:get_app_storage('ram', 'launcher_settings')
  8. -- Change background setting
  9. local current_theme_name = settings_data.selected_theme or mtos:get_theme().name or "default"
  10. local current_theme = mtos:get_theme(current_theme_name)
  11. local current_idx
  12. settings_data.themes_tab = {}
  13. for name, _ in pairs(laptop.themes) do
  14. if name ~= "default" and mtos:is_theme_compatible(name) then
  15. table.insert(settings_data.themes_tab, name)
  16. end
  17. end
  18. table.sort(settings_data.themes_tab)
  19. local formspec = mtos.theme:get_label('0,0.5', "Select theme")
  20. local formspec = formspec..mtos.theme:get_tableoptions()..
  21. "tablecolumns[text]"..
  22. "table[0,1;5,2;sel_theme;"
  23. for i, theme in ipairs(settings_data.themes_tab) do
  24. if i > 1 then
  25. formspec = formspec..','
  26. end
  27. if theme == current_theme_name then
  28. current_idx = i
  29. end
  30. formspec = formspec..theme
  31. end
  32. if current_idx then
  33. formspec = formspec..";"..current_idx
  34. end
  35. formspec = formspec.."]"
  36. if current_theme then
  37. formspec = formspec.."image[5.5,1;5,3.75;"..current_theme.desktop_background.."]"
  38. end
  39. formspec = formspec .. mtos.theme:get_button('0,3.2;2.5,0.6', 'major', 'theme_apply', 'Apply', 'Apply theme')
  40. return formspec
  41. end,
  42. receive_fields_func = function(app, mtos, sender, fields)
  43. local settings_data = mtos.bdev:get_app_storage('ram', 'launcher_settings')
  44. if fields.sel_theme then
  45. local event = minetest.explode_table_event(fields.sel_theme)
  46. settings_data.selected_theme = settings_data.themes_tab[event.row]
  47. end
  48. if fields.theme_apply and settings_data.selected_theme then
  49. mtos:set_theme(settings_data.selected_theme)
  50. settings_data.selected_theme = nil
  51. end
  52. end
  53. })