🥃 A plugin for swizzling Tauri’s NSWindow to NSPanel

Overview

Swizzle Tauri's NSWindow to NSPanel

Install

There are three general methods of installation that we can recommend.

  • Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
  • Pull sources directly from Github using git tags / revision hashes (most secure)
  • Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)

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

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

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};

// ...

// Define your handlers
// See, https://developer.apple.com/documentation/appkit/nswindowdelegate?language=objc
// for an exhaustive list of handlers.
//
// Example: to respond to windowWillBeginSheet:
// declare the function in snake case:
// fn window_will_begin_sheet(_: Panel<Wry>) { }

fn window_did_become_key(panel: Panel<Wry>) {
  let app_name = panel.app_handle().unwrap().package_info().name.to_owned();
  println!("[info]: {:?} panel becomes key window!", app_name);
}

fn window_did_resign_key(_: Panel<Wry>) {
  println!("[info]: panel resigned from key window!");
}

// Use the `panel_delegate!()` macro to create your custom delegate
let delegate = panel_delegate!(MyPanelDelegate<Wry> {
  window_did_become_key,
  window_did_resign_key
});

// Give the delegate a reference to your panel
delegate.set_panel(panel.to_owned());

// 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.released_when_closed(true);
panel.close();
  1. For more information on panel methods, please refer to the documentation page.

Related

The following are projects related to this plugin:

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.

You might also like...
Bindings to the Tauri API for projects using wasm-bindgen

tauri-sys Raw bindings to the Tauri API for projects using wasm-bindgen Installation This crate is not yet published to crates.io, so you need to use

Tauri and Leptos example.

tauri-leptos-example Tauri Leptos Requires Rust Nightly. See Leptos nightly Note. # Install Tauri CLI cargo install tauri-cli # Build and develop for

 A cross-platform tauri gui where Oblique Strategies meets Pomodoro
A cross-platform tauri gui where Oblique Strategies meets Pomodoro

Obliqoro Oblique Strategies meets Pomodoro Built in Rust, Vue3, and Typescript, using Tauri, and SQLite Screenshots About Obliqoro is an open source,

OpenAI ChatGPT desktop app for Mac, Windows, & Linux menubar using Tauri & Rust
OpenAI ChatGPT desktop app for Mac, Windows, & Linux menubar using Tauri & Rust

ChatGPT Desktop App Unofficial open source OpenAI ChatGPT desktop app for mac, windows, and linux menubar using tauri & rust. Downloads Windows (2.7 M

Web-wrapped Supabase desktop app for macOS, Windows & Linux powered by Tauri
Web-wrapped Supabase desktop app for macOS, Windows & Linux powered by Tauri

Supabase Desktop App What is it? It's a cross-platform web-wrapped Supabase desktop app powered by Tauri. You can install it on your macOS, Windows (u

SimpleX Chat GUI built with Rust, Tauri and Yew
SimpleX Chat GUI built with Rust, Tauri and Yew

simplex-desktop A desktop application for simplex-chat. WIP, contributions are welcome. Architecture For the back end we rust with tauri and frontend

A lightweight new Bing (AI chat) desktop application which based on Tauri.

Bing Lite A lightweight new Bing (AI chat) desktop application which based on Tauri. No more Microsoft Edge, no more Chromium/Electron! Download The l

A Tauri-based spreadsheet
A Tauri-based spreadsheet

Pulsars A Tauri-based spreadsheet The following cool libraries made it possible to build Pulsars 🚀 : fortune-sheet: TypeScript library for the spread

TaurApp is a WhatsApp desktop client powered by Tauri and Rust.
TaurApp is a WhatsApp desktop client powered by Tauri and Rust.

TaurApp TaurApp is a WhatsApp desktop client powered by Tauri and Rust. TaurApp is an experimental client and is initially created to test out Tauri i

Comments
  • chore(deps): update actions/checkout action to v3

    chore(deps): update actions/checkout action to v3

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | actions/checkout | action | major | v2 -> v3 |


    Release Notes

    actions/checkout

    v3

    Compare Source


    Configuration

    📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

    🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

    Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    🔕 Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, check this box

    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • Cargo.toml (cargo)
    • .github/workflows/audit.yml (github-actions)
    • .github/workflows/covector-status.yml (github-actions)
    • .github/workflows/covector-version-or-publish.yml (github-actions)
    • .github/workflows/format.yml (github-actions)
    • .github/workflows/lint.yml (github-actions)
    • .github/workflows/test.yml (github-actions)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation.
    • If Renovate detects semantic commits, it will use semantic commit type fix for dependencies and chore for all others.
    • Ignore node_modules, bower_components, vendor and various test/tests directories.
    • Group known monorepo packages together.
    • Use curated list of recommended non-monorepo package groupings.
    • apollo-server packages became scoped.
    • babel-eslint was renamed under the @babel scope.
    • Replace containerbase dependencies.
    • cucumber became scoped.
    • fastify packages became scoped.
    • hapi became scoped.
    • Jade was renamed to Pug.
    • joi became scoped under the hapi organization.
    • joi was moved out of the hapi organization.
    • The Kubernetes container registry has changed from k8s.gcr.io to registry.k8s.io.
    • The Kubernetes container registry has changed from k8s.gcr.io to registry.k8s.io.
    • The material-ui monorepo org was renamed from @material-ui to @mui.
    • The messageformat monorepo package naming scheme changed from messageFormat-{{package}}-to-@messageformat/{{package}}.
    • middie became scoped.
    • now was renamed to vercel.
    • @parcel/css was renamed to lightningcss.
    • react-query/devtools became scoped under the tanstack organization.
    • react-query became scoped under the tanstack organization.
    • react-scripts supports TypeScript since version 2.1.0.
    • The @renovate/pep440 package was renamed to @renovatebot/pep440.
    • The node-resolve plugin for rollup became scoped.
    • The vso-task-lib package is now published as azure-pipelines-task-lib.
    • The vsts-task-lib package is now published as azure-pipelines-task-lib.
    • The xmldom package is now published as @xmldom/xmldom.
    • A collection of workarounds for known problems with packages.

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 1 Pull Request:

    chore(deps): update actions/checkout action to v3
    • Schedule: ["at any time"]
    • Branch name: renovate/actions-checkout-3.x
    • Merge into: main
    • Upgrade actions/checkout to v3

    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • RUSTSEC-2023-0019: `kuchiki` is unmaintained

    RUSTSEC-2023-0019: `kuchiki` is unmaintained

    opened by github-actions[bot] 0
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    This repository currently has no open or pending branches.

    Detected dependencies

    cargo
    Cargo.toml
    • tauri 1.2.4
    • core-graphics 0.22.3
    • core-foundation 0.9.3
    • cocoa 0.24.1
    • objc 0.2.7
    • objc_id 0.1.1
    • objc-foundation 0.1.1
    github-actions
    .github/workflows/audit.yml
    • actions/checkout v3
    • actions-rs/audit-check v1
    .github/workflows/covector-status.yml
    • actions/checkout v3
    .github/workflows/covector-version-or-publish.yml
    • actions/checkout v3
    • tauri-apps/create-pull-request v3
    .github/workflows/docs.yml
    • actions/checkout v3
    • actions-rs/toolchain v1
    • JamesIves/github-pages-deploy-action v4
    .github/workflows/format.yml
    • actions/checkout v3
    • actions-rs/toolchain v1
    • actions-rs/cargo v1
    .github/workflows/lint.yml
    • actions/checkout v3
    • actions-rs/toolchain v1
    • actions-rs/clippy-check v1
    .github/workflows/test.yml
    • actions/checkout v3
    • actions-rs/toolchain v1
    • Swatinem/rust-cache v2
    • actions-rs/cargo v1

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
Owner
Victor Aremu
Software Engineer
Victor Aremu
Cross-platform Window library in Rust for Tauri. [WIP]

Cross-platform application window creation library in Rust that supports all major platforms like Windows, macOS, Linux, iOS and Android. Built for you, maintained for Tauri.

Tauri 899 Jan 1, 2023
Hydrogen is the desktop application for Geplauder, built with tauri studio.

Hydrogen Hydrogen is the desktop application for Geplauder, built with tauri studio. For more information on Geplauder, click here. Usage To configure

null 4 Nov 21, 2021
Helps positioning your tauri windows.

Tauri plugin positioner A plugin for tauri that helps positioning you windows at well known locations. Install Rust [dependencies] tauri-plugin-positi

Jonas Kruckenberg 42 Jan 5, 2023
A custom invoke system for Tauri that leverages a localhost server

Tauri Invoke HTTP This is a crate that provides a custom invoke system for Tauri using a localhost server. Each message is delivered through a XMLHttp

Tauri 17 Dec 17, 2022
This is a small demo to accompany the Tauri + Yew tutorial

Tauri + Yew Demo This is a small demo to accompany the Tauri + Yew tutorial

Steve Pryde 94 Jan 2, 2023
📦 Port of tauri-bundler

?? Port of tauri-bundler You can now easily create installers for your Deno apps, thanks to the amazing work of Tauri ??

Marc Espín 28 Dec 7, 2022
Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps.

rust-yew-axum-tauri-desktop template Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps. Crates frontend: Yew frontend app for de

Jet Li 54 Dec 23, 2022
Type-safe IPC for Tauri using GraphQL

Tauri Plugin graphql A plugin for Tauri that enables type-safe IPC through GraphQL. Install Rust [dependencies] tauri-plugin-graphql = "0.2" JavaScrip

Jonas Kruckenberg 40 Dec 29, 2022
🦀 Small Tauri SolidJS Example feat. Vite

Tauri Solid Example (2022) Simple Solid(vite) starter running with Tauri. Should hopefully save some time trying to setup Tauri and Solid. Currently c

Luke Secomb 14 Oct 25, 2022
A Raycast/Spotlight like app shell using tauri

Tauri Shell This repo can be used as reference for building alfred/raycast/spotlight apps using Tauri. Usage This reference repository is using Svelte

Shivaprasad Bhat 6 Oct 27, 2022