Compare commits

..

2 Commits

Author SHA1 Message Date
0a9578c1ec
libui/Font: Use RefString
All checks were successful
Build and test / build (push) Successful in 1m54s
2024-09-07 16:52:48 +02:00
1fc2da4fb0
taskbar: Use os::ConfigFile instead of manually parsing app files 2024-09-07 16:52:31 +02:00
2 changed files with 16 additions and 48 deletions

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)));

View File

@ -7,7 +7,7 @@
*
*/
#include <luna/String.h>
#include <luna/RefString.h>
#include <os/File.h>
#include <ui/Font.h>
@ -49,8 +49,8 @@ namespace ui
Result<SharedPtr<Font>> Font::load_builtin(StringView name, FontWeight weight)
{
auto path = TRY(String::format("/usr/share/fonts/%s-%s.psf"_sv, name.chars(),
weight == FontWeight::Bold ? "Bold" : "Regular"));
auto path = TRY(RefString::format("/usr/share/fonts/%s-%s.psf"_sv, name.chars(),
weight == FontWeight::Bold ? "Bold" : "Regular"));
return load(path.view());
}