Skip to content

Commit

Permalink
tweak: cleanup and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Aug 29, 2024
1 parent 7249429 commit 53ab967
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/gui/src/IPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion src/gui/src/services/ExecService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ 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', {
handler: this.launchApp.bind(this),
});
}

// 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 ?? {},
Expand Down
4 changes: 4 additions & 0 deletions src/gui/src/services/IPCService.js
Original file line number Diff line number Diff line change
@@ -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 () {
//
}
Expand Down

0 comments on commit 53ab967

Please sign in to comment.