Skip to content

Commit

Permalink
Implement puter.ui.wasLaunchedWithItems()
Browse files Browse the repository at this point in the history
  • Loading branch information
jelveh committed Jan 20, 2025
1 parent f13fa25 commit 55f3f07
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/puter-js/src/modules/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,15 @@ class UI extends EventListener {
this.#onItemsOpened = callback;
}

// Check if the app was launched with items
// This is useful for apps that are launched with items (e.g. when a file is opened with the app)
wasLaunchedWithItems = function() {
const URLParams = new URLSearchParams(window.location.search);
return URLParams.has('puter.item.name') &&
URLParams.has('puter.item.uid') &&
URLParams.has('puter.item.read_url');
}

onLaunchedWithItems = function(callback) {
// Check if a file was opened with this app, i.e. check URL parameters of window/iframe
// Even though the file has been opened when the app is launched, we need to wait for the onLaunchedWithItems callback to be set
Expand Down

0 comments on commit 55f3f07

Please sign in to comment.