#Global Shortcut Plugin: v1 to v2 migration

2 messages · Page 1 of 1 (latest)

spark kayak
#

I'm trying to migrate my app to V2 and Global Shortcut plugin makes it way too hard.

Here is my current code after migration:

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{Manager};
use tauri_plugin_global_shortcut::GlobalShortcutExt;

#[allow(unused_must_use)]
fn main() {
  tauri::Builder::default()
  .plugin(tauri_plugin_global_shortcut::Builder::new().build())
  .setup(|app| {
    let window = app.get_window("main").unwrap();

    app.global_shortcut().register("CommandOrControl+F11", move || {
        let is_fullscreen = !window.is_fullscreen().unwrap_or(false);
        window.set_fullscreen(is_fullscreen);
    });

    Ok(())
    })
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

Example from documentation does not work at all.
https://beta.tauri.app/guides/upgrade-migrate/from-tauri-1/#migrate-to-global-shortcut-plugin

This part from docs throws error:

.plugin(tauri_plugin_shortcut::init())

Moreover, tauri_plugin_shortcut doesn't even exist since it's called tauri_plugin_global_shortcut. And even then, ::init() doesn't work.

|   .plugin(tauri_plugin_global_shortcut::init())
|                                         ^^^^ not found in `tauri_plugin_global_shortcut`

After searching on Discord I found a way that doesn't throw error (see my code above) but I still can't make it work because it says it accepts only one argument. But then, how I'm supposed to attach a function to the shortcut?

analog onyx
#

There's now a only a single handler per GlobalShortcut object, something like this ```rs
.plugin(tauri_plugin_global_shortcut::Builder::new().with_handler(move |handle, shortcut| {...}).build())