From 84717b801effd7d814d9df0bb34c2e19f99959ae Mon Sep 17 00:00:00 2001 From: Smok1e Date: Mon, 15 Jan 2024 01:25:50 +0300 Subject: [PATCH] Fix installer --- .../Settings.app/Modules/1_Wallpaper/Main.lua | 115 +++++++----------- Libraries/System.lua | 2 +- 2 files changed, 47 insertions(+), 70 deletions(-) diff --git a/Applications/Settings.app/Modules/1_Wallpaper/Main.lua b/Applications/Settings.app/Modules/1_Wallpaper/Main.lua index 1d42f96f..c24fa78a 100644 --- a/Applications/Settings.app/Modules/1_Wallpaper/Main.lua +++ b/Applications/Settings.app/Modules/1_Wallpaper/Main.lua @@ -1,6 +1,7 @@ - local GUI = require("GUI") local system = require("System") +local fs = require("Filesystem") +local paths = require("Paths") local module = {} @@ -9,80 +10,56 @@ local userSettings = system.getUserSettings() -------------------------------------------------------------------------------- -module.name = localization.wallpaper -module.margin = 5 -module.onTouch = function() - window.contentLayout:addChild(GUI.text(1, 1, 0x2D2D2D, localization.wallpaperWallpaper)) +local wallpaperConfigurationControlsBegin, wallpaperConfigurationControlsEnd = nil, nil - local wallpaperChooser = window.contentLayout:addChild(GUI.filesystemChooser(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5, userSettings.interfaceWallpaperPath, localization.open, localization.cancel, localization.wallpaperPath, "/")) - wallpaperChooser:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE) - wallpaperChooser:addExtensionFilter(".pic") - wallpaperChooser:addExtensionFilter(".lua") - wallpaperChooser.onSubmit = function(path) - userSettings.interfaceWallpaperPath = path - system.updateWallpaper() - workspace:draw() - - system.saveUserSettings() +local function updateWallpaperConfigurationControls(layout) + -- Remove previously added controls from layout + if wallpaperConfigurationControlsBegin ~= nil then + layout:removeChildren(wallpaperConfigurationControlsBegin, wallpaperConfigurationControlsEnd) + wallpaperConfigurationControlsBegin, wallpaperConfigurationControlsEnd = nil, nil end - local comboBox = window.contentLayout:addChild(GUI.comboBox(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5)) - comboBox.selectedItem = userSettings.interfaceWallpaperMode or 1 - comboBox:addItem(localization.wallpaperStretch) - comboBox:addItem(localization.wallpaperCenter) - - local wallpaperSwitch = window.contentLayout:addChild(GUI.switchAndLabel(1, 1, 36, 8, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xA5A5A5, localization.wallpaperEnabled .. ":", userSettings.interfaceWallpaperEnabled)).switch - wallpaperSwitch.onStateChanged = function() - userSettings.interfaceWallpaperEnabled = wallpaperSwitch.state - system.updateWallpaper() - workspace:draw() - - system.saveUserSettings() + -- Add new controls if needed + if system.wallpaper and system.wallpaper.configure then + wallpaperConfigurationControlsBegin = #layout.children + 1 + system.wallpaper.configure(layout) + wallpaperCOnfigurationControlsEnd = #layout.children end - - window.contentLayout:addChild(GUI.textBox(1, 1, 36, 1, nil, 0xA5A5A5, {localization.wallpaperInfo}, 1, 0, 0, true, true)) - - local wallpaperSlider = window.contentLayout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xA5A5A5, 0, 100, userSettings.interfaceWallpaperBrightness * 100, false, localization.wallpaperBrightness .. ": ", "%")) - wallpaperSlider.height = 2 - wallpaperSlider.roundValues = true - wallpaperSlider.onValueChanged = function() - userSettings.interfaceWallpaperBrightness = wallpaperSlider.value / 100 - system.updateWallpaper() - workspace:draw() - - system.saveUserSettings() - end - - comboBox.onItemSelected = function() - userSettings.interfaceWallpaperMode = comboBox.selectedItem - system.updateWallpaper() - workspace:draw() - - system.saveUserSettings() - end - - window.contentLayout:addChild(GUI.text(1, 1, 0x2D2D2D, localization.wallpaperScreensaver)) - - local screensaverChooser = window.contentLayout:addChild(GUI.filesystemChooser(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5, userSettings.interfaceScreensaverPath, localization.open, localization.cancel, localization.wallpaperScreensaverPath, "/")) - screensaverChooser:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE) - screensaverChooser:addExtensionFilter(".lua") - - local screensaverSwitch = window.contentLayout:addChild(GUI.switchAndLabel(1, 1, 36, 8, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xA5A5A5, localization.wallpaperScreensaverEnabled .. ":", userSettings.interfaceScreensaverEnabled)).switch - - local screensaverSlider = window.contentLayout:addChild(GUI.slider(1, 1, 36, 0x66DB80, 0xE1E1E1, 0xFFFFFF, 0xA5A5A5, 1, 100, userSettings.interfaceScreensaverDelay, false, localization.wallpaperScreensaverDelay .. ": ", " s")) - - local function save() - userSettings.interfaceScreensaverEnabled = screensaverSwitch.state - userSettings.interfaceScreensaverPath = screensaverChooser.path - userSettings.interfaceScreensaverDelay = screensaverSlider.value - - system.saveUserSettings() - end - - screensaverChooser.onSubmit, screensaverSwitch.onStateChanged, screensaverSlider.onValueChanged = save, save, save end -------------------------------------------------------------------------------- -return module +module.name = localization.wallpaper +module.margin = 0 +module.onTouch = function() + window.contentLayout:addChild(GUI.text(1, 1, 0x2D2D2D, localization.wallpaperWallpaper)) + + local comboBox = window.contentLayout:addChild(GUI.comboBox(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5)) + for _, filename in pairs(fs.list(paths.system.wallpapers)) do + local path = paths.system.wallpapers .. filename + + if fs.isDirectory(path) and fs.extension(path) == ".wlp" then + local item = comboBox:addItem(fs.hideExtension(filename)) + + item.onTouch = function() + userSettings.interfaceWallpaperPath = path + system.updateWallpaper() + workspace:draw() + + system.saveUserSettings() + updateWallpaperConfigurationControls(window.contentLayout) + end + + if userSettings.interfaceWallpaperPath == path then + comboBox.selectedItem = comboBox:count() + end + end + end + + updateWallpaperConfigurationControls(window.contentLayout) +end + +-------------------------------------------------------------------------------- + +return module \ No newline at end of file diff --git a/Libraries/System.lua b/Libraries/System.lua index 1810f674..846e15b5 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -86,7 +86,7 @@ function system.getDefaultUserSettings() interfaceScreenAddress = nil, interfaceWallpaperEnabled = false, - interfaceWallpaperPath = paths.system.wallpapers .. "Stars.wlp", + interfaceWallpaperPath = paths.system.wallpapers .. "Stars.wlp/", interfaceWallpaperMode = 1, interfaceWallpaperBrightness = 0.9,