mirror of
https://github.com/HeyPuter/puter.git
synced 2026-09-26 15:15:58 +00:00
dev: lay the groundwork for client FS relay
Adds XDIncomingService to manage messages from another window. IPC now registers with XDIncoming and reports whether it was handled, that way messages intended to reach GUI can be reliably ignored. On GUI-side, XDIncomingService will be used by FSRelayService (not yet implemented) to handle requests for filesystem operations from another window. On App-side, XDIncomingService might be used by the PostMessageFS client-side filesystem implementation terminal to listen for filesystem events that were relayed by GUI (after a permission check) from their original websocket source. Either that, or we'll open a filesystem socket for each app using that app's token. NoPuterYetService was added because IPC.js is loaded before globalThis.puter exists, and was the easiest way to still allow IPC's listener to be registered with XDIncomingService. APIAccessService was added. This service currently holds auth_token and api_token and does nothing else. FilesystemService listens to this to maintain a websocket connection. APIAccessService will help to manage the complexity of all further code dependent on being informed about changes to the auth token or origin. Currently in puter.js these are passed around to several modules which manage the same piece of state information independantly.
This commit is contained in:
+15
-6
@@ -44,12 +44,12 @@ window.ipc_handlers = {};
|
||||
*
|
||||
* Precautions are taken to ensure proper usage of appInstanceIDs and other sensitive information.
|
||||
*/
|
||||
window.addEventListener('message', async (event) => {
|
||||
const ipc_listener = async (event, handled) => {
|
||||
const app_env = event.data?.env ?? 'app';
|
||||
|
||||
// Only process messages from apps
|
||||
if(app_env !== 'app')
|
||||
return;
|
||||
return handled.resolve(false);
|
||||
|
||||
// --------------------------------------------------------
|
||||
// A response to a GUI message received from the app.
|
||||
@@ -61,7 +61,7 @@ window.addEventListener('message', async (event) => {
|
||||
delete window.appCallbackFunctions[event.data.original_msg_id];
|
||||
|
||||
// Done
|
||||
return;
|
||||
return handled.resolve(false);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
@@ -70,18 +70,20 @@ window.addEventListener('message', async (event) => {
|
||||
|
||||
// `data` and `msg` are required
|
||||
if(!event.data || !event.data.msg){
|
||||
return;
|
||||
return handled.resolve(false);
|
||||
}
|
||||
|
||||
// `appInstanceID` is required
|
||||
if(!event.data.appInstanceID){
|
||||
console.error(`appInstanceID is needed`);
|
||||
return;
|
||||
return handled.resolve(false);
|
||||
}else if(!window.app_instance_ids.has(event.data.appInstanceID)){
|
||||
console.error(`appInstanceID is invalid`);
|
||||
return;
|
||||
return handled.resolve(false);
|
||||
}
|
||||
|
||||
handled.resolve(true);
|
||||
|
||||
const $el_parent_window = $(window.window_for_app_instance(event.data.appInstanceID));
|
||||
const parent_window_id = $el_parent_window.attr('data-id');
|
||||
const $el_parent_disable_mask = $el_parent_window.find('.window-disable-mask');
|
||||
@@ -1522,4 +1524,11 @@ window.addEventListener('message', async (event) => {
|
||||
status_code,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if ( ! window.when_puter_happens ) window.when_puter_happens = [];
|
||||
window.when_puter_happens.push(async () => {
|
||||
await puter.services.wait_for_init(['xd-incoming']);
|
||||
const svc_xdIncoming = puter.services.get('xd-incoming');
|
||||
svc_xdIncoming.register_filter_listener(ipc_listener);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user