/// <summary> /// Default entry into managed code. /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <object> Invoke(object input) { if (console == null) { console = await WebSharpJs.NodeJS.Console.Instance(); } try { IpcRenderer ipcRenderer = await IpcRenderer.Create(); await console.Log(await ipcRenderer.SendSync("synchronous-message", "synchronous ping")); // prints "pong" ipcRenderer.On("asynchronous-reply", (async(args) => { var argsArray = args as object[]; await console.Log(argsArray[1]); // prints "pong" return(null); })); await ipcRenderer.Send("asynchronous-message", "asynchronous ping"); await console.Log($"Hello: {input}"); } catch (Exception exc) { await console.Log($"extension exception: {exc.Message}"); } return(null); }
async void handleSource(object sender, EventArgs args) { var dialog = await Dialog.Instance(); // Create an OpenDialogOptions reference with custom FileFilters var openOptions = new OpenDialogOptions() { Filters = new FileFilter[] { //new FileFilter() { Name = "All Files", Extensions = new string[] {"*"} }, new FileFilter() { Name = "Movies", Extensions = new string[] { "mkv", "avi" } }, } }; // Now show the open dialog passing in the options created previously // and a call back function when a file is selected. // If a call back function is not specified then the ShowOpenDialog function // will return an array of the selected file(s) or an empty array if no // files are selected. var sourceFile = await dialog.ShowOpenDialog(await BrowserWindow.GetFocusedWindow(), openOptions ); if (sourceFile != null && sourceFile.Length > 0) { await source.SetProperty("value", sourceFile[0]); await name.SetProperty("value", Path.GetFileNameWithoutExtension(sourceFile[0]) + ".m4v"); await source.DispatchEvent(changeEvent); await ipcRenderer.Send("getMetaData", sourceFile[0]); } }
/// <summary> /// Default entry into managed code. /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <object> Invoke(object input) { if (console == null) { console = await WebSharpJs.NodeJS.Console.Instance(); } try { IpcRenderer ipcRenderer = await IpcRenderer.Create(); // Note: Sending a synchronous message from the render process will block // the whole renderer process, unless you know what you are doing you should never use it. // // View notes in MainWindow.cs await console.Log(await ipcRenderer.SendSync("synchronous-message", "synchronous ping")); // prints "pong" ipcRenderer.On("asynchronous-reply", new IpcRendererEventListener(async(result) => { var state = result.CallbackState as object[]; var parms = state[1] as object[]; foreach (var parm in parms) { await console.Log(parm); // prints "pong" } })); await ipcRenderer.Send("asynchronous-message", "asynchronous ping"); await console.Log($"Hello: {input}"); } catch (Exception exc) { await console.Log($"extension exception: {exc.Message}"); } return(null); }
/// <summary> /// Default entry into managed code. /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <object> Invoke(object input) { if (console == null) { console = await WebSharpJs.NodeJS.Console.Instance(); } try { ipcRenderer = await IpcRenderer.Create(); document = await HtmlPage.GetDocument(); var form = await document.QuerySelector("form"); // Input fields source = await form.QuerySelector("input[name=\"source\"]"); destination = await form.QuerySelector("input[name=\"destination\"]"); name = await form.QuerySelector("input[name=\"name\"]"); // Buttons btnSource = await document.GetElementById("chooseSource"); btnDestination = await document.GetElementById("chooseDestination"); btnSubmit = await form.QuerySelector("button[type=\"submit\"]"); // Handle input fields await source.AttachEvent(HtmlEventNames.Input, updateUI); await source.AttachEvent(HtmlEventNames.Change, updateUI); await destination.AttachEvent(HtmlEventNames.Input, updateUI); await destination.AttachEvent(HtmlEventNames.Change, updateUI); await name.AttachEvent(HtmlEventNames.Input, updateUI); // Handle buttons await btnSource.AttachEvent(HtmlEventNames.Click, handleSource); await btnDestination.AttachEvent(HtmlEventNames.Click, handleDestination); // Handle form Submit await form.AttachEvent(HtmlEventNames.Submit, async (s, e) => { e.PreventDefault(); await ToggleUI(true); // Send off the convert request await ipcRenderer.Send("submitform", await source.GetProperty <string>("value"), await destination.GetProperty <string>("value"), await name.GetProperty <string>("value") ); } ); await ipcRenderer.AddListener("gotMetaData", new IpcRendererEventListener( async(result) => { var state = result.CallbackState as object[]; var ipcMainEvent = (IpcRendererEvent)state[0]; var parms = state[1] as object[]; var audio = ScriptObjectHelper.AnonymousObjectToScriptableType <Audio>(parms[0]); var video = ScriptObjectHelper.AnonymousObjectToScriptableType <Video>(parms[1]); var duration = TimeSpan.Parse(parms[2].ToString()); await updateInfo(audio, video, duration); } ) ); await ipcRenderer.AddListener("completed", new IpcRendererEventListener( async(result) => { await ToggleUI(false); } ) ); await console.Log($"Hello: {input}"); } catch (Exception exc) { await console.Log($"extension exception: {exc.Message}"); } return(null); }