Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add display name support in app manifest #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions lib/applications/src/app.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "app.hpp"

#include <json.hpp>

namespace app
{
std::vector<App> appList;
Expand All @@ -9,23 +11,69 @@ namespace app

void init()
{
// Get all apps
std::vector<std::string> dirs = storage::Path(APP_DIR).listdir();

// Get already authorized apps
storage::FileStream stream((storage::Path(PERMS_DIR) / "auth.list").str(), storage::READ);
std::string allowedFiles = stream.read();
stream.close();

// List apps
for (auto dir : dirs)
{
std::cout << (storage::Path(APP_DIR) / dir).str() << std::endl;
if(allowedFiles.find((storage::Path(APP_DIR) / dir).str()) != std::string::npos)

const bool authorized = allowedFiles.find((storage::Path(APP_DIR) / dir).str()) != std::string::npos;
storage::Path appConfigFile;

// Check if app is already authorized
if (authorized)
{
appList.push_back({dir, storage::Path(APP_DIR) / dir / "app.lua", storage::Path(PERMS_DIR) / (dir + ".json"), true});
// If the app is already authorized
// The app config is cached in the permission directory

// NOTE : What's happening when updating the app's manifest ?

appConfigFile = storage::Path(PERMS_DIR) / (dir + ".json");
}
else
{
appList.push_back({dir, storage::Path(APP_DIR) / dir / "app.lua", storage::Path(APP_DIR) / dir / "manifest.json", false});
// If the app is not already authorized
// The app config is stored in the app's directory
appConfigFile = storage::Path(APP_DIR) / dir / "manifest.json";
}

// Read the app's manifest
storage::FileStream file2(appConfigFile.str(), storage::READ);
std::string appConfigJSON = file2.read();
file2.close();

if (!nlohmann::json::accept(appConfigJSON))
{
std::cerr << "Invalid app config : " << (storage::Path(APP_DIR) / dir).str() << std::endl;
continue;
}

nlohmann::json appConfig = nlohmann::json::parse(appConfigJSON);

// Find display name
// Default is application's dir name
std::string appDisplayName = dir;

if (appConfig.contains("display_name"))
{
appDisplayName = appConfig["display_name"];
}

// Push the app
appList.push_back({
dir,
appDisplayName,
storage::Path(APP_DIR) / dir / "app.lua",
appConfigFile,
authorized
});
}
}

Expand All @@ -39,7 +87,7 @@ namespace app
}
}

return {"", storage::Path(), storage::Path(), false};
return {"", "", storage::Path(), storage::Path(), false};
}

bool askPerm(App &app)
Expand Down
1 change: 1 addition & 0 deletions lib/applications/src/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace app
struct App
{
std::string name;
std::string displayName;
storage::Path path;
storage::Path manifest;
bool auth;
Expand Down
2 changes: 1 addition & 1 deletion lib/applications/src/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int launcher()
box->addChild(img);

Label* text = new Label(0, 46, 80, 34);
text->setText(app::appList[i].name);
text->setText(app::appList[i].displayName);
text->setVerticalAlignment(Label::Alignement::CENTER);
text->setHorizontalAlignment(Label::Alignement::CENTER);
text->setFontSize(16);
Expand Down
Loading