Skip to content

Commit

Permalink
Paramètres de luminosité et temps de veille paramétrable dans les set…
Browse files Browse the repository at this point in the history
…tings
  • Loading branch information
paxo-rch committed Oct 28, 2024
1 parent 4bf55d7 commit d072823
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 42 deletions.
4 changes: 0 additions & 4 deletions lib/applications/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ namespace AppManager {
// Get the currently running app
App* app = appStack.back();

if (app->background) {
return;
}

// Kill the app
app->kill();
}
Expand Down
54 changes: 51 additions & 3 deletions lib/lua/src/lua_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ void LuaFile::load()
lua.set("COLOR_LIGHT_GREY", COLOR_LIGHT_GREY);

lua.set_function("launch", sol::overload([&](std::string name, std::vector<std::string> arg)
{
{
std::cerr << "launch is deprecated, use system.app:launch instead" << std::endl;
try{
AppManager::get(name)->run(arg);
}
Expand Down Expand Up @@ -728,6 +729,53 @@ void LuaFile::load()

app.set_function("quit", [&]()
{ m_commandQueue.push(QUIT); });

app.set_function("launch", sol::overload([&](std::string name, std::vector<std::string> arg)
{
try{
AppManager::get(name)->run(arg);
}
catch(std::runtime_error &e) {
std::cerr << "Erreur: " << e.what() << std::endl;
// Ajout message d'erreur
GuiManager &guiManager = GuiManager::getInstance();
guiManager.showErrorMessage(e.what());
}

return true; },
[&](std::string name)
{
try
{
AppManager::get(name)->run({});
}
catch (std::runtime_error &e)
{
std::cerr << "Erreur: " << e.what() << std::endl;
// Ajout message d'erreur
GuiManager &guiManager = GuiManager::getInstance();
guiManager.showErrorMessage(e.what());
}

return true;
}));

app.set_function("stopApp", sol::overload([&](std::string name)
{
try{
auto app = AppManager::get(name);
if(app->luaInstance != nullptr && app->luaInstance.get() != this)
app->kill();
}
catch(std::runtime_error &e) {
std::cerr << "Erreur: " << e.what() << std::endl;
// Ajout message d'erreur
GuiManager &guiManager = GuiManager::getInstance();
guiManager.showErrorMessage(e.what());
}

return true; }
));
}

/**
Expand Down Expand Up @@ -855,7 +903,7 @@ void LuaFile::wakeup(std::vector<std::string> arg)
void LuaFile::stop(std::vector<std::string> arg)
{
const sol::protected_function func = lua.get<sol::protected_function>("quit");
;

if (!func.valid())
return;

Expand All @@ -871,7 +919,7 @@ void LuaFile::loop()
{
case QUIT:
// Quit lua app OUTSIDE of lua
AppManager::quitApp();
AppManager::get(this)->kill();
break;
}

Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ void setup()
systemConfig.write();
}

if (!systemConfig.has("settings.sleeptime")) {
systemConfig.set<uint64_t>("settings.sleeptime", 30000);
systemConfig.write();
}

libsystem::log("settings.brightness: " + std::to_string(systemConfig.get<uint8_t>("settings.brightness")));

graphics::setBrightness(systemConfig.get<uint8_t>("settings.brightness"));
Expand Down
10 changes: 5 additions & 5 deletions storage/sys_apps/.oobe/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ function run(arg)
title:setFontSize(42)

title = gui:label(win, 0, 210, 320, 40)
title:setText("Running on PaxOS 9")
title:setText("Utilise le PaxOS 9")
title:setTextColor(100, 100, 100)
title:setHorizontalAlignment(CENTER_ALIGNMENT)
title:setFontSize(20)

button = gui:button(win, 100, 380, 120, 40)
button:setIcon("sys_apps/.oobe/resources/images/arrow_forward_ios_64px.png")
button:setText("Welcome")
button:setText("Bienvenu !")
button:onClick(function ()
paxo.system.config.set("oobe", true)
paxo.system.config.write()
system.config.set("oobe", true)
system.config.write()

paxo.app.quit()
system.app.quit()
end)

gui:setWindow(win)
Expand Down
17 changes: 16 additions & 1 deletion storage/sys_apps/settings/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,22 @@ function systemSettings()
textBrightness:setVerticalAlignment(CENTER_ALIGNMENT)
textBrightness:setText("Luminosité")

local brightnessSlider = gui:slider(brightnessBox, 15, 53, 230, 10, 5, 255, system.config.getInt("settings.brightness"))
local brightnessSlider = gui:slider(brightnessBox, 15, 53, 230, 10, 5, 255, settings.getBrightness())
brightnessSlider:onChange(function()
settings.setBrightness(brightnessSlider:getValue(), false)
end)

local sleepTimeBox = createBox(win2, 100, 73)
local textsleepTime = gui:label(sleepTimeBox, 16, 0, 177, 55)
textsleepTime:setFontSize(24)
textsleepTime:setVerticalAlignment(CENTER_ALIGNMENT)
textsleepTime:setText("Veille: " .. int(settings.getStandBySleepTime()/1000) .. "s")
print("sleep time: " .. settings.getStandBySleepTime())
local sleepTimeSlider = gui:slider(sleepTimeBox, 15, 53, 230, 10, 20, 120, int(settings.getStandBySleepTime()/1000))
sleepTimeSlider:onChange(function()
settings.setStandBySleepTime(sleepTimeSlider:getValue()*1000, true)
textsleepTime:setText("Veille: " .. int(sleepTimeSlider:getValue()) .. "s")
end)

gui:setWindow(win2)
end
Expand Down
17 changes: 3 additions & 14 deletions storage/sys_apps/testbc/app.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
function run()
print("run baground testbc app, no displayed: show conter to 10 and run settings app")
print(time)
-- local counter = 0
print("this app in not in the background, will launch sub1 app for 5 seconds")

-- local function printCounter()
-- counter = counter + 1
-- print("Counter: " .. counter .. " sec")
-- if(counter == 10) then
-- launch("settings")
-- end
-- end

-- time:setInterval(printCounter, 1000)

launch("testbc.sub1")
window = gui:window()
gui:setWindow(window)
end
18 changes: 5 additions & 13 deletions storage/sys_apps/testbc/sub/.sub1/app.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
function run()
print("run sub1 app in background: will display counter2 to 10 then run the settings app")
local counter = 0

local function printCounter()
counter = counter + 1
print("Counter 2: " .. counter .. " sec")
if(counter == 10) then
launch("settings")
end
end

time:setInterval(printCounter, 1000)
end
time:setTimeout(function()
launch("testbc")
system.app:quit()
end, 1000)
end
4 changes: 2 additions & 2 deletions storage/sys_apps/testbc/sub/.sub1/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"files",
"time"
],
"background": true,
"autorun": false
"background": false,
"autorun": true
}
Binary file modified storage/system/config.bfc
Binary file not shown.

0 comments on commit d072823

Please sign in to comment.