From 53ab967dc06583cee600e98f8d8ea2b14d6d8581 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Wed, 28 Aug 2024 21:58:33 -0400 Subject: [PATCH] tweak: cleanup and comment --- src/gui/src/IPC.js | 12 +++++++++--- src/gui/src/services/ExecService.js | 9 ++++++++- src/gui/src/services/IPCService.js | 4 ++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/gui/src/IPC.js b/src/gui/src/IPC.js index b9f136bc..acae4ce7 100644 --- a/src/gui/src/IPC.js +++ b/src/gui/src/IPC.js @@ -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; } diff --git a/src/gui/src/services/ExecService.js b/src/gui/src/services/ExecService.js index 62e9f240..5946a075 100644 --- a/src/gui/src/services/ExecService.js +++ b/src/gui/src/services/ExecService.js @@ -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 ?? {}, diff --git a/src/gui/src/services/IPCService.js b/src/gui/src/services/IPCService.js index f2f025c8..83ac0bf3 100644 --- a/src/gui/src/services/IPCService.js +++ b/src/gui/src/services/IPCService.js @@ -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 () { // }