Skip to content

Commit

Permalink
ThirdParty repo test
Browse files Browse the repository at this point in the history
  • Loading branch information
Armored-Dragon committed Aug 24, 2023
1 parent 34eae7f commit cc85933
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 133 deletions.
136 changes: 100 additions & 36 deletions scripts/system/more-ng/more-ng.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//
// Copyright 2023 Overte e.V.
// "https://more.overte.org/applications/metadata.js",

const html_url = Script.resolvePath("./ui/index.html");
let tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
let shown = false;
const logs = (info) => console.log("[NEW_MORE] " + JSON.stringify(info));

tablet.screenChanged.connect(onScreenChanged);
Script.scriptEnding.connect(shutdownTabletApp);
Expand All @@ -14,6 +16,13 @@ let tabletButton = tablet.addButton({
activeIcon: Script.resolvePath("./img/icon-a.png"),
});

let repo_list = [
"https://raw.githubusercontent.com/Armored-Dragon/overte-app-examples/master/metadata.json",
];
let app_info = {
installed_apps: [],
thirdparty_apps: [],
};
// REVIEW: How can we optimize this further?
tabletButton.clicked.connect(clicked);

Expand Down Expand Up @@ -57,16 +66,8 @@ function onWebEventReceived(message) {
message = JSON.parse(message);

if (message.action === "ready") {
// Get apps from repos
// Form custom Object and send to ui

// Get installed apps
const installed_apps = ScriptDiscoveryService.getRunning();
const repo_apps = _get("");

const app_list = _createAppList(installed_apps, repo_apps);

_sendMessage({ action: "app_list", data: app_list });
getInstalledApps();
findThirdParty();
}

if (message.action === "new_repo") {
Expand All @@ -79,49 +80,112 @@ function onWebEventReceived(message) {
}

if (message.action === "install_script") {
// On installed, create "setting" to save app metadata
logs(`Installing script ${message.data}`);
ScriptDiscoveryService.loadScript(message.data);
}

if (message.action === "uninstall_script") {
logs(`Uninstalling script ${message.data}`);
ScriptDiscoveryService.stopScript(message.data);
// TODO: Reload application window
}
}

function _get(url) {
// HTTPS Request here
return [];
}
function getInstalledApps() {
const running_apps = ScriptDiscoveryService.getRunning();
const installed_apps = Settings.getValue("more_installed_list", []);

function _createAppList(installed_apps, repo_apps) {
let return_array = [];

installed_apps.forEach((app) => {
running_apps.forEach((app) => {
// REVIEW: Multiplatform support functional?
if (app.url.includes("file://")) return;
let found = false;

return_array.push({
title: app.name,
url: app.url,
icon: app.icon || "",
installed: true,
});
});
logs(`Processing ${app.name || app.title}`);
logs(app.url);

// REVIEW: Is this legit?
repo_apps.forEach((app) => {
for (let i = 0; installed_apps.length > i; i++) {
if (installed_apps[Object.keys(installed_apps)[i]].url === app.url)
if (installed_apps[i].url === app.url) {
return_array.push(installed_apps[i]);
found = true;
break;
}

// Our installed app is not saved in settings, add it
if (installed_apps.length === i) {
logs("Not in settings");
let template = {
title: app.name,
url: app.url,
icon: app.icon || "",
description: app.description,
directory: app.directory,
installed: true,
};
return_array.push(template);
found = true;
return;
}
}
if (!found) {
logs("Settings was blank; just pushing it in.");
let template = {
title: app.name,
url: app.url,
icon: app.icon || "",
description: app.description,
directory: app.directory,
installed: true,
};
return_array.push(template);
return;
}
});

Settings.setValue("more_installed_list", return_array);
_sendMessage({ action: "installed_apps", data: return_array });
}

return_array.push({
title: app.name,
url: app.url,
icon: app.icon || "",
installed: false,
function findThirdParty() {
repo_list.forEach((url) => {
var req = new XMLHttpRequest();

req.requestComplete.connect(() => {
if (req.status !== 200) {
_sendMessage({
action: "repo_loaded",
data: { error: true, status: req.status },
});
}

const response = JSON.parse(req.responseText);
let app_list_formatted = [];

response.forEach((app) => {
const app_dir =
url.split("/metadata.json")[0] + "/" + app.directory + "/";

const icon_url = app_dir + app.icon;
const script_url = app_dir + app.script;

app_list_formatted.push({
title: app.name,
url: script_url,
icon: icon_url,
description: app.description,
directory: app.directory,
installed: false,
});
});

return _sendMessage({
action: "repo_loaded",
data: app_list_formatted,
});
});
});

return return_array;
req.open("GET", url);
req.send();
});
}

repo_list = Settings.getValue("more_repo_list", repo_list);
4 changes: 4 additions & 0 deletions scripts/system/more-ng/ui/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ body {
overflow-y: hidden;
}

.container {
min-height: inherit;
}

.search-area {
display: grid;
grid-template-columns: auto 140px;
Expand Down
100 changes: 13 additions & 87 deletions scripts/system/more-ng/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,93 +24,17 @@

<div id="app-filters" class="container color-primary filter hidden">
<div class="horizontal-button-container">
<button class="generic">Only installed</button>
<button
data-filter_name="only_installed"
class=""
onclick="toggleFilter('only_installed')"
>
Only installed
</button>
</div>
</div>

<div class="app-list">

<div class="listing color-secondary">
<div class="app-info">
<div class="icon">
<img src="" />
</div>
<div class="body">
<div class="title"></div>
<div class="description"></div>
</div>
</div>
<div class="app-actions horizontial-button-container">
<button data-intention="view">View</button>
<button data-intention="uninstall"class="bad">Uninstall</button>
<button data-intention="install" class="good">Install</button>
</div>
</div>
<div class="listing color-secondary">
<div class="app-info">
<div class="icon">
<img src="" />
</div>
<div class="body">
<div class="title"></div>
<div class="description"></div>
</div>
</div>
<div class="app-actions horizontial-button-container">
<button data-intention="view">View</button>
<button data-intention="uninstall"class="bad">Uninstall</button>
<button data-intention="install" class="good">Install</button>
</div>
</div>
<div class="listing color-secondary">
<div class="app-info">
<div class="icon">
<img src="" />
</div>
<div class="body">
<div class="title"></div>
<div class="description"></div>
</div>
</div>
<div class="app-actions horizontial-button-container">
<button data-intention="view">View</button>
<button data-intention="uninstall"class="bad">Uninstall</button>
<button data-intention="install" class="good">Install</button>
</div>
</div>
<div class="listing color-secondary">
<div class="app-info">
<div class="icon">
<img src="" />
</div>
<div class="body">
<div class="title"></div>
<div class="description"></div>
</div>
</div>
<div class="app-actions horizontial-button-container">
<button data-intention="view">View</button>
<button data-intention="uninstall"class="bad">Uninstall</button>
<button data-intention="install" class="good">Install</button>
</div>
</div>
<div class="listing color-secondary">
<div class="app-info">
<div class="icon">
<img src="" />
</div>
<div class="body">
<div class="title"></div>
<div class="description"></div>
</div>
</div>
<div class="app-actions horizontial-button-container">
<button data-intention="view">View</button>
<button data-intention="uninstall"class="bad">Uninstall</button>
<button data-intention="install" class="good">Install</button>
</div>
</div>
</div>
<div class="app-list"></div>
</div>

<div id="settings" class="page hidden">
Expand All @@ -124,7 +48,7 @@
<span>
https://github.com/overte-org/community-apps/blob/master/applications/metadata.js
</span>
<button ">O</button>
<button>O</button>
<button class="bad">X</button>
</div>
</div>
Expand Down Expand Up @@ -170,7 +94,7 @@
<div class="listing color-secondary">
<div class="app-info">
<div class="icon">
<img src="" />
<img src="" />
</div>
<div class="body">
<div class="title"></div>
Expand All @@ -179,7 +103,9 @@
</div>
<div class="app-actions horizontial-button-container">
<button data-intention="view">View</button>
<button data-intention="uninstall"class="bad">Uninstall</button>
<button data-intention="uninstall" class="bad hidden">
Uninstall
</button>
<button data-intention="install" class="good">Install</button>
</div>
</div>
Expand Down
Loading

0 comments on commit cc85933

Please sign in to comment.