Convert a Tauri window (NSWindow) to panel (NSPanel)
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 = []
src-tauri/src/main.rs
fn main() {
tauri::Builder::default()
.plugin(tauri_nspanel::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
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.
app_handle.get_panel("label"):use tauri_nspanel::ManagerExt;
// ...
let my_panel = app_handle.get_panel("main");
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);
.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();
tauri-nspanel. For more information on panel methods, please refer to the documentation page.The following are projects related to this plugin:
Here are some projects using tauri-nspanel
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
MIT or MIT/Apache 2.0 where applicable.
$ claude mcp add tauri-nspanel \
-- python -m otcore.mcp_server <graph>