tweak: cleanup and comment

This commit is contained in:
KernelDeimos 2024-08-28 21:58:33 -04:00 committed by Eric Dubé
parent c86df11abd
commit 1cd21ee658
3 changed files with 21 additions and 4 deletions

View File

@ -29,7 +29,6 @@ import download from './helpers/download.js';
import path from "./lib/path.js";
import UIContextMenu from './UI/UIContextMenu.js';
import update_mouse_position from './helpers/update_mouse_position.js';
import launch_app from './helpers/launch_app.js';
import item_icon from './helpers/item_icon.js';
window.ipc_handlers = {};
@ -90,14 +89,21 @@ window.addEventListener('message', async (event) => {
const app_name = $(target_iframe).attr('data-app');
const app_uuid = $el_parent_window.attr('data-app_uuid');
// New IPC handlers should be registered here.
// Do this by calling `register_ipc_handler` of IPCService.
if ( window.ipc_handlers.hasOwnProperty(event.data.msg) ) {
console.log('got message to new IPC handler', event.data.msg);
// The IPC context contains information about the call
const ipc_context = {
appInstanceId: event.data.appInstanceID,
};
// Registered IPC handlers are an object with a `handle()`
// method. We call it "spec" here, meaning specification.
const spec = window.ipc_handlers[event.data.msg];
await spec.handler(event.data, { msg_id, ipc_context });
console.log('^ end of that thing');
// Early-return to avoid redundant invokation of any
// legacy IPC handler.
return;
}

View File

@ -2,6 +2,10 @@ import { Service } from "../definitions.js";
import launch_app from "../helpers/launch_app.js";
export class ExecService extends Service {
static description = `
Manages instances of apps on the Puter desktop.
`
async _init ({ services }) {
const svc_ipc = services.get('ipc');
svc_ipc.register_ipc_handler('launchApp', {
@ -9,13 +13,16 @@ export class ExecService extends Service {
});
}
// This method is exposed to apps via IPCService.
launchApp ({ app_name, args }, { ipc_context, msg_id } = {}) {
// This mechanism will be replated with xdrpc soon
const child_instance_id = window.uuidv4();
window.child_launch_callbacks[child_instance_id] = {
parent_instance_id: event.data.appInstanceID,
launch_msg_id: msg_id,
};
// launch child app
// The "body" of this method is in a separate file
launch_app({
name: app_name,
args: args ?? {},

View File

@ -1,6 +1,10 @@
import { Service } from "../definitions.js";
export class IPCService extends Service {
static description = `
Allows other services to expose methods to apps.
`
async _init () {
//
}