wails: `ClipboardSetText` successfully called, but actually failed

Description

On Macbook M1 Pro, after building, the ClipboardSetText is called. The feedback is successful, but the actual clipboard is empty

To Reproduce

ClipboardSetText(str).then(()=>{
    console.log('success')
  }).catch((err)=>{
    console.err('fail',err)
})

Expected behaviour

It should be possible to paste directly

Screenshots

No response

Attempted Fixes

No response

System Details

# System

OS           | MacOS    
Version      | 13.2.1     
Go Version   | go1.18.10
Platform     | darwin   
Architecture | arm64    

# Wails

Version | v2.4.1

# Dependencies

Dependency                | Package Name | Status    | Version     
Xcode command line tools  | N/A          | Installed | 2396        
npm                       | N/A          | Installed | 8.1.2       
*Xcode                    | N/A          | Installed | 14.2 (14C18)
*upx                      | N/A          | Available |             
*nsis                     | N/A          | Available |             
* - Optional Dependency

Additional context

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

This would make an ideal v3 plugin

Hey, I tested out the main branch and it does indeed work.

BUT… there is a potential bug/unintended functionality regarding osascript that was breaking the clipboard for me.

I was using osascript with a prompt, kind of like this

osascript -e 'do shell script "./NicelandVPN" with prompt "Run NicelandVPN as admin" with administrator privileges'

The problem that was occurring is that the GUI prompt which let’s you insert your username/password is grabbing the stdin/TTY (which is used by the clipboard to deliver text) and it was not returning it to the binary being executed by the osascript.

This lead me to abandon the osascript path and instead writing a C file that uses the macos internal Security Framework to generate admin credentials.

I will make the C code available via a git repository tomorrow if you want to use it in order to enable users to launch wails.io apps as administrator with a GUI prompt.

The main culprit for no data being returned is probably the pasteboard* daemon dying (see: [3]). If that daemon dies and set and gets/copies + pasts won’t work properly. And even if the daemon comes back up the app will maybe need to be completely restarted. (*pasteboard is what Apple calls a clipboard)

Inconsistencies could also be due to how pbpaste works when there are multiple items in various formats stored in the clipboard. All the wails implementations are using the system’s general pasteboard either implicitly or explicitly in wails v2 or wails v3 respectively.

In wails v2…(see: [5])
The pbcopy command is called directly via exec and piped input over stdin putting whatever text is given into the general pasteboard.

The pbpaste command is called the same way and the output from stdout is returned. However, no additional options for pbpaste are used. If you look at the manpage for pbpaste you’ll notice -Prefer as an option.

This option is not used explicitly in the wails v2 implementation. However, the reason this option exists is because a pasteboard can have multiple types of data stored in it (see: [7, 8]). pbpaste will check the pasteboard for a representation of each of these types of data. If none are present it will return nothing.

And in general there are other known problems (see: [4]) with getting back rich text as rich text.

TL;DR It’s possible that…

  • You can get back data from the clipboard with “data loss”. (Ex. Rich text becoming ASCII plaintext).
  • You can get back no data from clipboard when the type of data stored in he clipboard is not ASCII, PS, or RTF data.
  • You can get back old/incorrect/no data from the clipboard because the pboard(clipboard/pasteboard) daemon has died/restarted.

In wails v3… I refer you to the implementation in [6] using the information from above

Refs:

  1. man pbpaste
  2. man pbcopy
  3. restarting pboard daemon + apps
  4. rich text coming out of pasteboard as plain text
  5. wails v2 darwin clipboard implementation
  6. wails v3 darwin clipboard implementation
  7. Apple Pasteboard overview
  8. Apple Pasteboard programmer guide

image

There is cmd+v in the packaged program menu.

Everything is normal in wails dev, but wails build is packaged and it prompts that the copy is successful, but the actual cmd+v does not have any data