h4llow3En / mac-notification-sys

✉️ A simple wrapper to deliver or schedule macOS Notifications in Rust
98 stars 30 forks source link

crash when label is clicked in the dropdown options #54

Closed radiohertz closed 1 year ago

radiohertz commented 1 year ago

i have a notification which is setup like this

        let res = send_notification(
            "My App",
            Some(&format!(
                "Following device wants to mount: {:?}",
                disk.volume_name
            )),
            "Please allow/deny.",
            Some(Notification::new().main_button(
                mac_notification_sys::MainButton::DropdownActions("Choose", &["Allow", "Deny"]),
            )),
        )
        .unwrap();

i accidentally clicked on the "Choose" option which is supposed to be label and the program aborted. is there a way to make the label not clickable?

2023-08-10 10:42:44.313 diskguard[4386:36931] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndexedSubscript:]: index 9223372036854775807 beyond bounds [0 .. 1]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000019bdbf154 __exceptionPreprocess + 176
    1   libobjc.A.dylib                     0x000000019b8de4d4 objc_exception_throw + 60
    2   CoreFoundation                      0x000000019bea99b8 -[__NSCFString characterAtIndex:].cold.1 + 0
    3   CoreFoundation                      0x000000019bd32ee8 +[NSNull null] + 0
    4   diskguard                           0x00000001041eba10 -[NotificationCenterDelegate userNotificationCenter:didActivateNotification:] + 244
    5   Foundation                          0x000000019cd4e8d0 -[_NSConcreteUserNotificationCenter _sendDelegateMessage:sendToAppDelegate:withObject:] + 132
    6   Foundation                          0x000000019d2f3b74 -[_NSConcreteUserNotificationCenter _notificationClickedMessage:] + 436
    7   Foundation                          0x000000019cd08c90 __54-[_NSConcreteUserNotificationCenter _serverConnection]_block_invoke_4 + 88
    8   libdispatch.dylib                   0x000000019bab6874 _dispatch_call_block_and_release + 32
    9   libdispatch.dylib                   0x000000019bab8400 _dispatch_client_callout + 20
    10  libdispatch.dylib                   0x000000019bac6bf8 _dispatch_main_queue_drain + 928
    11  libdispatch.dylib                   0x000000019bac6848 _dispatch_main_queue_callback_4CF + 44
    12  CoreFoundation                      0x000000019bd87c54 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
    13  CoreFoundation                      0x000000019bd453d4 __CFRunLoopRun + 1992
    14  CoreFoundation                      0x000000019bd444b8 CFRunLoopRunSpecific + 612
    15  Foundation                          0x000000019ccbdfcc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
    16  Foundation                          0x000000019cd32394 -[NSRunLoop(NSRunLoop) runUntilDate:] + 100
    17  diskguard                           0x00000001041ec750 sendNotification + 1948
    18  diskguard                           0x00000001041e766c _ZN20mac_notification_sys17send_notification17h534efafd130e8591E + 896
    19  diskguard                           0x00000001041e1d00 _ZN9diskguard11allow_mount17hc6d117dd305f0512E + 780
    20  DiskArbitration                     0x00000001a2e764f4 _DADispatchCallback + 336
    21  DiskArbitration                     0x00000001a2e760f8 _DASessionCallback + 276
    22  CoreFoundation                      0x000000019bd76284 __CFMachPortPerform + 296
    23  CoreFoundation                      0x000000019bd46bcc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 60
    24  CoreFoundation                      0x000000019bd46aec __CFRunLoopDoSource1 + 520
    25  CoreFoundation                      0x000000019bd454cc __CFRunLoopRun + 2240
    26  CoreFoundation                      0x000000019bd444b8 CFRunLoopRunSpecific + 612
    27  CoreFoundation                      0x000000019bdc957c CFRunLoopRun + 64
    28  diskguard                           0x00000001041e20f4 _ZN9diskguard4main17ha29f688eb14bdc19E + 260
    29  diskguard                           0x00000001041e2bb0 _ZN4core3ops8function6FnOnce9call_once17hb33879ec86c26350E + 20
    30  diskguard                           0x00000001041e2564 _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h4733b85134cec3eaE + 24
    31  diskguard                           0x00000001041e2498 _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h372d4bda1ef4d76cE + 28
    32  diskguard                           0x0000000104209710 _ZN3std2rt19lang_start_internal17h434fe84e11a92429E + 648
    33  diskguard                           0x00000001041e2464 _ZN3std2rt10lang_start17h344ff8dd13fec62fE + 84
    34  diskguard                           0x00000001041e2208 main + 36
    35  dyld                                0x000000019b90ff28 start + 2236
)
libc++abi: terminating due to uncaught exception of type NSException
radiohertz commented 1 year ago

cc @hoodie

hoodie commented 1 year ago

nice catch, I recently found this two. Can you verify for me that it does not crash when you use #52?

radiohertz commented 1 year ago

nice catch, I recently found this two. Can you verify for me that it does not crash when you use #52?

hi @hoodie, your patch seems to be working. I don't see any crash now.

hoodie commented 1 year ago

nice to know, I'll merge it this weekend

hoodie commented 1 year ago

this should be fixed with 0.5.9 now