MCPcopy Index your code
hub / github.com/ahkohd/tauri-nspanel

github.com/ahkohd/tauri-nspanel @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
121 symbols 230 edges 22 files 64 documented · 53%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Convert a Tauri window (NSWindow) to panel (NSPanel)

Install

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

[dependencies]
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v1" }

[features]
cargo-clippy = []

Usage

  1. First you need to register the core plugin with Tauri:

src-tauri/src/main.rs

fn main() {
    tauri::Builder::default()
        .plugin(tauri_nspanel::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
  1. To swizzle a window's NSWindow to NSPanel, use the to_panel() method:
use tauri_nspanel::WindowExt;

// ...
let panel = window.to_panel().unwrap();

The window will be swizzled to NSPanel.

Only call the to_panel() method once on a window.

  1. To access your panels, use the app_handle.get_panel("label"):
use tauri_nspanel::ManagerExt;

// ...

let my_panel = app_handle.get_panel("main");
  1. To respond to panel events, such as resizing, moving, exposing, and minimizing (See the exhaustive list), you need to setup a NSWindowDelegate for your panel.

Use the panel_delegate!() macro to do this:

use tauri::Wry;
use tauri_nspanel::{objc_id::Id, panel_delegate, ManagerExt, Panel, WindowExt};

// ...
// Use the `panel_delegate!()` macro to create your custom delegate

// Specify your handlers
// See, https://developer.apple.com/documentation/appkit/nswindowdelegate?language=objc
// for an exhaustive list of handlers.
//
// Example: to respond to windowDidBecomeKey:
// specify in snake case: window_did_become_key

let delegate = panel_delegate!(MyPanelDelegate {
  window_did_become_key,
  window_did_resign_key
});

// Listen to when a delegate is called
delegate.set_listener(Box::new(|delegate_name: String| {
    println!("{} was called!", delegate_name);
}));

// Set your panel's delegate
panel.set_delegate(delegate);
  1. Simply calling the .close() method on your NSPanel instance may not be sufficient to fully release its resources. This is because, by default, NSPanels are not released when they are closed. This is because NSPanels are often lightweight and designed for reuse.

To ensure that your NSPanel is fully released:

// ...

panel.set_released_when_closed(true);
panel.close();
  1. See the examples to learn how to use tauri-nspanel. For more information on panel methods, please refer to the documentation page.

Related

The following are projects related to this plugin:

Showcase

Here are some projects using tauri-nspanel

Contributing

PRs accepted. Please make sure to read the Contributing Guide before making a pull request.

License

MIT or MIT/Apache 2.0 where applicable.

Extension points exported contracts — how you extend this code

EventHandler (Interface)
Trait for event handlers that can be used with panels
src/lib.rs
Panel (Interface)
Common trait for all panel types
src/lib.rs
FromWindow (Interface)
Trait for panels that can be created from a window
src/lib.rs
ManagerExt (Interface)
(no doc) [1 implementers]
src/lib.rs
WebviewWindowExt (Interface)
(no doc) [1 implementers]
src/lib.rs

Core symbols most depended-on inside this repo

build
called by 18
src/builder.rs
get_webview_panel
called by 17
src/lib.rs
title
called by 16
src/builder.rs
url
called by 11
src/builder.rs
position
called by 11
src/builder.rs
size
called by 10
src/builder.rs
can_join_all_spaces
called by 8
src/builder.rs
level
called by 8
src/builder.rs

Shape

Method 65
Function 42
Class 7
Interface 5
Enum 2

Languages

Rust100%

Modules by API surface

src/builder.rs67 symbols
src/lib.rs13 symbols
examples/panel_builder/src-tauri/src/main.rs5 symbols
examples/mouse_tracking/src-tauri/src/main.rs5 symbols
examples/hover_activate/src-tauri/src/main.rs5 symbols
examples/fullscreen/src-tauri/src/main.rs5 symbols
examples/basic/src-tauri/src/main.rs5 symbols
examples/panel_levels.rs2 symbols
examples/panel_builder.rs2 symbols
examples/collection_behavior.rs2 symbols
examples/builder_with_custom_panel.rs2 symbols
examples/panel_style_mask.rs1 symbols

For agents

$ claude mcp add tauri-nspanel \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact