Skip to content

Commit

Permalink
full render without passing vars
Browse files Browse the repository at this point in the history
  • Loading branch information
crutkas committed Nov 13, 2021
1 parent a60106a commit 9052fd9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
23 changes: 14 additions & 9 deletions ProofOfConcept/Monaco/monacoPreview/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private void WebView2Init(Object sender, CoreWebView2NavigationCompletedEventArg
// Disable status bar
settings.IsStatusBarEnabled = false;
}

File.Delete(fullCustomFilePath);
}

private void NavigationStarted(Object sender, CoreWebView2NavigationStartingEventArgs e)
Expand Down Expand Up @@ -104,6 +106,8 @@ private void FormResize(object sender, EventArgs e)
webView.Width = this.ActualWidth;
}

string customFileName = Guid.NewGuid().ToString("N") + ".html";
string fullCustomFilePath;
public async void InitializeAsync(string fileName)
{
// This function initializes the webview settings
Expand All @@ -114,15 +118,17 @@ public async void InitializeAsync(string fileName)
var base64FileCode = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(fileContent));

// prepping index html to load in
//var html = File.ReadAllText("index.html").Replace("\t", "");
//html = html.Replace("[[PT_CODE]]", base64FileCode);
//html = html.Replace("[[PT_LANG]]", vsCodeLangSet);
//html = html.Replace("[[PT_WRAP]]", settings.wrap ? "1" : "0");
//html = html.Replace("[[PT_THEME]]", settings.GetTheme(ThemeListener.AppMode));


var html = File.ReadAllText("index.html").Replace("\t", "");

html = html.Replace("[[PT_LANG]]", vsCodeLangSet);
html = html.Replace("[[PT_WRAP]]", settings.wrap ? "1" : "0");
html = html.Replace("[[PT_THEME]]", settings.GetTheme(ThemeListener.AppMode));
html = html.Replace("[[PT_CODE]]", base64FileCode);
File.WriteAllText(customFileName, html);
fullCustomFilePath = Path.Combine(AppContext.BaseDirectory, customFileName);
// Initialize WebView
webView.Source = GetURLwithCode(base64FileCode, vsCodeLangSet);
//webView.Source = GetURLwithCode(base64FileCode, vsCodeLangSet);
webView.Source = new Uri(fullCustomFilePath);
await webView.EnsureCoreWebView2Async(await CoreWebView2Environment.CreateAsync());

//webView.NavigateToString(html);
Expand All @@ -136,7 +142,6 @@ public Uri GetURLwithCode(string code, string lang)

// Converts code to base64
code = HttpUtility.UrlEncode(code); // this is needed for URL encode;
//code = code.Replace("+", "%2B");

return new Uri(settings.baseURL + "?code=" + code + "&lang=" + lang + "&theme=" + settings.GetTheme(ThemeListener.AppMode) + "&wrap=" + (settings.wrap ? "1" : "0"));
}
Expand Down
32 changes: 15 additions & 17 deletions ProofOfConcept/Monaco/monacoPreview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@
// `theme` can be "light" or "dark"
// `lang` is the language of the file
// `wrap` if the editor is wraping or not
//var theme = ("[[PT_THEME]]" == "dark") ? "vs-dark" : "vs";
//var lang = "[[PT_LANG]]";
//var wrap = ([[PT_WRAP]] == 1) ? true : false;
var theme = ("[[PT_THEME]]" == "dark") ? "vs-dark" : "vs";
var lang = "[[PT_LANG]]";
var wrap = ([[PT_WRAP]] == 1) ? true : false;

//var base64code = "[[PT_CODE]]";
//alert(base64code);

//var code = [atob(base64code)].join('\n');
//alert(code);
var base64code = "[[PT_CODE]]";
var code = [atob(base64code)].join('\n');

const urlParams = new URLSearchParams(window.location.search);
// Code for the editor
code = [atob(urlParams.get("code"))].join('\n');
// Theme of the editor
theme = urlParams.get("theme") == "dark" ? "vs-dark" : "vs";
// Code language
lang = urlParams.get("lang");
// Word wraping
wrap = urlParams.get("wrap") == 1 ? true : false;

// const urlParams = new URLSearchParams(window.location.search);
// // Code for the editor
// code = [atob(urlParams.get("code"))].join('\n');
// // Theme of the editor
// theme = urlParams.get("theme") == "dark" ? "vs-dark" : "vs";
// // Code language
// lang = urlParams.get("lang");
// // Word wraping
//wrap = urlParams.get("wrap") == 1 ? true : false;

//URL for accessibility help
accessibilityHelpUrl = "";
Expand Down

1 comment on commit 9052fd9

@github-actions

This comment was marked as outdated.

Please sign in to comment.