This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
forked from nolanlawson/pinafore
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: accept files in web share target (nolanlawson#1992)
fixes nolanlawson#1009
- Loading branch information
1 parent
5e61a85
commit 5e7440a
Showing
17 changed files
with
122 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
import { store } from '../_store/store' | ||
import { importShowComposeDialog } from '../_components/dialog/asyncDialogs/importShowComposeDialog.js' | ||
import { importShowComposeDialog } from '../_components/dialog/asyncDialogs/importShowComposeDialog' | ||
import { database } from '../_database/database' | ||
import { doMediaUpload } from './media' | ||
|
||
export async function showShareDialogIfNecessary () { | ||
const { isUserLoggedIn, openShareDialog } = store.get() | ||
store.set({ openShareDialog: false }) | ||
if (isUserLoggedIn && openShareDialog) { | ||
const showComposeDialog = await importShowComposeDialog() | ||
showComposeDialog() | ||
const { isUserLoggedIn } = store.get() | ||
if (!isUserLoggedIn) { | ||
return | ||
} | ||
const data = await database.getWebShareData() | ||
if (!data) { | ||
return | ||
} | ||
|
||
// delete from IDB and import the dialog in parallel | ||
const [showComposeDialog] = await Promise.all([ | ||
importShowComposeDialog(), | ||
database.deleteWebShareData() | ||
]) | ||
|
||
console.log('share data', data) | ||
const { title, text, url, file } = data | ||
|
||
// url is currently ignored on Android, but one can dream | ||
// https://web.dev/web-share-target/#verifying-shared-content | ||
const composeText = [title, text, url].filter(Boolean).join('\n\n') | ||
|
||
store.clearComposeData('dialog') | ||
store.setComposeData('dialog', { text: composeText }) | ||
store.save() | ||
|
||
showComposeDialog() | ||
if (file) { // start the upload once the dialog is in view so it shows the loading spinner and everything | ||
/* no await */ doMediaUpload('dialog', file) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { get, set, close, del } from '../_thirdparty/idb-keyval/idb-keyval' | ||
import { WEB_SHARE_TARGET_DATA_IDB_KEY } from '../_static/share' | ||
|
||
export function deleteWebShareData () { | ||
return del(WEB_SHARE_TARGET_DATA_IDB_KEY) | ||
} | ||
|
||
export function setWebShareData (data) { | ||
return set(WEB_SHARE_TARGET_DATA_IDB_KEY, data) | ||
} | ||
|
||
export function getWebShareData () { | ||
return get(WEB_SHARE_TARGET_DATA_IDB_KEY) | ||
} | ||
|
||
export function closeKeyValIDBConnection () { | ||
return close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const WEB_SHARE_TARGET_DATA_IDB_KEY = 'web-share-data' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.