Comments (6)
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.
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.
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.
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.
@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.
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)
- MacOS X Support HOT 1
- [FEAT] Add sandboxing support (Flatpaks, UWP, ...) on NvDialog. HOT 1
- [BUG] Gtk causes segmentation faults. HOT 1
- Why not use IFileOpenDialog? HOT 4
- [BUG] libnotify can't be `dlopen()`'ed on Debian-based distributions. HOT 1
- Finally, have a fallback path in case the original one isn't found.
- Specific NvDialog APIs will not succeed on macOS
- [BUG] Windows code returns a pointer to the stack, Mac has a use after free HOT 1
- [BUG] Windows code ignores cancel on open/save dialogs. HOT 1
- [BUG] Double free crash on Mac HOT 8
- [BUG] A char is treated as a pointer in _NvdDialogBox HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvdialog.