Beispiel #1
0
        private async Task Initialize(string title, NotificationOptions options)
        {
            Func <object, Task <object> > notification = await WebSharp.CreateJavaScriptFunction(@"
                                return function (options, callback) {
                                    let notification = new Notification(options.title, options);
                                    
                                    let proxy = {};
                                    proxy.get_title = function (data, cb) {
                                        cb(null, notification.title);
                                    };
                                    
                                    proxy.get_dir = function (data, cb) {
                                        cb(null, notification.dir);
                                    };
                                    proxy.get_lang = function (data, cb) {
                                        cb(null, notification.lang);
                                    };
                                    proxy.get_body = function (data, cb) {
                                        cb(null, notification.body);
                                    };
                                    proxy.get_tag = function (data, cb) {
                                        cb(null, notification.tag);
                                    };
                                    proxy.get_image = function (data, cb) {
                                        cb(null, notification.image);
                                    };
                                    proxy.get_icon = function (data, cb) {
                                        cb(null, notification.icon);
                                    };
                                    proxy.get_badge = function (data, cb) {
                                        cb(null, notification.badge);
                                    };
                                    proxy.get_sound = function (data, cb) {
                                        cb(null, notification.sound);
                                    };
                                    proxy.get_timestamp = function (data, cb) {
                                        cb(null, notification.timestamp);
                                    };
                                    proxy.get_renotify = function (data, cb) {
                                        cb(null, notification.renotify);
                                    };
                                    proxy.get_silent = function (data, cb) {
                                        cb(null, notification.silent);
                                    };
                                    proxy.get_requireInteraction = function (data, cb) {
                                        cb(null, notification.requireInteraction);
                                    };
                                    proxy.get_data = function (data, cb) {
                                        cb(null, notification.data);
                                    };

//   [SameObject] readonly attribute FrozenArray<unsigned long> vibrate;
//   [SameObject] readonly attribute FrozenArray<NotificationAction> actions;
                                    
                                    if (options.onclick) 
                                    {  
                                        if (options.onclick.formatter)
                                        {
                                            
                                            notification.onclick = function (evt) {
                                                 let event = {};
                                                 event.Event = {};
                                                 event.SrcElement = proxy;
                                                 event.Handler = options.onclick.handler;
                                                 // very simple serialization of event
                                                 for ( name in evt ) {
                                                    event.Event[name] = evt[ name ];
                                                 };
                                                 options.onclick.formatter(event, null);
                                             }
                                        }
                                        else
                                            notification.onclick = options.onclick.handler;
                                    }
                                    if (options.onshow) 
                                    {  
                                        if (options.onshow.formatter)
                                        {
                                            
                                            notification.onshow = function (evt) {
                                                 let event = {};
                                                 event.Event = {};
                                                 event.SrcElement = proxy;
                                                 event.Handler = options.onshow.handler;
                                                 // very simple serialization of event
                                                 for ( name in evt ) {
                                                    event.Event[name] = evt[ name ];
                                                 };
                                                 options.onshow.formatter(event, null);
                                             }
                                        }
                                        else
                                            notification.onshow = options.onshow.handler(null, null);
                                    }

                                    if (options.onerror) 
                                    {  
                                        if (options.onerror.formatter)
                                        {
                                            
                                            notification.onerror = function (evt) {
                                                 let event = {};
                                                 event.Event = {};
                                                 event.SrcElement = proxy;
                                                 event.Handler = options.onerror.handler;
                                                 // very simple serialization of event
                                                 for ( name in evt ) {
                                                    event.Event[name] = evt[ name ];
                                                 };
                                                 options.onerror.formatter(event, null);
                                             }
                                        }
                                        else
                                            notification.onerror = options.onerror.handler;
                                    }
                                    
                                    //console.log(notification);
                                    callback(null, proxy);
                                }
                            ");

            if (!string.IsNullOrEmpty(title))
            {
                options.Title = title;
            }

            _notificationProxy = await notification(options.AsDictionary());
        }