mirror of
https://github.com/HeyPuter/puter
synced 2024-11-15 06:15:47 +00:00
Add closeApp message
Sending a 'closeApp' message allows an app to close a target app, if it has permission to do so. Currently, permission is granted if the requesting app is the parent of the target app, or has godmode set.
This commit is contained in:
parent
c69a0abfa9
commit
21c64e827b
37
src/IPC.js
37
src/IPC.js
@ -1100,6 +1100,43 @@ window.addEventListener('message', async (event) => {
|
||||
contents,
|
||||
}, targetAppOrigin);
|
||||
}
|
||||
//--------------------------------------------------------
|
||||
// closeApp
|
||||
//--------------------------------------------------------
|
||||
else if (event.data.msg === 'closeApp') {
|
||||
const { appInstanceID, targetAppInstanceID } = event.data;
|
||||
|
||||
const target_window = window_for_app_instance(targetAppInstanceID);
|
||||
if (!target_window) {
|
||||
console.warn(`Failed to close non-existent app ${targetAppInstanceID}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
const allowed = (() => {
|
||||
// Parents can close their children
|
||||
if (target_window.dataset['parent_instance_id']) {
|
||||
console.log(`⚠️ Allowing app ${appInstanceID} to close child app ${targetAppInstanceID}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
// God-mode apps can close anything
|
||||
const app_info = await get_apps(app_name);
|
||||
if (app_info.godmode === 1) {
|
||||
console.log(`⚠️ Allowing GODMODE app ${appInstanceID} to close app ${targetAppInstanceID}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: What other situations should we allow?
|
||||
return false;
|
||||
})();
|
||||
|
||||
if (allowed) {
|
||||
$(target_window).close();
|
||||
} else {
|
||||
console.warn(`⚠️ App ${appInstanceID} is not permitted to close app ${targetAppInstanceID}`);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
// exit
|
||||
|
Loading…
Reference in New Issue
Block a user