tauri icon indicating copy to clipboard operation
tauri copied to clipboard

When upgrading from alpha version to beta version, I encountered the problem of not being able to copy and paste.

Open poohlaha opened this issue 1 year ago • 12 comments

I upgraded from 2.0.0-alpha to 2.0.0-beta version, including the following dependencies:

tauri-build
tauri
tauri-plugin-shell

Now I encountered the problem that text cannot be copied and pasted in the desktop version application. What permissions need to be added, otherwise it will be very inconvenient during development restrictions? My permissions are as follows: main.json

{
   "$schema": "./schemas/desktop-schema.json",
   "identifier": "default",
   "description": "Capability for the main window",
   "windows": ["main"],
   "permissions": [
     "path:default",
     "event:default",
     "window:default",
     "app:default",
     "resources:default",
     "menu:default",
     "tray:default",
     "shell:allow-open",
     "log:default",
     "dialog:allow-open"
   ]
}

poohlaha avatar Mar 12 '24 07:03 poohlaha

https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/permissions/autogenerated/reference.md

handexing avatar Mar 12 '24 07:03 handexing

Please also include the output of the tauri info command.

And just to be clear, you're talking about the ctrl/cmd + c/v shortcuts, right?

FabianLars avatar Mar 12 '24 08:03 FabianLars

Please also include the output of the tauri info command.

And just to be clear, you're talking about the ctrl/cmd + c/v shortcuts, right?

Yes, ctrl/cmd + c/v does not work in desktop applications, I don't know what permissions need to be added

poohlaha avatar Mar 12 '24 10:03 poohlaha

those shortcuts are not supposed to be behind permissions, so please show us the output of tauri info or at least tell us your OS so we can reproduce and fix this :)

FabianLars avatar Mar 12 '24 10:03 FabianLars

those shortcuts are not supposed to be behind permissions, so please show us the output of tauri info or at least tell us your OS so we can reproduce and fix this :)

computer information

macbook pro
Chip: Apple M1 Pro

Use ctrl + c to copy the text displayed on the front-end page in the application, and then use ctrl + c to paste in the input box of the front-end page. Nothing happens. Using ctrl + v in the text editor does not copy the information, but it is now in the application. Select the text in the program, use right-click -> Copy, you can copy the information, and then use right-click -> Parse to paste the information, but it will be effective, but it is more troublesome.

Use copy and paste to enter information in the background as follows

[2024-03-12][10:52:39][tao::platform_impl::platform::view][TRACE] Triggered `doCommandBySelector`
[2024-03-12][10:52:39][tao::platform_impl::platform::view][TRACE] Completed `doCommandBySelector`

poohlaha avatar Mar 12 '24 10:03 poohlaha

https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/permissions/autogenerated/reference.md

Using the tauri-plugin-clipboard-manager plugin still doesn't solve my problem Cargo.toml

tauri-plugin-clipboard-manager = "2.0.0-beta"

Code main.rs:

  tauri::Builder::default()
         .plugin(tauri_plugin_clipboard_manager::init())
         .plugin(tauri_plugin_shell::init())
         .plugin(tauri_plugin_dialog::init())
         .plugin(tauri_plugin_log::Builder::default().build())
         .setup(move |app| {
             Tray::builder(app);
             Ok(())
         })
         .invoke_handler(tauri::generate_handler![
             get_server_list,
         ])
         .run(tauri::generate_context!())
         .expect("error while running tauri application");

capabilities/main.json

{
   "$schema": "./schemas/desktop-schema.json",
   "identifier": "default",
   "description": "Capability for the main window",
   "windows": ["main"],
   "permissions": [
     "path:default",
     "event:default",
     "window:default",
     "app:default",
     "resources:default",
     "menu:default",
     "tray:default",
     "shell:allow-open",
     "log:default",
     "dialog:allow-open",
     "clipboard-manager:allow-read",
     "clipboard-manager:allow-write"
   ]
}

After adding the tauri-plugin-clipboard-manager plug-in, I saw that it has been added below gen/schemas/desktop-schema.json

image

But still can't use ctrl + c/v

poohlaha avatar Mar 12 '24 10:03 poohlaha

Can you also post the output of the tauri info command please? I don't see any issues on macos 14.4

Is your project public or do you have a minimal reproduction example?

FabianLars avatar Mar 18 '24 21:03 FabianLars

Can you also post the output of the tauri info command please? I don't see any issues on macos 14.4

Is your project public or do you have a minimal reproduction example?

So how do I use ctrl + c/v in the desktop application?

tauri info

[2024-03-12][10:52:39][tao::platform_impl::platform::view][TRACE] Triggered `doCommandBySelector`
[2024-03-12][10:52:39][tao::platform_impl::platform::view][TRACE] Completed `doCommandBySelector`

poohlaha avatar Mar 21 '24 03:03 poohlaha

So how do I use ctrl + c/v in the desktop application?

It should just work. And it also just works in my app, which is why i asked for your project or a small reproduction example.

With tauri info i meant the output if you run npm run tauri info

FabianLars avatar Mar 21 '24 10:03 FabianLars

So how do I use ctrl + c/v in the desktop application?

It should just work. And it also just works in my app, which is why i asked for your project or a small reproduction example.

With tauri info i meant the output if you run npm run tauri info

create project: image

h5 install: image

Run the project using pnpm tauri dev, it's ok。

Add the following package to cargo.toml: old:

tauri = { version = "2.0.0-beta", features = [] }
tauri-plugin-shell = "2.0.0-beta"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

new:

tauri = { version = "2.0.0-beta", features = ["tray-icon", "image-png", "unstable"] }
tauri-plugin-shell = "2.0.0-beta"
tauri-plugin-dialog = "2.0.0-beta"
tauri-plugin-log = "2.0.0-beta"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Then use pnpm tauri dev to run the project again, you cannot use ctrl+c/v, After investigation, it was caused by unstable

Because the project is upgraded from alpha to beta version, and need to use Tray

if event.click_type == ClickType::Left {
             let app = tray.app_handle();
             if let Some(window) = app.get_window("main") {
                 let _ = window.show();
                 let _ = window.set_focus();
             }
         }

Among them, the app.get_window method reports an error. The editor prompts that the unstable package needs to be introduced. If i do not use the unstable package, how do i get the main window?

poohlaha avatar Mar 26 '24 09:03 poohlaha

I think it could be a Mac specific issue. The Copy/Paste events don't go to the webview unless the PredefinedMenuItem for Copy and Paste are added.

hobbestherat avatar Mar 26 '24 16:03 hobbestherat

~Same issue on M1 here just to add npm run tauri dev native clipboard works no plugins added npm run tauri build~

Actually npm run tauri add clipboard-manager was all that was needed I think it added "clipboard-manager:default" to capabilities/default.json for me despite the docs saying nothing is enabled but this is what I want!

here's tauri info
[✔] Environment
    - OS: Mac OS 14.3.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.80.1 (3f5fd8dd4 2024-08-06) (Homebrew)
    ✔ cargo: 1.80.1
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.6.0
    - pnpm: 9.7.1
    - yarn: 1.22.22
    - npm: 10.8.2

[-] Packages
    - tauri [RUST]: 2.0.0-rc.6
    - tauri-build [RUST]: 2.0.0-rc.6
    - wry [RUST]: 0.42.0
    - tao [RUST]: 0.29.1
    - tauri-cli [RUST]: 2.0.0-rc.7
    - @tauri-apps/api [NPM]: 2.0.0-rc.3
    - @tauri-apps/cli [NPM]: 2.0.0-rc.7

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite
    - 

jswhisperer avatar Aug 23 '24 23:08 jswhisperer

I'm late to the party here but running into the exact same thing. right-click -> copy/paste works, but ctrl/cmd + c/v doesn't work. I've added all the manager permissions and initialized the plugin in lib.rs. I don't intend on actually managing the clipboard (i.e. just normal input copy/paste behavior like any website or application). Did we ever figure out what the cause or solution was for this? Repo here for reference: https://github.com/nsallis/firehose

tauri info: [✔] Environment - OS: Mac OS 15.5.0 x86_64 (X64) ✔ Xcode Command Line Tools: installed ✔ rustc: 1.87.0 (17067e9ac 2025-05-09) ✔ cargo: 1.87.0 (99624be96 2025-05-06) ✔ rustup: 1.28.2 (e4f3ad6f8 2025-04-28) ✔ Rust toolchain: stable-x86_64-apple-darwin (default) - node: 22.13.0 - yarn: 1.22.22 - npm: 10.9.2

[-] Packages - tauri 🦀: 2.6.2, (outdated, latest: 2.7.0) - tauri-build 🦀: 2.3.0, (outdated, latest: 2.3.1) - wry 🦀: 0.52.1 - tao 🦀: 0.34.0 - @tauri-apps/api : 2.5.0 - @tauri-apps/cli : 2.5.0

[-] Plugins - tauri-plugin-opener 🦀: 2.3.0, (outdated, latest: 2.4.0) - @tauri-apps/plugin-opener : 2.3.0 - tauri-plugin-fs 🦀: 2.4.0, (outdated, latest: 2.4.1) - @tauri-apps/plugin-fs : not installed! - tauri-plugin-shell 🦀: 2.3.0 - @tauri-apps/plugin-shell : 2.3.0 - tauri-plugin-clipboard-manager 🦀: 2.3.0 - @tauri-apps/plugin-clipboard-manager : not installed! - tauri-plugin-dialog 🦀: 2.3.0, (outdated, latest: 2.3.1) - @tauri-apps/plugin-dialog : 2.3.0

[-] App - build-type: bundle - CSP: unset - frontendDist: ../dist - devUrl: http://localhost:1420/ - framework: React - bundler: Vite ✨ Done in 11.22s.

nsallis avatar Jul 21 '25 17:07 nsallis

@nsallis your repo is private. Please also ignore any mention of clipboard plugins, that makes no sense for the issue. Do you still have the Copy & Paste menu items in the app menu bar? That's what handles shortcuts on macos.

FabianLars avatar Jul 21 '25 19:07 FabianLars

@FabianLars whoops sorry I forgot I made the repo private when I created it. You should be able to see it now. I do not have menu items for copy/paste nor do I really want them. Do I need to add the JS plugin for the clipboard manager to get this functionality?

nsallis avatar Jul 21 '25 20:07 nsallis

I do not have menu items for copy/paste nor do I really want them

This is how the shortcuts work on macos though. This is how virtually all apps are doing it. 🤷

Do I need to add the JS plugin for the clipboard manager to get this functionality?

You may be able to get close to native behavior by listening to Cmd+XCV in js (via the js native key events, not our global shortcut plugin) and then use the clipboard manager to get/set the clipboard.

FabianLars avatar Jul 21 '25 20:07 FabianLars

That got me on the right path! Definitely a MacOS thing and my ignorance in how windows on Mac work. For anyone searching for the same issue with cmd + c and cmd + v not working on MacOS: Make sure you add the PredefinedMenuItems for copy and paste to one of your menus. Additionally because MacOS only shows sub-menus you need to put them on a sub-menu, not the "main" menu.

Example:

import { Menu, MenuItem, Submenu, PredefinedMenuItem } from '@tauri-apps/api/menu';
//...
const subMenu = await Submenu.new({
        text: 'MySubMenu',
        items: [
          await MenuItem.new({
            id: 'subItem',
            text: 'Sub Item',
            action: () => {
              pickExportLocation();
            },
          }),
          // Important part here:
          copy,
          paste,
          cut,
        ],
      });
  //...
  const menu = await Menu.new({
        items: [
          subMenu,
        ],
      });

      menu.setAsAppMenu();

Hopefully this helps someone in the future!

nsallis avatar Jul 22 '25 11:07 nsallis