Repository: tauri
Issue: [bug] App::cleanup_before_exit() can crash if not run on main thread
Labels: type: bug,priority: 1 high,platform: macOS,status: needs triage

### Describe the bug

If an app has some resources that need to be cleaned up and the OS requires them to be cleaned up on main thread then calling `cleanup_before_exit()` from a worker thread may cause a crash.

I observed this crash reliably with a tray icon app on MacOS, see crash backtrace below.

### Reproduction

I don't have a minimal repro but you can look at my [fix](https://github.com/openscopeproject/TrguiNG/commit/79beca8ee08eb4b9b0f9eda060d3373f0f9fbf5b) for this issue for my app and if you compile the parent commit the issue will reproduce.

### Expected behavior

Any cleanup that should happen on main thread should be handled on main thread inside the `cleanup_before_exit()` method

### Full `tauri info` output

```text
[✔] Environment
    - OS: Mac OS 12.6.5 x86_64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-apple-darwin (default)
    - node: 18.16.1
    - yarn: 1.22.19
    - npm: 9.5.1

[-] Packages
    - tauri 🦀: 2.2.5
    - tauri-build 🦀: 2.0.5
    - wry 🦀: 0.48.1
    - tao 🦀: 0.31.1
    - @tauri-apps/api : 2.2.0
    - @tauri-apps/cli : 2.2.7

[-] Plugins
    - tauri-plugin-cli 🦀: 2.2.0
    - @tauri-apps/plugin-cli : 2.2.0
    - tauri-plugin-fs 🦀: 2.2.0
    - @tauri-apps/plugin-fs : 2.2.0
    - tauri-plugin-notification 🦀: 2.2.1
    - @tauri-apps/plugin-notification : 2.2.1
    - tauri-plugin-dialog 🦀: 2.2.0
    - @tauri-apps/plugin-dialog : 2.2.0
    - tauri-plugin-clipboard-manager 🦀: 2.2.0
    - @tauri-apps/plugin-clipboard-manager : 2.2.0
    - tauri-plugin-shell 🦀: 2.2.0
    - @tauri-apps/plugin-shell : 2.2.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:8080/
    - framework: React
    - bundler: Webpack
```

### Stack trace

```text
Stack:(
	0   CoreAutoLayout                      0x00007ff810af0939 _AssertAutoLayoutOnAllowedThreadsOnly + 202
	1   CoreAutoLayout                      0x00007ff810af0cb8 -[NSISEngine withBehaviors:performModifications:] + 25
	2   AppKit                              0x00007ff80b94b7eb -[NSView(NSConstraintBasedLayout) _withAutomaticEngineOptimizationDisabled:] + 59
	3   AppKit                              0x00007ff80b9547a0 -[NSView _setSuperview:] + 427
	4   AppKit                              0x00007ff80b97a6fd -[NSView removeFromSuperview] + 140
	5   trguing                             0x000000010c3a8790 _ZN59_$LT$$LP$$RP$$u20$as$u20$objc2..encode..EncodeArguments$GT$8__invoke17hb7a6c4bf884c5499E + 48
	6   trguing                             0x000000010c3a4930 _ZN5objc27runtime16message_receiver18msg_send_primitive4send17hdc096b39f28b4a85E + 48
	7   trguing                             0x000000010c3ac19a _ZN5objc27runtime16message_receiver15MessageReceiver12send_message28_$u7b$$u7b$closure$u7d$$u7d$17hf963d757138bbd8dE + 42
	8   trguing                             0x000000010c3a2165 _ZN115_$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$9call_once17hf510c43f9825693eE + 21
	9   trguing                             0x000000010c388abc _ZN5objc29exception5catch28_$u7b$$u7b$closure$u7d$$u7d$17h6001a24d09e7b206E + 28
	10  trguing                             0x000000010c3851d1 _ZN5objc29exception10try_no_ret24try_objc_execute_closure17hf89e6beb1fa1b5eaE + 97
	11  trguing                             0x000000010c3d043e rust_objc_sys_0_3_try_catch_exception + 30
	12  trguing                             0x000000010c37f9aa _ZN5objc29exception10try_no_ret17h3755cd8e77b9aeb3E + 202
	13  trguing                             0x000000010c3874fc _ZN5objc29exception5catch17hd88fd32da641a5e9E + 60
	14  trguing                             0x000000010c3921e6 _ZN5objc27runtime16message_receiver15MessageReceiver12send_message17h891939fda8d344f0E + 198
	15  trguing                             0x000000010c36e98a _ZN5objc215__macro_helpers8msg_send7MsgSend12send_message17haf987ba6b13894b2E + 154
	16  trguing                             0x000000010c36f51b _ZN13objc2_app_kit9generated8__NSView6NSView19removeFromSuperview17h176a96d531be7d45E + 59
	17  trguing                             0x000000010c2018b9 _ZN9tray_icon13platform_impl8platform8TrayIcon6remove17h8de954157eb3f2cbE + 265
	18  trguing                             0x000000010c2029b1 _ZN86_$LT$tray_icon..platform_impl..platform..TrayIcon$u20$as$u20$core..ops..drop..Drop$GT$4drop17h2ed453f407fca991E + 17
	19  trguing                             0x000000010c20ce35 _ZN4core3ptr65drop_in_place$LT$tray_icon..platform_impl..platform..TrayIcon$GT$17h3964376b9c17c46eE + 21
	20  trguing                             0x000000010c20d401 _ZN4core3ptr95drop_in_place$LT$core..cell..UnsafeCell$LT$tray_icon..platform_impl..platform..TrayIcon$GT$$GT$17h0097c275dbf2f21aE + 17
	21  trguing                             0x000000010c20d305 _ZN4core3ptr92drop_in_place$LT$core..cell..RefCell$LT$tray_icon..platform_impl..platform..TrayIcon$GT$$GT$17h7deeef8a3e7ccc49E + 21
	22  trguing                             0x000000010c050453 _ZN68_$LT$alloc..rc..Rc$LT$T$C$A$GT$$u20$as$u20$core..ops..drop..Drop$GT$4drop17h4743926d18d28cb2E + 211
	23  trguing                             0x000000010c036fd1 _ZN4core3ptr113drop_in_place$LT$alloc..rc..Rc$LT$core..cell..RefCell$LT$tray_icon..platform_impl..platform..TrayIcon$GT$$GT$$GT$17h6c4380a792eb9331E + 17
	24  trguing                             0x000000010c03e651 _ZN4core3ptr40drop_in_place$LT$tray_icon..TrayIcon$GT$17heec8ccdf7c3f286bE + 65
	25  trguing                             0x000000010c03e8ce _ZN4core3ptr42drop_in_place$LT$tauri..tray..TrayIcon$GT$17hd3f1732453dbbf5dE + 78
	26  trguing                             0x000000010c03f779 _ZN4core3ptr52drop_in_place$LT$$u5b$tauri..tray..TrayIcon$u5d$$GT$17h8e99aae541cdc0a1E + 73
	27  trguing                             0x000000010b0e0c68 _ZN5alloc3vec16Vec$LT$T$C$A$GT$5clear17h0fa9eea50f73cab6E + 104
	28  trguing                             0x000000010a9fd1e2 _ZN5tauri3app18AppHandle$LT$R$GT$19cleanup_before_exit17h50af6d8232cabda3E + 274
	29  trguing                             0x000000010aaa8a93 _ZN7trguing5setup28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17he70420d5c4f79ff7E + 83
	30  trguing                             0x000000010c05c9ac _ZN86_$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..Fn$LT$Args$GT$$GT$4call17h76d182de2ec98565E + 60
	31  trguing                             0x000000010c03244b _ZN5tauri5event8listener9Listeners11emit_filter17hd4abbe1e1fc223f7E + 875
	32  trguing                             0x000000010c032668 _ZN5tauri5event8listener9Listeners4emit17h893afe9e4fb3b155E + 40
	33  trguing                             0x000000010b812f3b _ZN5tauri7manager19AppManager$LT$R$GT$4emit17h279bc9e7619f313cE + 923
	34  trguing                             0x000000010aa00936 _ZN5tauri7Emitter4emit17hf913b73e54776162E + 374
	35  trguing                             0x000000010b707711 _ZN5tauri5event6plugin4emit28_$u7b$$u7b$closure$u7d$$u7d$17hee67980034de4fa3E + 385
	36  trguing                             0x000000010b7073fc _ZN53_$LT$F$u20$as$u20$futures_core..future..TryFuture$GT$8try_poll17hb989c87d179643cbE + 28
	37  trguing                             0x000000010b35c3ac _ZN117_$LT$futures_util..future..try_future..into_future..IntoFuture$LT$Fut$GT$$u20$as$u20$core..future..future..Future$GT$4poll17h270432a3f7d0ef32E + 60
	38  trguing                             0x000000010b798a6a _ZN102_$LT$futures_util..future..future..map..Map$LT$Fut$C$F$GT$$u20$as$u20$core..future..future..Future$GT$4poll17hf95a0dafefd0da89E + 154
	39  trguing                             0x000000010b6950fc _ZN97_$LT$futures_util..future..future..Map$LT$Fut$C$F$GT$$u20$as$u20$core..future..future..Future$GT$4poll17hbc52fd8862f22ddbE + 60
	40  trguing                             0x000000010abee11c _ZN104_$LT$futures_util..future..try_future..MapErr$LT$Fut$C$F$GT$$u20$as$u20$core..future..future..Future$GT$4poll17h68c6988be6b94473E + 60
	41  trguing                             0x000000010abf1d9c _ZN105_$LT$futures_util..future..try_future..ErrInto$LT$Fut$C$E$GT$$u20$as$u20$core..future..future..Future$GT$4poll17hd7e73990ba7abdbcE + 60
	42  trguing                             0x000000010b77434a _ZN102_$LT$futures_util..future..future..map..Map$LT$Fut$C$F$GT$$u20$as$u20$core..future..future..Future$GT$4poll17h370b86799ba3dbf3E + 154
	43  trguing                             0x000000010b6966dc _ZN97_$LT$futures_util..future..future..Map$LT$Fut$C$F$GT$$u20$as$u20$core..future..future..Future$GT$4poll17hfb0b631433a2b2e7E + 60
	44  trguing                             0x000000010b7094fa _ZN5tauri5event6plugin4init28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17h95e530e6d2e47d85E + 2250
	45  trguing                             0x000000010b0a1e88 _ZN5tauri3ipc23InvokeResolver$LT$R$GT$24respond_async_serialized28_$u7b$$u7b$closure$u7d$$u7d$17h748908d6d392be44E + 440
	46  trguing                             0x000000010b22bebd _ZN72_$LT$core..pin..Pin$LT$P$GT$$u20$as$u20$core..future..future..Future$GT$4poll17h8b9c41a90f5d48ccE + 45
	47  trguing                             0x000000010b488d95 _ZN5tokio7runtime4task4core17Core$LT$T$C$S$GT$4poll28_$u7b$$u7b$closure$u7d$$u7d$17h479b44755168375eE + 101
	48  trguing                             0x000000010b4620f8 _ZN5tokio7runtime4task4core17Core$LT$T$C$S$GT$4poll17h12d1f0ffdb97e551E + 56
	49  trguing                             0x000000010acf1927 _ZN5tokio7runtime4task7harness11poll_future28_$u7b$$u7b$closure$u7d$$u7d$17h8e87e26b3af877adE + 71
	50  trguing                             0x000000010aa6ce72 _ZN115_$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$9call_once17h25631f19413a1046E + 34
	51  trguing                             0x000000010b85a446 _ZN3std9panicking3try7do_call17h977e37b7e86a4b95E + 54
	52  trguing                             0x000000010b2fbe7d __rust_try + 29
	53  trguing                             0x000000010b2a5662 _ZN3std5panic12catch_unwind17h54d4d0d6388cad96E + 82
	54  trguing                             0x000000010aca6f63 _ZN5tokio7runtime4task7harness11poll_future17h6ff009252dd4782bE + 115
	55  trguing                             0x000000010ad30a36 _ZN5tokio7runtime4task7harness20Harness$LT$T$C$S$GT$10poll_inner17hdb57e410d500cde9E + 134
	56  trguing                             0x000000010adae255 _ZN5tokio7runtime4task7harness20Harness$LT$T$C$S$GT$4poll17he993eac640135ce2E + 21
	57  trguing                             0x000000010b5bf29d _ZN5tokio7runtime4task3raw4poll17h9b1724ff8c73c760E + 29
	58  trguing                             0x000000010c31f6f6 _ZN5tokio7runtime4task3raw7RawTask4poll17hc4cbd9c33b85ce7fE + 38
	59  trguing                             0x000000010c316dd2 _ZN5tokio7runtime4task22LocalNotified$LT$S$GT$3run17h527060227f42cb1aE + 34
	60  trguing                             0x000000010c30d1e9 _ZN5tokio7runtime9scheduler12multi_thread6worker7Context8run_task28_$u7b$$u7b$closure$u7d$$u7d$17h68e0216e3454e97aE + 57
	61  trguing                             0x000000010c30d0ab _ZN5tokio7runtime9scheduler12multi_thread6worker7Context8run_task17he2e4fc4cefeefc18E + 827
	62  trguing                             0x000000010c30c949 _ZN5tokio7runtime9scheduler12multi_thread6worker7Context3run17h51b91dfaaf93a40fE + 585
	63  trguing                             0x000000010c30c660 _ZN5tokio7runtime9scheduler12multi_thread6worker3run28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17h66c6aaeb1f03b2bcE + 96
	64  trguing                             0x000000010c32a175 _ZN5tokio7runtime7context6scoped15Scoped$LT$T$GT$3set17hf02214323105a8bdE + 133
	65  trguing                             0x000000010c2f62bb _ZN5tokio7runtime7context13set_scheduler28_$u7b$$u7b$closure$u7d$$u7d$17h6c0fab7fa03d6bb4E + 43
	66  trguing                             0x000000010c339776 _ZN3std6thread5local17LocalKey$LT$T$GT$8try_with17he680abde8c5f2b17E + 214
	67  trguing                             0x000000010c338101 _ZN3std6thread5local17LocalKey$LT$T$GT$4with17h92815f48b3b9200cE + 17
	68  trguing                             0x000000010c2f6230 _ZN5tokio7runtime7context13set_scheduler17h91834690cea337f9E + 48
	69  trguing                             0x000000010c30c593 _ZN5tokio7runtime9scheduler12multi_thread6worker3run28_$u7b$$u7b$closure$u7d$$u7d$17h2c0c2de76fcae1e7E + 355
	70  trguing                             0x000000010c3018dc _ZN5tokio7runtime7context7runtime13enter_runtime17hecb05cda0e891aa3E + 220
	71  trguing                             0x000000010c30c381 _ZN5tokio7runtime9scheduler12multi_thread6worker3run17h473ebf6192cf7077E + 561
	72  trguing                             0x000000010c30c141 _ZN5tokio7runtime9scheduler12multi_thread6worker6Launch6launch28_$u7b$$u7b$closure$u7d$$u7d$17h240a92828f8f2eebE + 17
	73  trguing                             0x000000010c310d06 _ZN102_$LT$tokio..runtime..blocking..task..BlockingTask$LT$T$GT$$u20$as$u20$core..future..future..Future$GT$4poll17h50b3c0da6b35e124E + 118
	74  trguing                             0x000000010c3355f5 _ZN5tokio7runtime4task4core17Core$LT$T$C$S$GT$4poll28_$u7b$$u7b$closure$u7d$$u7d$17h9ebd142f9a68f1bcE + 101
	75  trguing                             0x000000010c335448 _ZN5tokio7runtime4task4core17Core$LT$T$C$S$GT$4poll17h028d064f1fe32cecE + 56
	76  trguing                             0x000000010c3240a7 _ZN5tokio7runtime4task7harness11poll_future28_$u7b$$u7b$closure$u7d$$u7d$17h2cb6ea2397ecf6adE + 71
	77  trguing                             0x000000010c309002 _ZN115_$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$9call_once17h15f1ba179fe00350E + 34
	78  trguing                             0x000000010c309456 _ZN3std9panicking3try7do_call17h622591ede7e60a9fE + 54
	79  trguing                             0x000000010c2f6acd __rust_try + 29
	80  trguing                             0x000000010c2f42a2 _ZN3std5panic12catch_unwind17h83ed0f2beec2733fE + 82
	81  trguing                             0x000000010c323c73 _ZN5tokio7runtime4task7harness11poll_future17h43f235a405c3a5ceE + 115
	82  trguing                             0x000000010c322b26 _ZN5tokio7runtime4task7harness20Harness$LT$T$C$S$GT$10poll_inner17h8cf936f8e139f599E + 134
	83  trguing                             0x000000010c322875 _ZN5tokio7runtime4task7harness20Harness$LT$T$C$S$GT$4poll17h665caef9dcba709aE + 21
	84  trguing                             0x000000010c31f97d _ZN5tokio7runtime4task3raw4poll17h5b198bbea979f154E + 29
	85  trguing                             0x000000010c31f6f6 _ZN5tokio7runtime4task3raw7RawTask4poll17hc4cbd9c33b85ce7fE + 38
	86  trguing                             0x000000010c316e7e _ZN5tokio7runtime4task20UnownedTask$LT$S$GT$3run17h2e1a2de2296f5c4fE + 46
	87  trguing                             0x000000010c2e9799 _ZN5tokio7runtime8blocking4pool4Task3run17h7522f86b1aa8256cE + 25
	88  trguing                             0x000000010c2eb8a0 _ZN5tokio7runtime8blocking4pool5Inner3run17hd4f1ce091573ea00E + 496
	89  trguing                             0x000000010c2eb626 _ZN5tokio7runtime8blocking4pool7Spawner12spawn_thread28_$u7b$$u7b$closure$u7d$$u7d$17hb28d0044f4837a81E + 134
	90  trguing                             0x000000010c2f3f6d _ZN3std3sys9backtrace28__rust_begin_short_backtrace17h352dd52abadcc8f7E + 13
	91  trguing                             0x000000010c32d160 _ZN3std6thread7Builder16spawn_unchecked_28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17h8641cc4f11ea9683E + 48
	92  trguing                             0x000000010c3090c0 _ZN115_$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$9call_once17h8a64eb289fe9f6d8E + 48
	93  trguing                             0x000000010c3096e0 _ZN3std9panicking3try7do_call17hf9cdee01075319c9E + 64
	94  trguing                             0x000000010c330d0d __rust_try + 29
	95  trguing                             0x000000010c32cdb3 _ZN3std6thread7Builder16spawn_unchecked_28_$u7b$$u7b$closure$u7d$$u7d$17h6df6f05e1f6d265eE + 755
	96  trguing                             0x000000010c2d7d11 _ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h3d1aaa82df38aa73E + 17
	97  trguing                             0x000000010c85d6bb _ZN3std3sys3pal4unix6thread6Thread3new12thread_start17hcd19cc58b6db093aE + 43
	98  libsystem_pthread.dylib             0x00007ff808efb4e1 _pthread_start + 125
	99  libsystem_pthread.dylib             0x00007ff808ef6f6b thread_start + 15
)
thread 'tokio-runtime-worker' panicked at library/core/src/panicking.rs:221:5:
panic in a function that cannot unwind
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:112:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:122:5
   3: core::panicking::panic_nounwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:221:5
   4: core::panicking::panic_cannot_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:309:5
   5: objc2::exception::try_no_ret::try_objc_execute_closure
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc2-0.5.2/src/exception.rs:196:9
   6: rust_objc_sys_0_3_try_catch_exception
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc-sys-0.3.5/extern/exception.m:14:9
   7: objc2::exception::try_no_ret
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc2-0.5.2/src/exception.rs:232:28
   8: objc2::exception::catch
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc2-0.5.2/src/exception.rs:291:27
   9: objc2::runtime::message_receiver::MessageReceiver::send_message
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc2-0.5.2/src/runtime/message_receiver.rs:25:15
  10: objc2::__macro_helpers::msg_send::MsgSend::send_message
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc2-0.5.2/src/__macro_helpers/msg_send.rs:27:31
  11: objc2_app_kit::generated::__NSView::NSView::removeFromSuperview
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/objc2-0.5.2/src/macros/extern_methods.rs:247:14
  12: tray_icon::platform_impl::platform::TrayIcon::remove
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.19.2/src/platform_impl/macos/mod.rs:106:17
  13: <tray_icon::platform_impl::platform::TrayIcon as core::ops::drop::Drop>::drop
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.19.2/src/platform_impl/macos/mod.rs:258:9
  14: core::ptr::drop_in_place<tray_icon::platform_impl::platform::TrayIcon>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ptr/mod.rs:542:1
  15: core::ptr::drop_in_place<core::cell::UnsafeCell<tray_icon::platform_impl::platform::TrayIcon>>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ptr/mod.rs:542:1
  16: core::ptr::drop_in_place<core::cell::RefCell<tray_icon::platform_impl::platform::TrayIcon>>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ptr/mod.rs:542:1
  17: <alloc::rc::Rc<T,A> as core::ops::drop::Drop>::drop
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/rc.rs:2222:17
  18: core::ptr::drop_in_place<alloc::rc::Rc<core::cell::RefCell<tray_icon::platform_impl::platform::TrayIcon>>>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ptr/mod.rs:542:1
  19: core::ptr::drop_in_place<tray_icon::TrayIcon>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ptr/mod.rs:542:1
  20: core::ptr::drop_in_place<tauri::tray::TrayIcon>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ptr/mod.rs:542:1
  21: core::ptr::drop_in_place<[tauri::tray::TrayIcon]>
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ptr/mod.rs:542:1
  22: alloc::vec::Vec<T,A>::clear
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/vec/mod.rs:2243:13
  23: tauri::app::AppHandle<R>::cleanup_before_exit
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/app.rs:888:9
  24: trguing::setup::{{closure}}::{{closure}}
             at ./src/main.rs:149:13
  25: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/alloc/src/boxed.rs:2084:9
  26: tauri::event::listener::Listeners::emit_filter
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/event/listener.rs:204:13
  27: tauri::event::listener::Listeners::emit
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/event/listener.rs:219:5
  28: tauri::manager::AppManager<R>::emit
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/manager/mod.rs:558:5
  29: tauri::Emitter::emit
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/lib.rs:943:5
  30: tauri::event::plugin::emit::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/event/plugin.rs:64:3
  31: <F as futures_core::future::TryFuture>::try_poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-core-0.3.31/src/future.rs:92:9
  32: <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/try_future/into_future.rs:34:9
  33: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/map.rs:55:37
  34: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  35: <futures_util::future::try_future::MapErr<Fut,F> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  36: <futures_util::future::try_future::ErrInto<Fut,E> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  37: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/map.rs:55:37
  38: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  39: tauri::event::plugin::init::{{closure}}::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/event/plugin.rs:58:1
  40: tauri::ipc::InvokeResolver<R>::respond_async_serialized::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.2.5/src/ipc/mod.rs:343:33
  41: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/future/future.rs:123:9
  42: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/core.rs:331:17
  43: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/loom/std/unsafe_cell.rs:16:9
  44: tokio::runtime::task::core::Core<T,S>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/core.rs:320:13
  45: tokio::runtime::task::harness::poll_future::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:532:19
  46: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panic/unwind_safe.rs:272:9
  47: std::panicking::try::do_call
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  48: ___rust_try
  49: std::panicking::try
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  50: std::panic::catch_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  51: tokio::runtime::task::harness::poll_future
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:520:18
  52: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:209:27
  53: tokio::runtime::task::harness::Harness<T,S>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:154:15
  54: tokio::runtime::task::raw::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/raw.rs:271:5
  55: tokio::runtime::task::raw::RawTask::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/raw.rs:201:18
  56: tokio::runtime::task::LocalNotified<S>::run
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/mod.rs:449:9
  57: tokio::runtime::scheduler::multi_thread::worker::Context::run_task::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/scheduler/multi_thread/worker.rs:596:13
  58: tokio::runtime::coop::with_budget
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/coop.rs:107:5
  59: tokio::runtime::coop::budget
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/coop.rs:73:5
  60: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/scheduler/multi_thread/worker.rs:595:9
  61: tokio::runtime::scheduler::multi_thread::worker::Context::run
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/scheduler/multi_thread/worker.rs:546:24
  62: tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/scheduler/multi_thread/worker.rs:511:21
  63: tokio::runtime::context::scoped::Scoped<T>::set
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/context/scoped.rs:40:9
  64: tokio::runtime::context::set_scheduler::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/context.rs:180:26
  65: std::thread::local::LocalKey<T>::try_with
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:283:12
  66: std::thread::local::LocalKey<T>::with
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/local.rs:260:9
  67: tokio::runtime::context::set_scheduler
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/context.rs:180:9
  68: tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/scheduler/multi_thread/worker.rs:506:9
  69: tokio::runtime::context::runtime::enter_runtime
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/context/runtime.rs:65:16
  70: tokio::runtime::scheduler::multi_thread::worker::run
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/scheduler/multi_thread/worker.rs:498:5
  71: tokio::runtime::scheduler::multi_thread::worker::Launch::launch::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/scheduler/multi_thread/worker.rs:464:45
  72: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/blocking/task.rs:42:21
  73: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/core.rs:331:17
  74: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/loom/std/unsafe_cell.rs:16:9
  75: tokio::runtime::task::core::Core<T,S>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/core.rs:320:13
  76: tokio::runtime::task::harness::poll_future::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:532:19
  77: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panic/unwind_safe.rs:272:9
  78: std::panicking::try::do_call
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  79: ___rust_try
  80: std::panicking::try
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  81: std::panic::catch_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  82: tokio::runtime::task::harness::poll_future
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:520:18
  83: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:209:27
  84: tokio::runtime::task::harness::Harness<T,S>::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/harness.rs:154:15
  85: tokio::runtime::task::raw::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/raw.rs:271:5
  86: tokio::runtime::task::raw::RawTask::poll
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/raw.rs:201:18
  87: tokio::runtime::task::UnownedTask<S>::run
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/task/mod.rs:486:9
  88: tokio::runtime::blocking::pool::Task::run
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/blocking/pool.rs:161:9
  89: tokio::runtime::blocking::pool::Inner::run
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/blocking/pool.rs:511:17
  90: tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}
             at /Users/quick/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.43.0/src/runtime/blocking/pool.rs:469:13
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.
```

### Additional context

_No response_