taskbar: Use os::ConfigFile instead of manually parsing app files

This commit is contained in:
apio 2024-09-07 16:52:31 +02:00
parent 9c4f20790f
commit 1fc2da4fb0
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -1,5 +1,6 @@
#include <luna/Sort.h>
#include <luna/StringBuilder.h>
#include <os/Config.h>
#include <os/Directory.h>
#include <os/File.h>
#include <os/FileSystem.h>
@ -66,64 +67,31 @@ static Result<void> load_application_file(const os::Path& path)
{
os::println("[taskbar] reading app file: %s", path.name().chars());
auto file = TRY(os::File::open(path, os::File::ReadOnly));
auto file = TRY(os::ConfigFile::open(path));
ApplicationFile app_file;
while (true)
app_file.name = TRY(String::from_string_view(file->read_string_or("Name", "")));
if (app_file.name.is_empty())
{
auto line = TRY(file->read_line());
if (line.is_empty()) break;
line.trim("\n");
if (line.is_empty()) continue;
auto parts = TRY(line.split_once('='));
if (parts.size() < 2 || parts[0].is_empty() || parts[1].is_empty())
{
os::println("[taskbar] file contains invalid line, aborting: '%s'", line.chars());
return {};
}
if (parts[0].view() == "Name")
{
app_file.name = move(parts[1]);
continue;
}
if (parts[0].view() == "Description")
{
// We let users specify this in the config file, but taskbar doesn't actually use it.
continue;
}
if (parts[0].view() == "Command")
{
app_file.command = move(parts[1]);
continue;
}
if (parts[0].view() == "Icon")
{
app_file.icon = move(parts[1]);
continue;
}
os::println("[taskbar] skipping unknown entry name %s", parts[0].chars());
}
if (app_file.icon.is_empty())
{
os::println("[taskbar] app file is missing 'Icon' entry, aborting!");
os::println("[taskbar] app file is missing 'Name' entry, aborting!");
return {};
}
app_file.command = TRY(String::from_string_view(file->read_string_or("Command", "")));
if (app_file.command.is_empty())
{
os::println("[taskbar] app file is missing 'Command' entry, aborting!");
return {};
}
app_file.icon = TRY(String::from_string_view(file->read_string_or("Icon", "")));
if (app_file.icon.is_empty())
{
os::println("[taskbar] app file is missing 'Icon' entry, aborting!");
return {};
}
os::println("[taskbar] loaded app %s into memory", app_file.name.chars());
TRY(s_app_files.try_append(move(app_file)));