implement query param passing between browser window and app iframe

This commit is contained in:
Nariman Jelveh
2024-03-16 19:57:33 -07:00
parent ca30d075da
commit 8100edbef9
3 changed files with 17 additions and 0 deletions

View File

@@ -930,6 +930,7 @@ async function UIDesktop(options){
name: app_launched_from_url,
readURL: qparams.get('readURL'),
maximized: qparams.get('maximized'),
params: app_query_params ?? [],
is_fullpage: window.is_fullpage_mode,
window_options: {
stay_on_top: false,

View File

@@ -1904,6 +1904,7 @@ window.launch_app = async (options)=>{
// add app_instance_id to URL
iframe_url.searchParams.append('puter.app_instance_id', uuid);
// add app_id to URL
iframe_url.searchParams.append('puter.app.id', app_info.uuid);
@@ -1939,6 +1940,14 @@ window.launch_app = async (options)=>{
else if(options.token){
iframe_url.searchParams.append('puter.auth.token', options.token);
}
// if options.params is set, add them to the URL as query params
if(options.params && options.params.length > 0){
for (const property in options.params) {
iframe_url.searchParams.append(property, options.params[property]);
}
}
// Try to acquire app token from the server
else{
let response = await fetch(window.api_origin + "/auth/get-user-app-token", {

View File

@@ -76,6 +76,13 @@ window.initgui = async function(){
const url_paths = window.location.pathname.split('/').filter(element => element);
if(url_paths[0]?.toLocaleLowerCase() === 'app' && url_paths[1]){
window.app_launched_from_url = url_paths[1];
// 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 url_query_params) {
if(!key.startsWith('puter.'))
app_query_params[key] = value;
}
}
//--------------------------------------------------------------------------------------