Keep track of app_instance_ids

This commit is contained in:
Nariman Jelveh 2024-04-24 17:57:30 -07:00
parent c21c16026b
commit 25eea41f60
4 changed files with 12 additions and 4 deletions

View File

@ -112,10 +112,11 @@ window.puter = (function() {
// The default APIOrigin is https://api.puter.com. However, if the URL contains a `puter.api_origin` query parameter,
// then that value is used as the APIOrigin. If the URL contains a `puter.domain` query parameter, then the APIOrigin
// is constructed as `https://api.<puter.domain>`.
// This should only be done when the SDK is running in 'app' mode.
this.APIOrigin = this.defaultAPIOrigin;
if(URLParams.has('puter.api_origin')){
if(URLParams.has('puter.api_origin') && this.env === 'app'){
this.APIOrigin = decodeURIComponent(URLParams.get('puter.api_origin'));
}else if(URLParams.has('puter.domain')){
}else if(URLParams.has('puter.domain') && this.env === 'app'){
this.APIOrigin = 'https://api.' + URLParams.get('puter.domain');
}

View File

@ -71,7 +71,10 @@ window.addEventListener('message', async (event) => {
// `appInstanceID` is required
if(!event.data.appInstanceID){
console.log(`appInstanceID is needed`);
console.error(`appInstanceID is needed`);
return;
}else if(!window.app_instance_ids.has(event.data.appInstanceID)){
console.error(`appInstanceID is invalid`);
return;
}
@ -165,7 +168,6 @@ window.addEventListener('message', async (event) => {
center: event.data.options.center,
show_in_taskbar: event.data.options.show_in_taskbar,
iframe_srcdoc: event.data.options.content,
iframe_url: event.data.options.url,
parent_uuid: event.data.appInstanceID,
})
}

View File

@ -24,6 +24,7 @@ window.window_nav_history = {};
window.window_nav_history_current_position = {};
window.progress_tracker = [];
window.upload_item_global_id = 0;
window.app_instance_ids = new Set();
window.download_progress = [];
window.download_item_global_id = 0;

View File

@ -1762,6 +1762,10 @@ window.launch_app = async (options)=>{
// ...and finally append utm_source=puter.com to the URL
iframe_url.searchParams.append('utm_source', 'puter.com');
// register app_instance_uid
window.app_instance_ids.add(uuid);
// open window
el_win = UIWindow({
element_uuid: uuid,
title: title,