From 1cf71f51b5a3fa16ee27d6d7220e66b73ceecd25 Mon Sep 17 00:00:00 2001 From: Psychotoxical Date: Mon, 9 Mar 2026 19:35:25 +0100 Subject: [PATCH] fix(tauri): exit app on close and grant ipc permissions & update changelog --- CHANGELOG.md | 5 +++++ src-tauri/capabilities/default.json | 6 +++++- src-tauri/src/lib.rs | 9 +++++++-- src/App.tsx | 4 ++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66567a33..d7f4c584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.1] - Beta Hotfix + +### Fixed +- **App Termination Bug**: Fixed an issue where the application would hang in the background when the close button was clicked due to default Tauri tray icon handling. The `exit_app` event is now correctly triggered. + ## [0.1.0] - Initial Release ### Added diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index be1f52a1..079d30da 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -23,6 +23,10 @@ "fs:allow-mkdir", "fs:scope-download-recursive", "fs:scope-home-recursive", - "core:window:allow-set-title" + "core:window:allow-set-title", + "core:window:allow-close", + "core:window:allow-hide", + "core:window:allow-show", + "core:app:allow-exit" ] } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1cbf34a5..4034513f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -12,6 +12,11 @@ fn greet(name: &str) -> String { format!("Hello, {}!", name) } +#[tauri::command] +fn exit_app(app_handle: tauri::AppHandle) { + app_handle.exit(0); +} + pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_shell::init()) @@ -54,7 +59,7 @@ pub fn run() { } } "quit" => { - app.exit(0); + std::process::exit(0); } _ => {} }) @@ -102,7 +107,7 @@ pub fn run() { let _ = window.emit("window:close-requested", ()); } }) - .invoke_handler(tauri::generate_handler![greet]) + .invoke_handler(tauri::generate_handler![greet, exit_app]) .run(tauri::generate_context!()) .expect("error while running Psysonic"); } diff --git a/src/App.tsx b/src/App.tsx index 3bd47ed1..d67e1db1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState, useCallback } from 'react'; import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; import { listen } from '@tauri-apps/api/event'; +import { invoke } from '@tauri-apps/api/core'; import { getCurrentWindow } from '@tauri-apps/api/window'; import Sidebar from './components/Sidebar'; import PlayerBar from './components/PlayerBar'; @@ -207,6 +208,9 @@ function TauriEventBridge() { if (minimizeToTray) { event.preventDefault(); await win.hide(); + } else { + // If not minimizing to tray, we want to exit the app completely + await invoke('exit_app'); } }).then(u => unlisten.push(u));