Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ third_party/*/patches/.applied_*
__pycache__/
libs/libfreetype/include/
utils/.cached/*
.vscode
6 changes: 6 additions & 0 deletions build/userland/prepare_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import json
import subprocess
from distutils.dir_util import copy_tree

fs_app_name = sys.argv[1]
app_name = sys.argv[2]
Expand Down Expand Up @@ -45,6 +46,11 @@ def write_config(config, outpath):
for fname in os.listdir(src_dir):
if fname == "info.json":
config = read_config(src_dir + "/info.json")

if 'assets' in config:
for asset_dir in config['assets']:
copy_tree(src_dir + "/" + asset_dir, outpath + '/' + asset_dir)

break

write_config(config, outpath)
20 changes: 20 additions & 0 deletions libs/libfoundation/include/libfoundation/AssetManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Begining of possible AssetManager to locate/read/write to files and folders in the app directory
Comment thread
nimelehin marked this conversation as resolved.
namespace LFoundation {

class AssetManager {
public:
AssetManager(std::string name) {
Comment thread
nimelehin marked this conversation as resolved.
Outdated
app_root = "/Applications/";
app_root += name + ".app/Content/";
}

~AssetManager() = default;

std::string find(std::string path) {
return app_root + path;
}
private:
std::string app_root;
Comment thread
nimelehin marked this conversation as resolved.
Outdated
};

}
6 changes: 5 additions & 1 deletion userland/applications/about/AppDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#include "ViewController.h"
#include <libui/AppDelegate.h>
#include <libui/MenuBar.h>
#include <libfoundation/AssetManager.h>

class AppDelegate : public UI::AppDelegate {
public:
AppDelegate() = default;
virtual ~AppDelegate() = default;

LG::Size preferred_desktop_window_size() const override { return LG::Size(200, 210); }
const char* icon_path() const override { return "/res/icons/apps/about.icon"; }
const char* icon_path() const override {
LFoundation::AssetManager assets = LFoundation::AssetManager("about");
return assets.find("Resources/about.icon").c_str();
}

virtual bool application() override
{
Expand Down
4 changes: 4 additions & 0 deletions userland/applications/about/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"icon_rel_path": "Resources/about.icon/",
"assets": ["Resources"]
}
6 changes: 5 additions & 1 deletion userland/applications/activity_monitor/AppDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#include "ViewController.h"
#include <libui/AppDelegate.h>
#include <libfoundation/AssetManager.h>

class AppDelegate : public UI::AppDelegate {
public:
AppDelegate() = default;
virtual ~AppDelegate() = default;

LG::Size preferred_desktop_window_size() const override { return LG::Size(220, 210); }
const char* icon_path() const override { return "/res/icons/apps/activity_monitor.icon"; }
const char* icon_path() const override {
LFoundation::AssetManager assets = LFoundation::AssetManager("activity_monitor");
return assets.find("Resources/activity_monitor.icon").c_str();
}

virtual bool application() override
{
Expand Down
4 changes: 4 additions & 0 deletions userland/applications/activity_monitor/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"icon_rel_path": "Resources/activity_monitor.icon",
"assets": ["Resources"]
}
6 changes: 5 additions & 1 deletion userland/applications/calculator/AppDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#include "ViewController.h"
#include <libui/AppDelegate.h>
#include <libfoundation/AssetManager.h>

class AppDelegate : public UI::AppDelegate {
public:
AppDelegate() = default;
virtual ~AppDelegate() = default;

LG::Size preferred_desktop_window_size() const override { return LG::Size(240, 340); }
const char* icon_path() const override { return "/res/icons/apps/calculator.icon"; }
const char* icon_path() const override {
LFoundation::AssetManager assets = LFoundation::AssetManager("calculator");
return assets.find("Resources/calculator.icon").c_str();
}

virtual bool application() override
{
Expand Down
4 changes: 4 additions & 0 deletions userland/applications/calculator/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"icon_rel_path": "Resources/calculator.icon",
"assets": ["Resources"]
}
6 changes: 5 additions & 1 deletion userland/applications/terminal/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "TerminalViewController.h"
#include <csignal>
#include <libui/AppDelegate.h>
#include <libfoundation/AssetManager.h>

static int shell_pid = 0;

Expand Down Expand Up @@ -38,7 +39,10 @@ class AppDelegate : public UI::AppDelegate {
virtual ~AppDelegate() = default;

LG::Size preferred_desktop_window_size() const override { return LG::Size(400, 300); }
const char* icon_path() const override { return "/res/icons/apps/terminal.icon"; }
const char* icon_path() const override {
LFoundation::AssetManager assets = LFoundation::AssetManager("terminal");
return assets.find("Resources/terminal.icon").c_str();
}

bool application() override
{
Expand Down
4 changes: 4 additions & 0 deletions userland/applications/terminal/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"icon_rel_path": "Resources/terminal.icon",
"assets": ["Resources"]
}
6 changes: 6 additions & 0 deletions userland/system/applist/AppListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class AppListViewController : public UI::ViewController<AppListView> {
LG::PNG::PNGLoader loader;

std::string icon_path = jdict_root->data()["icon_path"]->cast_to<LFoundation::Json::StringObject>()->data();
std::string icon_rel_path = jdict_root->data()["icon_rel_path"]->cast_to<LFoundation::Json::StringObject>()->data();

if (!icon_rel_path.empty()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an "empty" icon if icon_rel_path is not set. (here they are: https://github.com/opuntiaOS-Project/opuntiaOS/tree/master/base/res/icons/apps/missing.icon)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so that means icon_path generated by prepare_app.py should be completely omitted? Or is there any plan for it? Maybe always setting it to the missing icon path

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should unify icon_path and icon_rel_path for sure, so yeah we should omit one of them. But also in case if there is no such field in info.json which describes location of an icon, we should set a "missing icon".

As an alternative to this icon_path and icon_rel_path we could provide path to asset folder in the info.json. And to require have a "special" folder which contains icons inside the asset folder. In other words to have a provided path to an asset folder and look there for a "AppIcon" folder to get all of the icons.

icon_path = content_dir + icon_rel_path;
}

new_ent.set_icon(loader.load_from_file(icon_path + "/32x32.png"));

std::string rel_exec_path = jdict_root->data()["exec_rel_path"]->cast_to<LFoundation::Json::StringObject>()->data();
Expand Down
33 changes: 29 additions & 4 deletions userland/system/dock/DockViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,49 @@
#include <libui/Window.h>
#include <memory>
#include <sys/types.h>
#include <libfoundation/json/Parser.h>

class DockViewController : public UI::ViewController<DockView> {
public:
DockViewController(DockView& view)
: UI::ViewController<DockView>(view)
{
dock_apps.push_back("about");
dock_apps.push_back("terminal");
dock_apps.push_back("calculator");
dock_apps.push_back("activity_monitor");
}
virtual ~DockViewController() = default;

virtual void view_did_load() override
{
view().set_background_color(LG::Color::LightSystemOpaque);
view().new_dock_entity("/Applications/about.app/Content/about", "/res/icons/apps/about.icon", "com.opuntia.about");
view().new_dock_entity("/Applications/terminal.app/Content/terminal", "/res/icons/apps/terminal.icon", "com.opuntia.terminal");
view().new_dock_entity("/Applications/activity_monitor.app/Content/activity_monitor", "/res/icons/apps/activity_monitor.icon", "com.opuntia.activity_monitor");
view().new_dock_entity("/Applications/calculator.app/Content/calculator", "/res/icons/apps/calculator.icon", "com.opuntia.calculator");
for (auto& app : dock_apps) {
std::string app_content_dir = "/Applications/";
app_content_dir += app;
app_content_dir += ".app/Content/";
auto json_parser = LFoundation::Json::Parser(app_content_dir + "info.json");
LFoundation::Json::Object* jobj_root = json_parser.object();

if (jobj_root->invalid()) {
return;
}

auto* jdict_root = jobj_root->cast_to<LFoundation::Json::DictObject>();

std::string icon_path = jdict_root->data()["icon_path"]->cast_to<LFoundation::Json::StringObject>()->data();
std::string icon_rel_path = jdict_root->data()["icon_rel_path"]->cast_to<LFoundation::Json::StringObject>()->data();

if (!icon_rel_path.empty()) {
icon_path = app_content_dir + icon_rel_path;
}
std::string bundle_id = jdict_root->data()["bundle_id"]->cast_to<LFoundation::Json::StringObject>()->data();
view().new_dock_entity(app_content_dir + app, icon_path, bundle_id);
}

view().set_needs_display();
}

private:
std::vector<std::string> dock_apps;
Comment thread
nimelehin marked this conversation as resolved.
Outdated
};