Im trying out tauri (v2) for the first time (love it), but the documentation is lacking. Im creating a frontend in svelte, and I dont want the window to close, but rather run in the background as a system tray application, and upon double clicking, it should reopen the webview window. Following the documentation, this is my tray.ts file
import { defaultWindowIcon } from "@tauri-apps/api/app";import { TrayIcon, type TrayIconOptions } from "@tauri-apps/api/tray";import { Menu } from "@tauri-apps/api/menu";import { getCurrentWindow,Window } from "@tauri-apps/api/window";import { Webview } from "@tauri-apps/api/webview";function onTrayMenuClick(itemId: string) {}const menu = await Menu.new({ items: [ { id: "quit", text: "Quit", action: onTrayMenuClick, }, ],});const options: TrayIconOptions = { icon: (await defaultWindowIcon()) ?? "default-icon.png", menu, action: (event) => { switch (event.type) { case "DoubleClick": console.log(`mouse ${event.button} button pressed`); break; } }, showMenuOnLeftClick: true, tooltip: "Tauri App",};export const tray = await TrayIcon.new(options);
The svelte code is normal svelte code, not interfering with any native features except maybe the ability to send notifications.
<script lang="ts"> import { onMount, onDestroy } from 'svelte'; import { sendNotification } from '@tauri-apps/plugin-notification'; import { fetch } from '@tauri-apps/plugin-http'; async function requestNotificationPermission() { try { await Notification.requestPermission(); } catch (error) { console.error('Error requesting notification permission:', error); } }// and so on
The problem im encountering is that i dont know how to implement the non-closure of the window when X is clicked, and how to make the tray app's quit functionality make the app stop instead (hence the code is blank)