mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
tweak: cleanup and comment
This commit is contained in:
parent
c86df11abd
commit
1cd21ee658
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 ?? {},
|
||||
|
@ -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 () {
|
||||
//
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user