https://github.com/freethinkel/tauri-nspopover-plugin
NSPopover plugin for tauri
https://github.com/freethinkel/tauri-nspopover-plugin
cargo macos menu menuapp nspopover popover rust statusbar tauri
Last synced: 3 months ago
JSON representation
NSPopover plugin for tauri
- Host: GitHub
- URL: https://github.com/freethinkel/tauri-nspopover-plugin
- Owner: freethinkel
- License: mit
- Created: 2024-01-23T09:49:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-27T09:07:15.000Z (4 months ago)
- Last Synced: 2025-05-27T09:30:36.553Z (4 months ago)
- Topics: cargo, macos, menu, menuapp, nspopover, popover, rust, statusbar, tauri
- Language: Rust
- Homepage:
- Size: 1.35 MB
- Stars: 33
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-tauri - tauri-nspopover-plugin - Native NSPopover view for use in the status bar in macOS. (Development / Plugins)
README
# Tauri Plugin NSpopover
Only for MacOS
![]()
## Install
```toml
# Cargo.toml
[dependencies]
tauri-plugin-nspopover = { git = "https://github.com/freethinkel/tauri-nspopover-plugin.git", version = "4.0.0" }
``````json
// package.json
"dependencies": {
"tauri-plugin-nspopover": "git+https://github.com/freethinkel/tauri-nspopover-plugin"
}
```## Usage
```rust
// main.rs
use tauri::{ActivationPolicy, Manager};
use tauri_plugin_nspopover::{AppExt, ToPopoverOptions, WindowExt};fn main() {
tauri::Builder::default()
.setup(|app| {
app.set_activation_policy(ActivationPolicy::Accessory);
let window = app.handle().get_webview_window("main").unwrap();window.to_popover(ToPopoverOptions {
is_fullsize_content: true,
});Ok(())
})
.plugin(tauri_plugin_nspopover::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
``````ts
// main.ts
import { TrayIcon } from "@tauri-apps/api/tray";
import { isOpen, show, hide } from "tauri-plugin-nspopover";TrayIcon.new({
id: "main",
async action(event) {
console.log(event);
if (
event.type === "Click" &&
event.buttonState === "Up" &&
event.button === "Left"
) {
const isShown = await isOpen();if (isShown) {
hide();
} else {
show();
}
}
},
});
```OR you can use rust api
```rust
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_nspopover::init())
.setup(|app| {
app.set_activation_policy(ActivationPolicy::Accessory);
let window = app.handle().get_webview_window("main").unwrap();
window.to_popover(ToPopoverOptions {
is_fullsize_content: true,
});let tray = app.tray_by_id("main").unwrap();
let handle = app.handle().clone();tray.on_tray_icon_event(move |_, event| match event {
TrayIconEvent::Click {
button,
button_state,
..
} => {
if button == MouseButton::Left && button_state == MouseButtonState::Up {
if !handle.is_popover_shown() {
handle.show_popover();
} else {
handle.hide_popover();
}
}
}
_ => {}
});Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
``````json
// tauri.config.json
"systemTray": {
"iconPath": "icons/statusbar-icon.png",
"iconAsTemplate": true,
"id": "main"
},
...
"windows": [
{
"fullscreen": false,
"visible": false,
"title": "example",
"width": 300,
"height": 450,
"transparent": true
}
]
```## Permissions
Don't forget to add the necessary permissions to your `src-tauri/capabilities/default.json` file.
```json
...
"nspopover:allow-show-popover",
"nspopover:allow-hide-popover",
"nspopover:allow-is-popover-shown",
"core:tray:allow-new",
"core:tray:default"
...
```## Example
```sh
git clone https://github.com/freethinkel/tauri-plugin-nspopover
cd tauri-plugin-nspopover/example
pnpm install
pnpm tauri dev
```