Skip to content

Commit

Permalink
Add App Store PML support!
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsLap committed May 26, 2024
1 parent 9f39d46 commit 03fbce4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
26 changes: 19 additions & 7 deletions pkgs/apps/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,28 @@ export default {

async function installApp(pkg, app, force = false) {
let appNameSafe = makeAppNameSafe(pkg);
let fileExtension = "." + app.assets.path.split(".").pop();
if (fileExtension === ".js") fileExtension = ".app";

await fetch(
`${host}pkgs/${pkg}/${app.assets.path}?t=` + performance.now()
)
.then(async (e) => {
console.log(await vfs.whatIs(`${asFilePath}/${appNameSafe}.app`));
console.log(
await vfs.whatIs(`${asFilePath}/${appNameSafe}${fileExtension}`)
);
if (
(await vfs.whatIs(`${asFilePath}/${appNameSafe}.app`)) ===
null ||
(await vfs.whatIs(
`${asFilePath}/${appNameSafe}${fileExtension}`
)) === null ||
force == true
) {
let result = await e.text();

await vfs.writeFile(`${asFilePath}/${appNameSafe}.app`, result);
await vfs.writeFile(
`${asFilePath}/${appNameSafe}${fileExtension}`,
result
);

const img = await new Promise((resolve, reject) => {
fetch(`${host}pkgs/${pkg}/${app.assets.icon}`)
Expand All @@ -280,13 +289,16 @@ export default {

pages.appPage(app, pkg);
} else if (
(await vfs.whatIs(`${asFilePath}/${appNameSafe}.app`)) ===
"file"
(await vfs.whatIs(
`${asFilePath}/${appNameSafe}${fileExtension}`
)) === "file"
) {
await Root.Core.startPkg(
"data:text/javascript," +
encodeURIComponent(
await vfs.readFile(`${asFilePath}/${appNameSafe}.app`)
await vfs.readFile(
`${asFilePath}/${appNameSafe}${fileExtension}`
)
),
false,
true
Expand Down
49 changes: 33 additions & 16 deletions pkgs/lib/FileMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ export default {
c.startPkg(shrtFile.fullName, true, true);
},
};
} else if (ext === "app" && path.startsWith("Registry/AppStore/")) {
} else if (
(ext === "app" && path.startsWith("Registry/AppStore/")) ||
(ext === "pml" && path.startsWith("Registry/AppStore/"))
) {
const asExists = await vfs.whatIs(
"Registry/AppStore/_AppStoreIndex.json"
);
Expand All @@ -214,21 +217,35 @@ export default {
if (window.__DEBUG === true) console.log(fileName, as);

if (fileName in as) {
return {
name: as[fileName].name,
icon: `<img style="border-radius:50%;width:24px;height:24px" src="${as[fileName].icon}">`,
fullName: as[fileName].shortDescription,
ctxMenuApp: undefined,
invalid: false,
async onClick() {
C.startPkg(
"data:text/javascript," +
encodeURIComponent(await vfs.readFile(path)),
false,
false
);
},
};
if (ext === "app") {
return {
name: as[fileName].name,
icon: `<img style="border-radius:50%;width:24px;height:24px" src="${as[fileName].icon}">`,
fullName: as[fileName].shortDescription,
ctxMenuApp: undefined,
invalid: false,
async onClick() {
C.startPkg(
"data:text/javascript," +
encodeURIComponent(await vfs.readFile(path)),
false,
false
);
},
};
} else {
return {
name: as[fileName].name,
icon: `<img style="border-radius:50%;width:24px;height:24px" src="${as[fileName].icon}">`,
fullName: as[fileName].shortDescription,
ctxMenuApp: undefined,
invalid: false,
async onClick() {
let x = await c.startPkg("apps:PML", true, true);
x.proc.send({ type: "loadFile", path });
},
};
}
} else {
return {
name: "App Store App (unknown)",
Expand Down
4 changes: 2 additions & 2 deletions pkgs/ui/Desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export default {
return { type: "desktop", item: f.item };
});
const installedApps = (await vfs.list("Root/Pluto/apps"))
.filter((f) => f.item.endsWith(".app"))
.filter((f) => f.item.endsWith(".app") || f.item.endsWith(".pml"))
.map((f) => {
return { type: "installed", item: f.item };
});
Expand All @@ -381,7 +381,7 @@ export default {
if (asExists !== null) {
console.log(asExists);
asApps = (await vfs.list("Registry/AppStore"))
.filter((f) => f.item.endsWith(".app"))
.filter((f) => f.item.endsWith(".app") || f.item.endsWith(".pml"))
.map((f) => {
return { type: "appStore", item: f.item };
});
Expand Down

0 comments on commit 03fbce4

Please sign in to comment.