瀏覽代碼

Keep track of `app_instance_id`s

Nariman Jelveh 1 年之前
父節點
當前提交
25eea41f60
共有 4 個文件被更改,包括 12 次插入4 次删除
  1. 3 2
      packages/puter-js/src/index.js
  2. 4 2
      src/IPC.js
  3. 1 0
      src/globals.js
  4. 4 0
      src/helpers.js

+ 3 - 2
packages/puter-js/src/index.js

@@ -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');
             }
 

+ 4 - 2
src/IPC.js

@@ -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,
             })
         }

+ 1 - 0
src/globals.js

@@ -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;

+ 4 - 0
src/helpers.js

@@ -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,