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
|
// Disable status bar
|
||||||
settings.IsStatusBarEnabled = false;
|
settings.IsStatusBarEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
File.Delete(fullCustomFilePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NavigationStarted(Object sender, CoreWebView2NavigationStartingEventArgs e)
|
private void NavigationStarted(Object sender, CoreWebView2NavigationStartingEventArgs e)
|
||||||
|
@ -106,8 +104,7 @@ namespace monacoPreview
|
||||||
webView.Width = this.ActualWidth;
|
webView.Width = this.ActualWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
string customFileName = "powerToysPreview" + Guid.NewGuid().ToString("N") + ".html";
|
const string VirtualHostName = "PowerToysLocalMonaco";
|
||||||
string fullCustomFilePath;
|
|
||||||
public async void InitializeAsync(string fileName)
|
public async void InitializeAsync(string fileName)
|
||||||
{
|
{
|
||||||
// This function initializes the webview settings
|
// 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_WRAP]]", settings.wrap ? "1" : "0");
|
||||||
html = html.Replace("[[PT_THEME]]", settings.GetTheme(ThemeListener.AppMode));
|
html = html.Replace("[[PT_THEME]]", settings.GetTheme(ThemeListener.AppMode));
|
||||||
html = html.Replace("[[PT_CODE]]", base64FileCode);
|
html = html.Replace("[[PT_CODE]]", base64FileCode);
|
||||||
File.WriteAllText(customFileName, html);
|
html = html.Replace("[[PT_URL]]", VirtualHostName);
|
||||||
fullCustomFilePath = Path.Combine(AppContext.BaseDirectory, customFileName);
|
|
||||||
// Initialize WebView
|
|
||||||
//webView.Source = GetURLwithCode(base64FileCode, vsCodeLangSet);
|
|
||||||
webView.Source = new Uri(fullCustomFilePath);
|
|
||||||
await webView.EnsureCoreWebView2Async(await CoreWebView2Environment.CreateAsync());
|
|
||||||
|
|
||||||
//webView.NavigateToString(html);
|
// Initialize WebView
|
||||||
|
await webView.EnsureCoreWebView2Async();
|
||||||
|
webView.CoreWebView2.SetVirtualHostNameToFolderMapping(VirtualHostName, AppDomain.CurrentDomain.BaseDirectory, CoreWebView2HostResourceAccessKind.DenyCors);
|
||||||
|
webView.NavigateToString(html);
|
||||||
webView.NavigationCompleted += WebView2Init;
|
webView.NavigationCompleted += WebView2Init;
|
||||||
webView.NavigationStarting += NavigationStarted;
|
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 -->
|
<!-- Container for the editor -->
|
||||||
<div id="container"></div>
|
<div id="container"></div>
|
||||||
<!-- Script -->
|
<!-- Script -->
|
||||||
<script src="monacoSRC/min/vs/loader.js"></script>
|
<script src="http://[[PT_URL]]/monacoSRC/min/vs/loader.js"></script>
|
||||||
<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 () {
|
require(['vs/editor/editor.main'], function () {
|
||||||
// Creates the editor
|
// Creates the editor
|
||||||
// For all parameters: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandaloneeditorconstructionoptions.html
|
// For all parameters: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandaloneeditorconstructionoptions.html
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<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.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" />
|
<PackageReference Include="WindowsThemeListener" Version="1.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -42,5 +42,8 @@
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Update="Microsoft.VCRTForwarders.140" Version="1.0.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in a new issue