Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog stuck after pressing Ok button on macos #42

Closed
alr2413 opened this issue Jun 14, 2023 · 6 comments · Fixed by #48
Closed

Dialog stuck after pressing Ok button on macos #42

alr2413 opened this issue Jun 14, 2023 · 6 comments · Fixed by #48
Labels
bug Something isn't working macOS Mac-specific issue todo To be worked on tracking Tracking issue upstream Related to upstream

Comments

@alr2413
Copy link

alr2413 commented Jun 14, 2023

Hi,
I tried to compile and use this library on MacOS (12.6 Monterey), but the problem is that when I show a dialog if I click on OK button it hangs.
The issue is exactly same as this one:

https://developer.apple.com/forums/thread/19540

@alr2413 alr2413 added the bug Something isn't working label Jun 14, 2023
@alr2413
Copy link
Author

alr2413 commented Jun 15, 2023

Sorry, that problem was related to other parts of my application. I created a test project which only includes this library and it worked fine.

@alr2413 alr2413 closed this as completed Jun 15, 2023
@tseli0s
Copy link
Owner

tseli0s commented Jun 15, 2023

Could you share the actual problem? I'd like to add some note in the documentation so that other users don't hit the same bug.

@alr2413
Copy link
Author

alr2413 commented Jun 16, 2023

I could not actually find the source of issue. If I use that in a sample project it works fine but when I add it to my main project, it stuck and I think the issue might be related to context,
so I started modifying the library to use "CFUserNotificationDisplayAlert" instead of NSAlert (by adding a definition at top of the file so I can easily switch between them) and it worked perfectly.

here is the content of "nvdialog_dialog_box.m":

#include "nvdialog.h"
#include "nvdialog_cocoa.h"

#include <AppKit/AppKit.h>

#include "../../nvdialog_assert.h"

#define useNSAlert 0

struct _NvdDialogBox {
#if useNSAlert
    NSAlert         *window_handle;
#else
    int             *window_handle;
#endif
    const char      *msg;
    const char      *content;
    NvdDialogType   type;
};

NvdDialogBox *nvd_dialog_box_cocoa(const char *title, const char *message, NvdDialogType type)
{
    NvdDialogBox *dialog = malloc(sizeof(struct _NvdDialogBox));
   	NVD_RETURN_IF_NULL(dialog);

    dialog->content = message;
    dialog->msg = title;
    dialog->type = type;

#if useNSAlert
    
    NSAlert *nativedlg = dialog->window_handle = [[NSAlert alloc] init];

    nativedlg.messageText = @(dialog->msg);
    nativedlg.informativeText = @(dialog->content);

    switch (type) {
    default:
    case NVD_DIALOG_SIMPLE:
        nativedlg.alertStyle = NSAlertStyleInformational;
        break;
    case NVD_DIALOG_WARNING:
        nativedlg.alertStyle = NSAlertStyleWarning;
        break;
    case NVD_DIALOG_ERROR:
        nativedlg.alertStyle = NSAlertStyleCritical;
        break;
    }
#else
    
    CFOptionFlags alertStyle;
    
    switch (type) {
    default:
    case NVD_DIALOG_SIMPLE:
            alertStyle = kCFUserNotificationNoteAlertLevel;
        break;
    case NVD_DIALOG_WARNING:
            alertStyle = kCFUserNotificationCautionAlertLevel;
        break;
    case NVD_DIALOG_ERROR:
            alertStyle = kCFUserNotificationStopAlertLevel;
        break;
    }

    CFStringRef alertHeader = CFStringCreateWithCString(kCFAllocatorDefault, dialog->msg, kCFStringEncodingUTF8);
    
    CFStringRef alertContent = CFStringCreateWithCString(kCFAllocatorDefault, dialog->content, kCFStringEncodingUTF8);
    
    CFOptionFlags cfRes;
    
    CFUserNotificationDisplayAlert(-1, alertStyle,
            NULL, NULL, NULL,
            alertHeader,
            alertContent,
            CFSTR("OK"),
            NULL,
            NULL,
            &cfRes);
#endif
    return dialog;
}

void nvd_show_dialog_cocoa(NvdDialogBox *dialog)
{
#if useNSAlert
    [dialog->window_handle runModal];
//    [dialog->window_handle release];
#else
#endif
}

void *nvd_dialog_box_get_raw_cocoa(NvdDialogBox *dlg)
{
#if useNSAlert
    return (__bridge void *)(dlg->window_handle);
#else
    return dlg->window_handle;
#endif
}

@alr2413 alr2413 reopened this Jun 16, 2023
@tseli0s
Copy link
Owner

tseli0s commented Jun 16, 2023

Consider making a PR then if the code you've posted actually works. Unfortunately I can't detect any issues with macOS since I don't use it.

@tseli0s tseli0s added tracking Tracking issue todo To be worked on upstream Related to upstream labels Jun 16, 2023
@alr2413 alr2413 closed this as completed Jun 16, 2023
@alr2413
Copy link
Author

alr2413 commented Jun 16, 2023

@tseli0s, I need to spend some time to update all other objective-c files.
about the issue you can take a look at this link as well, might be helpful
https://stackoverflow.com/questions/48550829/nsalert-wont-disappear

@tseli0s
Copy link
Owner

tseli0s commented Jun 16, 2023

Sure, take your time. But don't close the issue, this one has not been resolved yet so it has to remain open.

@tseli0s tseli0s reopened this Jun 16, 2023
@tseli0s tseli0s added the macOS Mac-specific issue label Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macOS Mac-specific issue todo To be worked on tracking Tracking issue upstream Related to upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants