Getting dynamic inMemory loading so no file writing
This commit is contained in:
parent
5c12139052
commit
a3b0fe44af
|
@ -76,8 +76,6 @@ namespace monacoPreview
|
|||
// Disable status bar
|
||||
settings.IsStatusBarEnabled = false;
|
||||
}
|
||||
|
||||
File.Delete(fullCustomFilePath);
|
||||
}
|
||||
|
||||
private void NavigationStarted(Object sender, CoreWebView2NavigationStartingEventArgs e)
|
||||
|
@ -106,8 +104,7 @@ namespace monacoPreview
|
|||
webView.Width = this.ActualWidth;
|
||||
}
|
||||
|
||||
string customFileName = "powerToysPreview" + Guid.NewGuid().ToString("N") + ".html";
|
||||
string fullCustomFilePath;
|
||||
const string VirtualHostName = "PowerToysLocalMonaco";
|
||||
public async void InitializeAsync(string fileName)
|
||||
{
|
||||
// This function initializes the webview settings
|
||||
|
@ -124,26 +121,14 @@ namespace monacoPreview
|
|||
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 = new Uri(fullCustomFilePath);
|
||||
await webView.EnsureCoreWebView2Async(await CoreWebView2Environment.CreateAsync());
|
||||
html = html.Replace("[[PT_URL]]", VirtualHostName);
|
||||
|
||||
//webView.NavigateToString(html);
|
||||
// Initialize WebView
|
||||
await webView.EnsureCoreWebView2Async();
|
||||
webView.CoreWebView2.SetVirtualHostNameToFolderMapping(VirtualHostName, AppDomain.CurrentDomain.BaseDirectory, CoreWebView2HostResourceAccessKind.DenyCors);
|
||||
webView.NavigateToString(html);
|
||||
webView.NavigationCompleted += WebView2Init;
|
||||
webView.NavigationStarting += NavigationStarted;
|
||||
}
|
||||
|
||||
public Uri GetURLwithCode(string code, string lang)
|
||||
{
|
||||
// This function returns a url you can use to access index.html
|
||||
|
||||
// Converts code to base64
|
||||
code = HttpUtility.UrlEncode(code); // this is needed for URL encode;
|
||||
|
||||
return new Uri(settings.baseURL + "?code=" + code + "&lang=" + lang + "&theme=" + settings.GetTheme(ThemeListener.AppMode) + "&wrap=" + (settings.wrap ? "1" : "0"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@
|
|||
<!-- Container for the editor -->
|
||||
<div id="container"></div>
|
||||
<!-- Script -->
|
||||
<script src="monacoSRC/min/vs/loader.js"></script>
|
||||
<script src="http://[[PT_URL]]/monacoSRC/min/vs/loader.js"></script>
|
||||
<script>
|
||||
require.config({ paths: { vs: 'monacoSRC/min/vs' } });
|
||||
require.config({ paths: { vs: 'http://[[PT_URL]]/monacoSRC/min/vs' } });
|
||||
require(['vs/editor/editor.main'], function () {
|
||||
// Creates the editor
|
||||
// For all parameters: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandaloneeditorconstructionoptions.html
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="6.1.1" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.1.1" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.Controls" Version="6.1.2" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.705.50" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1020.30" />
|
||||
<PackageReference Include="WindowsThemeListener" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -42,5 +42,8 @@
|
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Update="Microsoft.VCRTForwarders.140" Version="1.0.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Reference in a new issue