Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CfW: When Clipboard permission is denied prevent the app from crashing #1905

Open
wants to merge 1 commit into
base: jb-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ class JsPlatformClipboard : Clipboard {
getW3CClipboard()
}

private val emptyClipboardItems = emptyArray<ClipboardItem>()

override suspend fun getClipEntry(): ClipEntry? {
val items = nativeClipboard.read().await()
val items = nativeClipboard.read().catch {
// The most common reason is that the permission was denied
println("Failed to read from Clipboard: $it")
emptyClipboardItems
}.then {
it
}.await()

if (items.isEmpty()) return null
return ClipEntry(items)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ class WasmPlatformClipboard : Clipboard {
getW3CClipboard()
}

private val emptyClipboardItems = emptyArray<ClipboardItem>().toJsArray()

override suspend fun getClipEntry(): ClipEntry? {
val items = nativeClipboard.read().await<JsArray<ClipboardItem>>()
val items = nativeClipboard.read().catch {
// The most common reason is that the permission was denied
println("Failed to read from Clipboard: $it")
emptyClipboardItems
}.then {
it
}.await<JsArray<ClipboardItem>>()

if (items.length == 0) return null
return ClipEntry(items)
}
Expand Down