async Task InitializeAsync(string userDataFolder, ControlsBrowserTypes browserType, string navigationPath) { if (browserType == ControlsBrowserTypes.UIControlsBrowser) { //set up an Environment which we can then use for the Options Browser as well. ControlsCoreWebView2Environment = await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(null, userDataFolder, null); } await EnsureCoreWebView2Async(ControlsCoreWebView2Environment); CoreWebView2.Settings.AreDevToolsEnabled = false; CoreWebView2.Settings.IsZoomControlEnabled = false; CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; DefaultBackgroundColor = System.Drawing.Color.Transparent; ZoomFactorChanged += ControlsBrowser_ZoomFactorChanged; CoreWebView2.Navigate(navigationPath); if (browserType == ControlsBrowserTypes.OptionsControlsBrowser) { LostFocus += OptionsControlsBrowser_LostFocus; Visibility = System.Windows.Visibility.Hidden; } }
private async void LoadedWebview() { await Storage.ensureAsserts(); sourceFolder = Storage.getStoragePath("Source"); engine = await Task.Run(() => { return(Python.CreateEngine()); }); ICollection <string> Paths = engine.GetSearchPaths(); Paths.Add(sourceFolder); Paths.Add(getSourcePath("Lib")); engine.SetSearchPaths(Paths); await MainWebView.EnsureCoreWebView2Async(); coreWebView = MainWebView.CoreWebView2; coreWebView.Settings.IsZoomControlEnabled = false; coreWebView.Settings.AreDevToolsEnabled = true; coreWebView.Navigate(Storage.getEditorPath()); coreWebView.WebMessageReceived += async(s, e) => { message msg = JsonConvert.DeserializeObject <message>(e.TryGetWebMessageAsString()); if (msg.type == "init_code") { string pyFileSource = await File.ReadAllTextAsync(getSourcePath("test.c")); msg.value = pyFileSource; coreWebView.PostWebMessageAsString(JsonConvert.SerializeObject(msg)); Lexcial.IsEnabled = true; } else if (msg.type == "return_code") { FileStream fs = new FileStream(getSourcePath("test.c--"), FileMode.Create); byte[] data = Encoding.Default.GetBytes(msg.value); fs.Write(data, 0, data.Length); fs.Close(); var result = await Task.Run(() => { return(LexcialAnalyzer()); }); List <token> tokens = new List <token>(); foreach (var item in result) { var temp = item as PythonDictionary; token Token = new token(); Token.type = temp["type"].ToString(); Token.value = temp["name"].ToString(); Token.row = temp["row"].ToString(); Token.colum = temp["colum"].ToString(); tokens.Add(Token); } DataGrid.ItemsSource = tokens; DataGrid.Visibility = Visibility.Visible; Progress.Visibility = Visibility.Collapsed; Syntactic.IsEnabled = true; } }; }