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}!"); } }
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); } } })); }
public static Task Run(this IBridgeToNode thiz, Action action) { return(thiz.Run(() => { action(); return (object)null; })); }
/// <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; }
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()); }
public static Task RunAsync(this IBridgeToNode thiz, Func <object, Task> asyncAction, object state, CancellationToken cancellationToken = default) { return(thiz.Run(asyncAction, state, cancellationToken).Unwrap()); }
public static Task Run(this IBridgeToNode thiz, Action action, CancellationToken cancellationToken = default) { return(thiz.Run(RunActionState, action, cancellationToken)); }
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; }
public static Task RunAsync(this IBridgeToNode thiz, Func <Task> asyncAction) { return(thiz.Run(asyncAction).Unwrap()); }
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); }
public ElectronConsoleWriter(IBridgeToNode node) { _node = node; _console = node.Global.console; }
public ElectronNavigationManager(IBridgeToNode node) { _blazorInternal = node.Global.window.Blazor._internal; _navigationManager = _blazorInternal.navigationManager; }
public static Task Run(this IBridgeToNode thiz, Action <object> action, object state, CancellationToken cancellationToken = default) { return(thiz.Run(RunActionState, new Action(() => action(state)), cancellationToken)); }
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)); }
public ElectronDispatcher(IBridgeToNode node) { _node = node; }