Code Monkey home page Code Monkey logo

Comments (6)

tseli0s avatar tseli0s commented on June 2, 2024 2

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.

from nvdialog.

alr2413 avatar alr2413 commented on June 2, 2024

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.

from nvdialog.

tseli0s avatar tseli0s commented on June 2, 2024

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.

from nvdialog.

alr2413 avatar alr2413 commented on June 2, 2024

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
}

from nvdialog.

alr2413 avatar alr2413 commented on June 2, 2024

@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

from nvdialog.

tseli0s avatar tseli0s commented on June 2, 2024

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

from nvdialog.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.