/// <summary> /// A BrowserView can be used to embed additional web content into a BrowserWindow. /// It is like a child window, except that it is positioned relative to its owning window. /// It is meant to be an alternative to the webview tag. /// </summary> /// <param name="options"></param> /// <returns></returns> public Task <BrowserView> CreateBrowserViewAsync(BrowserViewConstructorOptions options) { var taskCompletionSource = new TaskCompletionSource <BrowserView>(); BridgeConnector.Socket.On("BrowserViewCreated", (id) => { BridgeConnector.Socket.Off("BrowserViewCreated"); string browserViewId = id.ToString(); BrowserView browserView = new BrowserView(int.Parse(browserViewId)); _browserViews.Add(browserView); taskCompletionSource.SetResult(browserView); }); var ownjsonSerializer = new JsonSerializer() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore }; BridgeConnector.Socket.Emit("createBrowserView", JObject.FromObject(options, ownjsonSerializer)); return(taskCompletionSource.Task); }
/// <summary> /// A BrowserView can be used to embed additional web content into a BrowserWindow. /// It is like a child window, except that it is positioned relative to its owning window. /// It is meant to be an alternative to the webview tag. /// </summary> /// <param name="options"></param> /// <returns></returns> public Task <BrowserView> CreateBrowserViewAsync(BrowserViewConstructorOptions options) { var taskCompletionSource = new TaskCompletionSource <BrowserView>(TaskCreationOptions.RunContinuationsAsynchronously); BridgeConnector.On <int>("BrowserViewCreated", (id) => { BridgeConnector.Off("BrowserViewCreated"); BrowserView browserView = new BrowserView(id); _browserViews.Add(browserView); taskCompletionSource.SetResult(browserView); }); var keepDefaultValuesSerializer = new JsonSerializer() { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Include }; BridgeConnector.Emit("createBrowserView", JObject.FromObject(options, keepDefaultValuesSerializer)); return(taskCompletionSource.Task); }