Example #1
0
        private static async Task RunAsyncApp(IBridgeToNode host)
        {
            try
            {
                host.Global.console.log($"Hello world from pid:{host.Global.process.pid}!");

                await host.RunAsync(async() =>
                {
                    var global  = host.Global;
                    var console = global.console;

                    console.log("Dynamic log from .Net is ", true);

                    console.log("TestClass", global.TestClass.CreateNewInstance("Hallo ctor argument"));

                    global.testCallback(new Func <string, string, string>(MarshalledDelegate), "SecondArg", "ThirdArg");
                    //global.gc();

                    await Task.Delay(100);

                    console.log("DELAYED");

                    var dynInstance = host.New();
                    dynInstance.dynamicProperty1 = "DynProp1";
                    dynInstance.dynamicProperty2 = new Func <string, string, string>(MarshalledDelegate2);
                    // TODO: Why can we not read from the dynamic properties? e.g. dynInstance.dynamicProperty1

                    //global.gc();

                    global.testCallback(new Func <string, string, string>(MarshalledDelegate2), dynInstance, "ThirdArg2");

                    await Task.Delay(100);
                    //global.gc();

                    global.testCallback(new Func <string, string, string>(MarshalledDelegate), "3", dynInstance);
                    //global.gc();

                    global.testCallback(new Func <string, string, string>((a, b) => { console.log("asdas"); return(null); }), "3", dynInstance);

                    var tcs = new TaskCompletionSource <object>();
                    global.callLater(new Action(() =>
                    {
                        console.log("We have been called later");
                        tcs.SetResult(null);
                        throw new InvalidOperationException("Test exception");
                    }));

                    Console.WriteLine($"Int from JS {(int)global.testAddon.a}");
                    await tcs.Task;
                });
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e);
            }
            finally
            {
                host.Global.console.log($"ByeBye world from pid:{host.Global.process.pid}!");
            }
        }
Example #2
0
        public void Register(IBridgeToNode node, Action afterCallback)
        {
            Node   = node;
            Global = node.Global;

            Global.describe(GetType().Name.Replace("_", " "),
                            new Action(() =>
            {
                Global.after(afterCallback);
                foreach (var method in GetType().GetMethods())
                {
                    var callback = method.ReturnType == typeof(void) ?
                                   SyncTest(method) :
                                   AsyncTest(method);

                    if (method.Name == "Before")
                    {
                        Global.before(callback);
                    }
                    else if (method.Name.StartsWith("It_"))
                    {
                        Global.it(method.Name.Replace("It_", " ").Replace("_", " "), callback);
                    }
                }
            }));
        }
Example #3
0
 public static Task Run(this IBridgeToNode thiz, Action action)
 {
     return(thiz.Run(() =>
     {
         action();
         return (object)null;
     }));
 }
Example #4
0
        /// <summary>
        /// Constructs an instance of <see cref="ElectronRenderer"/>.
        /// </summary>
        /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use when initializing components.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        /// <param name="node">The bridge to use for JS interop</param>
        public ElectronRenderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IBridgeToNode node) : base(serviceProvider, loggerFactory)
        {
            _node           = node;
            _logger         = loggerFactory.CreateLogger <ElectronRenderer>();
            _blazorInternal = node.Global.window.Blazor._internal;
            _dispatcher     = new ElectronDispatcher(node);
            var eventDispatcher = new ElectronEventDispatcher(this);

            _blazorInternal.HandleRendererEvent = new Func <dynamic, string, Task>(eventDispatcher.DispatchEvent);
            _blazorInternalRenderBatch          = _blazorInternal.renderBatch;
        }
Example #5
0
        public ElectronJSRuntime(IBridgeToNode node)
        {
            _node             = node;
            using var dotNet  = node.Global.DotNet;
            _jsCallDispatcher = dotNet.jsCallDispatcher;

            using var dotnetDispatcher               = node.New();
            dotnetDispatcher.invokeDotNetFromJS      = new Func <string, string, dynamic, string, string>(InvokeDotNetFromJS);
            dotnetDispatcher.beginInvokeDotNetFromJS = new Action <long, string, string, dynamic, string>(BeginInvokeDotNetFromJS);
            dotnetDispatcher.endInvokeJSFromDotNet   = new Action <long, bool, string>(EndInvokeJSFromDotNet);
            dotNet.attachDispatcher(dotnetDispatcher);
            JsonSerializerOptions.Converters.Add(new ElementReferenceJsonConverter());
        }
Example #6
0
 public static Task RunAsync(this IBridgeToNode thiz, Func <object, Task> asyncAction, object state, CancellationToken cancellationToken = default)
 {
     return(thiz.Run(asyncAction, state, cancellationToken).Unwrap());
 }
Example #7
0
 public static Task Run(this IBridgeToNode thiz, Action action, CancellationToken cancellationToken = default)
 {
     return(thiz.Run(RunActionState, action, cancellationToken));
 }
Example #8
0
 public static Task <T> RunAsync <T>(this IBridgeToNode thiz, Func <Task <T> > asyncFunc, CancellationToken cancellationToken = default)
 {
     return(thiz.Run(asyncFunc, cancellationToken).Unwrap());
 }
 public ElectronNavigationInterception(IBridgeToNode node)
 {
     _navigationManager = node.Global.window.Blazor._internal.navigationManager;
 }
Example #10
0
 public static Task RunAsync(this IBridgeToNode thiz, Func <Task> asyncAction)
 {
     return(thiz.Run(asyncAction).Unwrap());
 }
Example #11
0
 public static Task <T> RunAsync <T>(this IBridgeToNode thiz, Func <Task <T> > asyncFunc)
 {
     return(thiz.Run(asyncFunc).Unwrap());
 }
 public ElectronLoggerProvider(IBridgeToNode node)
 {
     _writer = new ElectronConsoleWriter(node);
 }
Example #13
0
 public ElectronConsoleWriter(IBridgeToNode node)
 {
     _node    = node;
     _console = node.Global.console;
 }
 public ElectronNavigationManager(IBridgeToNode node)
 {
     _blazorInternal    = node.Global.window.Blazor._internal;
     _navigationManager = _blazorInternal.navigationManager;
 }
Example #15
0
 public static Task Run(this IBridgeToNode thiz, Action <object> action, object state, CancellationToken cancellationToken = default)
 {
     return(thiz.Run(RunActionState, new Action(() => action(state)), cancellationToken));
 }
Example #16
0
 public ElectronHost(IServiceProvider services, IJSRuntime runtime, IBridgeToNode node)
 {
     Services = services ?? throw new ArgumentNullException(nameof(services));
     _runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
     _node    = node ?? throw new ArgumentNullException(nameof(node));
 }
Example #17
0
 public ElectronDispatcher(IBridgeToNode node)
 {
     _node = node;
 }