Skip to content

Commit

Permalink
make the overlay that appears after a homebrew is launched munch more…
Browse files Browse the repository at this point in the history
… informative
  • Loading branch information
john-tornblom committed May 29, 2024
1 parent 5c96c6b commit 303d1a9
Show file tree
Hide file tree
Showing 22 changed files with 1,485 additions and 678 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ please file an issue before you start to work on you changes. This will allow us
to discuss the solution properly before you commit time and effort.

## License
ps5-payload-websrv uses [smoothscroll][smoothscroll] and [navigo][navigo] to
ps5-payload-websrv uses [smoothscroll][smoothscroll] and [xterm.js][xterm.js] to
render its web interface, both which are licenced under the MIT licence. Unless
otherwhise explicitly specified inside induvidual files, The rest is the source
code included with ps5-payload-websrv are licensed under the GPLv3+.
Expand All @@ -70,5 +70,5 @@ code included with ps5-payload-websrv are licensed under the GPLv3+.
[issues]: https://github.com/ps5-payload-dev/websrv/issues/new
[elfldr]: https://github.com/ps5-payload-dev/elfldr
[smoothscroll]: https://github.com/iamdustan/smoothscroll
[navigo]: https://github.com/krasimir/navigo
[xterm.js]: https://github.com/xtermjs/xterm.js
[launcher]: https://github.com/ps5-payload-dev/websrv/blob/master/homebrew/IV9999-FAKE00001_00-HOMEBREWLOADER01.pkg?raw=true
53 changes: 28 additions & 25 deletions assets/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,73 @@ class DirectoryListing {
* @param {string} name
* @param {string} mode
*/
constructor(name, mode) {
this.name = name;
this.mode = mode;
constructor(name, mode) {
this.name = name;
this.mode = mode;
}

isDir() {
return this.mode === 'd' && !ignoredFileNames.includes(this.name);
return this.mode === "d" && !ignoredFileNames.includes(this.name);
}

isFile() {
return this.mode === '-' && !ignoredFileNames.includes(this.name);
return this.mode === "-" && !ignoredFileNames.includes(this.name);
}
}

// @ts-ignore
const baseURL = window.location.origin == 'null' ? 'http://127.0.0.1:8080' : window.location.origin;
const ignoredFileNames = ['.', '..'];
const baseURL = window.location.origin == "null" ? "http://127.0.0.1:8080" : window.location.origin;
const ignoredFileNames = [".", ".."];
class ApiClient {
/**
* @param {string} path
* @param {(string | string[])?} [args]
* @returns {Promise<boolean>} only returns true, throws error if not success code
* @returns {Promise<ReadableStream<Uint8Array>?>} only returns true, throws error if not success code
*/
static async launchApp(path, args = null) {
let params = new URLSearchParams({
'path': path
"pipe": "1",
"path": path
});

if (typeof args === 'string') {
params.append('args', args.replaceAll(" ", "\\ "));
if (typeof args === "string") {
// @ts-ignore
params.append("args", args.replaceAll(" ", "\\ "));
} else if (Array.isArray(args)) {
params.append('args', args.map(arg => arg.replaceAll(" ", "\\ ")).join(' '));
// @ts-ignore
params.append("args", args.map(arg => arg.replaceAll(" ", "\\ ")).join(" "));
}

let uri = baseURL + '/hbldr?' + params.toString();
let uri = baseURL + "/hbldr?" + params.toString();

let response = await fetch(uri);
if (response.status !== 200) {
throw new Error('Failed to launch app, status code: ' + response.status);
throw new Error("Failed to launch app, status code: " + response.status);
}

return true;
return response.body;
}

/**
* @param {string} path
* @returns {Promise<DirectoryListing[]?>}
*/
static async fsListDir(path) {
if (!path.endsWith('/')) {
path += '/';
if (!path.endsWith("/")) {
path += "/";
}

let response = await fetch(baseURL + "/fs" + path + "?fmt=json");
if (!response.ok) {
return null;
}
let data = await response.json();
data.sort((x, y) => x.mode == y.mode ?
x.name.localeCompare(y.name) :
x.mode.localeCompare(y.mode));
data.sort((x, y) => x.mode == y.mode ?
x.name.localeCompare(y.name) :
y.mode.localeCompare(x.mode));

return data.filter(entry => !ignoredFileNames.includes(entry.name)).map(entry =>
new DirectoryListing(entry.name, entry.mode));
new DirectoryListing(entry.name, entry.mode));
}

/**
Expand All @@ -96,7 +99,7 @@ class ApiClient {
* @returns {Promise<ReadableStream<Uint8Array>?>}
*/
static async fsGetFileStream(path) {
if (path.endsWith('/') || !path.startsWith('/')) {
if (path.endsWith("/") || !path.startsWith("/")) {
return null;
}

Expand All @@ -113,7 +116,7 @@ class ApiClient {
* @returns {Promise<string?>}
*/
static async fsGetFileText(path) {
if (path.endsWith('/') || !path.startsWith('/')) {
if (path.endsWith("/") || !path.startsWith("/")) {
return null;
}

Expand Down
Loading

0 comments on commit 303d1a9

Please sign in to comment.