tauri-plugin-prevent-default

Crates.iotauri-plugin-prevent-default
lib.rstauri-plugin-prevent-default
version0.1.9
sourcesrc
created_at2024-07-01 03:44:36.450244
updated_at2024-07-12 14:24:08.763623
descriptionDisable default webview shortcuts
homepagehttps://github.com/ferreira-tb/tauri-plugin-prevent-default
repositoryhttps://github.com/ferreira-tb/tauri-plugin-prevent-default
max_upload_size
id1288351
size10,914
Andrew Ferreira (ferreira-tb)

documentation

https://docs.rs/tauri-plugin-prevent-default

README

tauri-plugin-prevent-default

Disable default browser shortcuts in your Tauri app, e.g. F3 or Ctrl+J.

Install

Install the plugin by adding the following to your Cargo.toml file:

[dependencies]
tauri-plugin-prevent-default = 0.1

Usage

Register the plugin with Tauri:

src-tauri/src/main.rs

fn main() {
  tauri::Builder::default()
    .plugin(tauri_plugin_prevent_default::Builder::new().build())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

You can also use flags to determine which shortcuts the plugin should disable. By default, it will disable all of them.

use tauri_plugin_prevent_default::Flags;

fn main() {
  let prevent = tauri_plugin_prevent_default::Builder::new()
    .with_flags(Flags::CONTEXT_MENU | Flags::PRINT | Flags::DOWNLOADS)
    .build();

  tauri::Builder::default()
    .plugin(prevent)
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

To disable all but a few:

use tauri_plugin_prevent_default::Flags;

// This will disable all shortcuts, except `FIND` and `RELOAD`.
tauri_plugin_prevent_default::Builder::new()
  .with_flags(Flags::all().difference(Flags::FIND | Flags::RELOAD))
  .build()

To keep certain shortcuts enabled only when in dev mode:

fn main() {
  tauri::Builder::default()
    .plugin(prevent_default())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

#[cfg(debug_assertions)]
pub fn prevent_default() -> tauri::plugin::TauriPlugin<tauri::Wry> {
  use tauri_plugin_prevent_default::Flags;

  tauri_plugin_prevent_default::Builder::new()
    .with_flags(Flags::all().difference(Flags::DEV_TOOLS | Flags::RELOAD))
    .build()
}

#[cfg(not(debug_assertions))]
pub fn prevent_default() -> tauri::plugin::TauriPlugin<tauri::Wry> {
  tauri_plugin_prevent_default::Builder::new().build()
}

Note

The plugin should work fine on Windows, but there are still tests to be done on MacOS and Linux. If you encounter any problems on these platforms, please open an issue.

Contributing

If there is any other shortcuts that I can include in the plugin, please let me know!

Commit count: 23

cargo fmt