From 18cfef65b865fea536045904808c201b3c123688 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Tue, 27 Aug 2024 20:02:01 -0700 Subject: [PATCH] Attempt to open apps from URL only if user is authenticated and desktop is loaded --- src/gui/src/UI/UIDesktop.js | 23 +++++++++++++++++++++++ src/gui/src/initgui.js | 26 +------------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/gui/src/UI/UIDesktop.js b/src/gui/src/UI/UIDesktop.js index 18d5e4d1..8a0ea744 100644 --- a/src/gui/src/UI/UIDesktop.js +++ b/src/gui/src/UI/UIDesktop.js @@ -1022,6 +1022,29 @@ async function UIDesktop(options){ // adjust window container to take into account the toolbar height $('.window-container').css('top', window.toolbar_height); + + //-------------------------------------------------------------------------------------- + // Determine if an app was launched from URL + // i.e. https://puter.com/app/ + //-------------------------------------------------------------------------------------- + if(window.url_paths[0]?.toLocaleLowerCase() === 'app' && window.url_paths[1]){ + window.app_launched_from_url = window.url_paths[1]; + // get app metadata + try{ + window.app_launched_from_url = await puter.apps.get(window.url_paths[1]) + window.is_fullpage_mode = window.app_launched_from_url.metadata?.fullpage_on_landing ?? false; + }catch(e){ + console.error(e); + } + + // get query params, any param that doesn't start with 'puter.' will be passed to the app + window.app_query_params = {}; + for (let [key, value] of window.url_query_params) { + if(!key.startsWith('puter.')) + window.app_query_params[key] = value; + } + } + // --------------------------------------------- // Run apps from insta-login URL // --------------------------------------------- diff --git a/src/gui/src/initgui.js b/src/gui/src/initgui.js index a74763de..b2a3e66b 100644 --- a/src/gui/src/initgui.js +++ b/src/gui/src/initgui.js @@ -188,30 +188,7 @@ window.initgui = async function(options){ // will hold the result of the whoami API call let whoami; - const url_paths = window.location.pathname.split('/').filter(element => element); - - //-------------------------------------------------------------------------------------- - // Determine if an app was launched from URL - // i.e. https://puter.com/app/ - //-------------------------------------------------------------------------------------- - if(url_paths[0]?.toLocaleLowerCase() === 'app' && url_paths[1]){ - window.app_launched_from_url = url_paths[1]; - - // get app metadata - try{ - window.app_launched_from_url = await puter.apps.get(window.app_launched_from_url) - window.is_fullpage_mode = window.app_launched_from_url.metadata?.fullpage_on_landing ?? false; - }catch(e){ - console.error(e); - } - - // get query params, any param that doesn't start with 'puter.' will be passed to the app - window.app_query_params = {}; - for (let [key, value] of window.url_query_params) { - if(!key.startsWith('puter.')) - window.app_query_params[key] = value; - } - } + window.url_paths = window.location.pathname.split('/').filter(element => element); //-------------------------------------------------------------------------------------- // Extract 'action' from URL @@ -235,7 +212,6 @@ window.initgui = async function(options){ window.is_fullpage_mode = true; } - // Launch services before any UI is rendered await launch_services(options);