diff --git a/ProofOfConcept/Monaco/monacoPreview/MainWindow.xaml.cs b/ProofOfConcept/Monaco/monacoPreview/MainWindow.xaml.cs
index 221d015e7..90924c2a1 100644
--- a/ProofOfConcept/Monaco/monacoPreview/MainWindow.xaml.cs
+++ b/ProofOfConcept/Monaco/monacoPreview/MainWindow.xaml.cs
@@ -1,8 +1,6 @@
using System;
using System.IO;
-using System.Windows;
using Microsoft.Web.WebView2.Core;
-using Windows.UI.Xaml;
using WK.Libraries.WTL;
namespace monacoPreview
@@ -11,7 +9,7 @@ namespace monacoPreview
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : System.Windows.Window
- {
+ {
// This variable prevents users from navigating
private bool WasNavigated = false;
@@ -32,19 +30,20 @@ namespace monacoPreview
string[] file = GetFile(args);
- InitializeAsync(file[0], fileHandler.GetLanguage(file[1]));
+ InitializeAsync(settings.compatibility?file[0]:file[2], fileHandler.GetLanguage(file[1]));
}
- private string[] GetFile(string[] args)
+ public string[] GetFile(string[] args)
{
// This function gets a file
- string[] returnValue = new string[2];
+ string[] returnValue = new string[3];
// Get source code
returnValue[0] = File.ReadAllText(args[1]);
// Gets file extension (without .)
returnValue[1] = Path.GetExtension(args[1]).Replace(".","");
+ returnValue[2] = args[1];
return returnValue;
}
@@ -100,29 +99,43 @@ namespace monacoPreview
webView.Width = this.ActualWidth;
}
- async void InitializeAsync(string code, string lang)
+ public async void InitializeAsync(string code, string lang)
{
// This function initializes the webview settings
// Partely copied from https://weblog.west-wind.com/posts/2021/Jan/14/Taking-the-new-Chromium-WebView2-Control-for-a-Spin-in-NET-Part-1
// Sets the url
- webView.Source = GetURL(code, lang);
+ webView.Source = settings.compatibility?GetURLwithCode(code, lang):GetURLwithFilePath(code, lang);
// Initialize WebView
- var env = await CoreWebView2Environment.CreateAsync();
+
+ var webViewOptions = new CoreWebView2EnvironmentOptions
+ {
+ // Enable CORS for local file access.
+ AdditionalBrowserArguments = "--disable-web-security"
+ };
+
+ var env = await CoreWebView2Environment.CreateAsync(null, null, webViewOptions);
await webView.EnsureCoreWebView2Async(env);
webView.NavigationCompleted += WebView2Init;
webView.NavigationStarting += NavigationStarted;
}
- public Uri GetURL(string code, string lang)
+ public Uri GetURLwithFilePath(string file, string lang)
+ {
+ // This function returns a url you can use to access index.html
+
+ return new Uri(settings.baseURL + "?file=" + file + "&lang=" + lang + "&theme=" + settings.GetTheme(ThemeListener.AppMode) + "&wrap=" + (this.settings.wrap?"1":"0"));
+ }
+
+ public Uri GetURLwithCode(string code, string lang)
{
// This function returns a url you can use to access index.html
// Converts code to base64
code = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(code)).Replace("+", "%2B");
- return new Uri(settings.baseURL + "?code=" + code + "&lang=" + lang + "&theme=" + settings.GetTheme(ThemeListener.AppMode) + "&wrap=" + (this.settings.wrap?"1":"0"));
+ return new Uri(settings.baseURL + "?code=" + code + "&lang=" + lang + "&theme=" + settings.GetTheme(ThemeListener.AppMode) + "&wrap=" + (this.settings.wrap ? "1" : "0"));
}
}
}
diff --git a/ProofOfConcept/Monaco/monacoPreview/MonacoPreviewHandlerInterfaces.cs b/ProofOfConcept/Monaco/monacoPreview/MonacoPreviewHandlerInterfaces.cs
new file mode 100644
index 000000000..298843edf
--- /dev/null
+++ b/ProofOfConcept/Monaco/monacoPreview/MonacoPreviewHandlerInterfaces.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.ComTypes;
+using System.Text;
+
+namespace monacoPreview
+{
+
+ public struct RECT
+ {
+ public int Left { get; set; }
+
+ public int Top { get; set; }
+
+ public int Right { get; set; }
+
+ public int Bottom { get; set; }
+
+ public Rectangle ToRectangle()
+ {
+ return Rectangle.FromLTRB(Left, Top, Right, Bottom);
+ }
+ }
+
+ public struct MSG
+ {
+ public IntPtr Hwnd { get; set; }
+
+ public int Message { get; set; }
+
+ public IntPtr WParam { get; set; }
+ public IntPtr LParam { get; set; }
+
+ public int Time { get; set; }
+
+ public int PtX { get; set; }
+
+ public int PtY { get; set; }
+ }
+
+ [ComImport]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ [Guid("cfac301a-fdd7-4e54-aa10-318ffa7f7bd2")]
+ public interface IPreviewHandler
+ {
+ void SetWindow(IntPtr hwnd, ref RECT rect);
+
+ void SetRect(ref RECT rect);
+
+ void DoPreview();
+
+ void Unload();
+
+ void SetFocus();
+
+ void QueryFocus(out IntPtr phwnd);
+
+ [PreserveSig]
+ uint TranslateAccelerator(ref MSG pmsg);
+ }
+
+ [ComImport]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ [Guid("cfac301a-fdd7-4e54-aa10-318ffa7f7bd2")]
+ public interface IInitializeWithStream
+ {
+ void Initialize(IStream pstream, uint grfMode);
+ }
+
+ [ComImport]
+ [Guid("cfac301a-fdd7-4e54-aa10-318ffa7f7bd2")]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IOleWindow
+ {
+ void GetWindow(out IntPtr phwnd);
+
+ void ContextSensitiveHelp([MarshalAs(UnmanagedType.Bool)] bool fEnterMode);
+ }
+
+ [ComImport]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ [Guid("fc4801a3-2ba9-11cf-a229-00aa003d7352")]
+ public interface IObjectWithSite
+ {
+ void SetSite([In, MarshalAs(UnmanagedType.IUnknown)] object pUnkSite);
+
+ void GetSite(ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppvSite);
+ }
+}
diff --git a/ProofOfConcept/Monaco/monacoPreview/PreviewWindow.xaml b/ProofOfConcept/Monaco/monacoPreview/PreviewWindow.xaml
new file mode 100644
index 000000000..12ee347c9
--- /dev/null
+++ b/ProofOfConcept/Monaco/monacoPreview/PreviewWindow.xaml
@@ -0,0 +1,21 @@
+