-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
When installing snapdrop as PWA by adding it to home screen, snapdrop could register itself as a share target to the device.
By doing that files can simply be send via snapdrop from the native share menu.
The workflow for users would then be reduced to the following:
- User shares File(s)/Photo(s) directly from native share menu to the installed snapdrop PWA
- User taps on receiver to send files immediatly
Integration would look like this:
- web manifest has a attribute
share_targetwhich tells the launcher to publish the PWA as a share target on install
{
"share_target": {
"action": "/",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"url": "url",
"text": "text",
"files": [
{
"name": "photos",
"accept": ["image/*"]
}
]
}
}
}The files attribute would need to be filled with every filetype we accept. */* should work to accept everything.
2. The files shared should be saved to Cache or IndexDB via service worker on fetch event:
self.addEventListener("fetch", (event) => {
// Regular requests not related to Web Share Target.
if (event.request.method !== "POST") {
event.respondWith(fetch(event.request));
return;
}
// Requests related to Web Share Target.
event.respondWith(
(async () => {
const formData = await event.request.formData();
const files = formData.get("files") || "";
const text = formData.get("text") || "";
const url = formData.get("url") || "";
// if files.length > 0 save files to IndexedDB or Cache
// save url and text to IndexedDB or Cache
// redirect to url with flag to directly enter share UI
return Response.redirect("/?share-target=true", 303);
})()
);
});- Redirect to sth like
https://snapdrop.net/?share-target=true - Detect
share-target=trueand enter Sharing UI to send contents files / text directly (similar to PasteUI on Implement Paste UI for selecting recipient peer and other paste related stuff #488 ) - When clicking a target peer, instead of opening an input menu the shared contents are send directly:
if files exists: send files
elseif url exists: append url to text and send as text
else: send text - clear files, text and url entries in Cache resp. IndexedDB and remove share-target attribute from url / location.history
Bellisario, JustSch and MrPropre
Metadata
Metadata
Assignees
Labels
No labels