mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-06 21:20:27 -06:00
implement query param passing between browser window and app iframe
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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", {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user