2023-03-21 19:08:04 -04:00
|
|
|
async function fetch_info(apps) {
|
|
|
|
let result = {};
|
|
|
|
for (let [key, value] of Object.entries(apps)) {
|
|
|
|
let blob = await ssb.blobGet(value);
|
|
|
|
blob = blob ? utf8Decode(blob) : '{}';
|
|
|
|
result[key] = JSON.parse(blob);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-12-28 12:48:21 -05:00
|
|
|
async function main() {
|
2023-03-21 19:08:04 -04:00
|
|
|
var apps = await fetch_info(await core.apps());
|
|
|
|
var core_apps = await fetch_info(await core.apps('core'));
|
2021-12-28 12:48:21 -05:00
|
|
|
var doc = `<!DOCTYPE html>
|
|
|
|
<html>
|
2023-03-21 12:54:06 -04:00
|
|
|
<head>
|
|
|
|
<style>
|
|
|
|
.container {
|
|
|
|
display: grid;
|
2023-03-21 19:08:04 -04:00
|
|
|
grid-template-columns: repeat(auto-fill, 64px);
|
2023-03-21 12:54:06 -04:00
|
|
|
justify-content: space-around;
|
|
|
|
}
|
|
|
|
.app {
|
2023-03-21 19:08:04 -04:00
|
|
|
height: 96px;
|
|
|
|
width: 64px;
|
2023-03-21 12:54:06 -04:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
|
|
|
.app > a {
|
|
|
|
text-decoration: none;
|
2023-03-21 19:08:04 -04:00
|
|
|
max-width: 64px;
|
2023-03-21 12:54:06 -04:00
|
|
|
text-overflow: ellipsis ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
2021-12-28 12:48:21 -05:00
|
|
|
<body style="background: #888">
|
2023-03-21 21:19:53 -04:00
|
|
|
<h1 id="apps_title">Apps</h1>
|
2023-03-21 12:54:06 -04:00
|
|
|
<div id="apps" class="container"></div>
|
2022-01-25 21:49:45 -05:00
|
|
|
<h1>Core Apps</h1>
|
2023-03-21 12:54:06 -04:00
|
|
|
<div id="core_apps" class="container"></div>
|
2021-12-28 12:48:21 -05:00
|
|
|
</body>
|
|
|
|
<script>
|
2022-01-25 21:49:45 -05:00
|
|
|
function populate_apps(id, name, apps) {
|
|
|
|
var list = document.getElementById(id);
|
2022-05-25 20:03:46 -04:00
|
|
|
for (let app of Object.keys(apps).sort()) {
|
2023-03-21 12:54:06 -04:00
|
|
|
let div = list.appendChild(document.createElement('div'));
|
|
|
|
div.classList.add('app');
|
|
|
|
|
|
|
|
let icon_a = document.createElement('a');
|
|
|
|
let icon = document.createElement('div');
|
2023-03-21 19:08:04 -04:00
|
|
|
icon.appendChild(document.createTextNode(apps[app].emoji || '📦'));
|
2023-03-21 12:54:06 -04:00
|
|
|
icon.style.fontSize = 'xxx-large';
|
|
|
|
icon_a.appendChild(icon);
|
|
|
|
icon_a.href = '/~' + name + '/' + app + '/';
|
|
|
|
icon_a.target = '_top';
|
|
|
|
div.appendChild(icon_a);
|
|
|
|
|
|
|
|
let a = document.createElement('a');
|
|
|
|
a.appendChild(document.createTextNode(app));
|
2022-01-25 21:49:45 -05:00
|
|
|
a.href = '/~' + name + '/' + app + '/';
|
|
|
|
a.target = '_top';
|
2023-03-21 12:54:06 -04:00
|
|
|
div.appendChild(a);
|
2022-01-25 21:49:45 -05:00
|
|
|
}
|
2021-12-28 12:48:21 -05:00
|
|
|
}
|
2023-03-21 21:20:57 -04:00
|
|
|
document.getElementById('apps_title').innerText = "~${escape(core.user.credentials?.session?.name || 'guest')}'s Apps";
|
2022-10-12 08:27:32 -04:00
|
|
|
populate_apps('apps', '${core.user.credentials?.session?.name}', ${JSON.stringify(apps)});
|
2022-01-25 21:49:45 -05:00
|
|
|
populate_apps('core_apps', 'core', ${JSON.stringify(core_apps)});
|
2021-12-28 12:48:21 -05:00
|
|
|
</script>
|
2023-03-24 20:46:40 -04:00
|
|
|
</html>`;
|
2021-12-28 12:48:21 -05:00
|
|
|
app.setDocument(doc);
|
|
|
|
}
|
|
|
|
|
2023-03-21 19:08:04 -04:00
|
|
|
main();
|