mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
HackStudio: Allow customizing the actions of the Build & Run buttons
This commit introduces per-project settings that can be customized through a JSON file placed in '.hackstudio/config.json' in the project's root
This commit is contained in:
parent
3e6c083754
commit
9096da19f1
7 changed files with 106 additions and 0 deletions
46
Userland/DevTools/HackStudio/ProjectConfig.cpp
Normal file
46
Userland/DevTools/HackStudio/ProjectConfig.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ProjectConfig.h"
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibCore/File.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
||||
ProjectConfig::ProjectConfig(JsonObject config)
|
||||
: m_config(move(config))
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<ProjectConfig>> ProjectConfig::try_load_project_config(String path)
|
||||
{
|
||||
auto file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly));
|
||||
auto file_contents = file->read_all();
|
||||
file->close();
|
||||
|
||||
auto json = TRY(JsonValue::from_string(StringView { file_contents }));
|
||||
if (!json.is_object())
|
||||
return Error::from_string_literal("The topmost JSON element is not an object");
|
||||
|
||||
return adopt_own(*new ProjectConfig(json.as_object()));
|
||||
}
|
||||
|
||||
NonnullOwnPtr<ProjectConfig> ProjectConfig::create_empty()
|
||||
{
|
||||
JsonObject empty {};
|
||||
return adopt_own(*new ProjectConfig(empty));
|
||||
}
|
||||
|
||||
Optional<String> ProjectConfig::read_key(String key_name) const
|
||||
{
|
||||
auto const& value = m_config.get(key_name);
|
||||
if (!value.is_string())
|
||||
return {};
|
||||
|
||||
return { value.as_string() };
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue