mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
Self-contained .NET (#22217)
* dotnet sc
* MD preview - C# app
- working self-contained
* Gcode preview - C# app
* DevFiles preview - C# app
* Fix passing path with spaces as cmd arg and monacocpp proj file
* Pdf preview - C# app
* Svg preview - C# app
* Fix comment
* Gcode thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Pdf thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Pdf thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Fix GcodeThumbnailProviderCpp.vcxproj
* Svg thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Fix Svg tests
* Thumbnail providers - installer
* Self-contained Hosts and FileLocksmith
* Fix hardcoded <RuntimeIdentifier>
* Remove unneeded files
* Try to fix Nuget in PR CI
* Prefix new dlls with PowerToys.
Sign new dlls and exes
* Add new .exe files to ProcessList
* ci: debug by listing all env vars
* ci: try setting variable in the right ci file
* Bring back hardcoded RuntimeIdentifier
* ci: Add comment and remove debug action
* Remove unneeded lib
* [WIP] Platform conditional dotnet files & hardlinks
* Cleanup
* Update expect.txt
* Test fix - ARM installer
* Fix uninstall bug
* Update docs
* Fix failing test
* Add dll details
* Minor cleanup
* Improve resizing
* Add some logs
* Test fix - release build
* Remove InvokeOnControlThread
* Test fix: logger initialization
* Fix arm64 installer
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
This commit is contained in:
@@ -133,14 +133,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
||||
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMarkdownPreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
||||
{
|
||||
// GPO is disabling this utility. Show an error message instead.
|
||||
InvokeOnControlThread(() =>
|
||||
{
|
||||
_infoBarDisplayed = true;
|
||||
_infoBar = GetTextBoxControl(Resources.GpoDisabledErrorText);
|
||||
Resize += FormResized;
|
||||
Controls.Add(_infoBar);
|
||||
base.DoPreview(dataSource);
|
||||
});
|
||||
_infoBarDisplayed = true;
|
||||
_infoBar = GetTextBoxControl(Resources.GpoDisabledErrorText);
|
||||
Resize += FormResized;
|
||||
Controls.Add(_infoBar);
|
||||
base.DoPreview(dataSource);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -153,7 +150,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
||||
{
|
||||
if (!(dataSource is string filePath))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(dataSource)} for {nameof(MarkdownPreviewHandler)} must be a string but was a '{typeof(T)}'");
|
||||
throw new ArgumentException($"{nameof(dataSource)} for {nameof(MarkdownPreviewHandlerControl)} must be a string but was a '{typeof(T)}'");
|
||||
}
|
||||
|
||||
string fileText = File.ReadAllText(filePath);
|
||||
@@ -174,80 +171,74 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
||||
Dock = DockStyle.Fill,
|
||||
};
|
||||
|
||||
InvokeOnControlThread(() =>
|
||||
{
|
||||
var webView2Options = new CoreWebView2EnvironmentOptions("--block-new-web-contents");
|
||||
ConfiguredTaskAwaitable<CoreWebView2Environment>.ConfiguredTaskAwaiter
|
||||
var webView2Options = new CoreWebView2EnvironmentOptions("--block-new-web-contents");
|
||||
ConfiguredTaskAwaitable<CoreWebView2Environment>.ConfiguredTaskAwaiter
|
||||
webView2EnvironmentAwaiter = CoreWebView2Environment
|
||||
.CreateAsync(userDataFolder: _webView2UserDataFolder, options: webView2Options)
|
||||
.ConfigureAwait(true).GetAwaiter();
|
||||
webView2EnvironmentAwaiter.OnCompleted(() =>
|
||||
webView2EnvironmentAwaiter.OnCompleted(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
InvokeOnControlThread(async () =>
|
||||
_webView2Environment = webView2EnvironmentAwaiter.GetResult();
|
||||
await _browser.EnsureCoreWebView2Async(_webView2Environment).ConfigureAwait(true);
|
||||
_browser.CoreWebView2.SetVirtualHostNameToFolderMapping(VirtualHostName, AssemblyDirectory, CoreWebView2HostResourceAccessKind.Deny);
|
||||
_browser.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
|
||||
_browser.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
|
||||
_browser.CoreWebView2.Settings.AreDevToolsEnabled = false;
|
||||
_browser.CoreWebView2.Settings.AreHostObjectsAllowed = false;
|
||||
_browser.CoreWebView2.Settings.IsGeneralAutofillEnabled = false;
|
||||
_browser.CoreWebView2.Settings.IsPasswordAutosaveEnabled = false;
|
||||
_browser.CoreWebView2.Settings.IsScriptEnabled = false;
|
||||
_browser.CoreWebView2.Settings.IsWebMessageEnabled = false;
|
||||
|
||||
// Don't load any resources.
|
||||
_browser.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All);
|
||||
_browser.CoreWebView2.WebResourceRequested += (object sender, CoreWebView2WebResourceRequestedEventArgs e) =>
|
||||
{
|
||||
try
|
||||
// Show local file we've saved with the markdown contents. Block all else.
|
||||
if (new Uri(e.Request.Uri) != _localFileURI)
|
||||
{
|
||||
_webView2Environment = webView2EnvironmentAwaiter.GetResult();
|
||||
await _browser.EnsureCoreWebView2Async(_webView2Environment).ConfigureAwait(true);
|
||||
_browser.CoreWebView2.SetVirtualHostNameToFolderMapping(VirtualHostName, AssemblyDirectory, CoreWebView2HostResourceAccessKind.Deny);
|
||||
_browser.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
|
||||
_browser.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
|
||||
_browser.CoreWebView2.Settings.AreDevToolsEnabled = false;
|
||||
_browser.CoreWebView2.Settings.AreHostObjectsAllowed = false;
|
||||
_browser.CoreWebView2.Settings.IsGeneralAutofillEnabled = false;
|
||||
_browser.CoreWebView2.Settings.IsPasswordAutosaveEnabled = false;
|
||||
_browser.CoreWebView2.Settings.IsScriptEnabled = false;
|
||||
_browser.CoreWebView2.Settings.IsWebMessageEnabled = false;
|
||||
|
||||
// Don't load any resources.
|
||||
_browser.CoreWebView2.AddWebResourceRequestedFilter("*", CoreWebView2WebResourceContext.All);
|
||||
_browser.CoreWebView2.WebResourceRequested += (object sender, CoreWebView2WebResourceRequestedEventArgs e) =>
|
||||
{
|
||||
// Show local file we've saved with the markdown contents. Block all else.
|
||||
if (new Uri(e.Request.Uri) != _localFileURI)
|
||||
{
|
||||
e.Response = _browser.CoreWebView2.Environment.CreateWebResourceResponse(null, 403, "Forbidden", null);
|
||||
}
|
||||
};
|
||||
|
||||
// WebView2.NavigateToString() limitation
|
||||
// See https://learn.microsoft.com/dotnet/api/microsoft.web.webview2.core.corewebview2.navigatetostring?view=webview2-dotnet-1.0.864.35#remarks
|
||||
// While testing the limit, it turned out it is ~1.5MB, so to be on a safe side we go for 1.5m bytes
|
||||
if (markdownHTML.Length > 1_500_000)
|
||||
{
|
||||
string filename = _webView2UserDataFolder + "\\" + Guid.NewGuid().ToString() + ".html";
|
||||
File.WriteAllText(filename, markdownHTML);
|
||||
_localFileURI = new Uri(filename);
|
||||
_browser.Source = _localFileURI;
|
||||
}
|
||||
else
|
||||
{
|
||||
_browser.NavigateToString(markdownHTML);
|
||||
}
|
||||
|
||||
Controls.Add(_browser);
|
||||
|
||||
_browser.NavigationStarting += async (object sender, CoreWebView2NavigationStartingEventArgs args) =>
|
||||
{
|
||||
if (args.Uri != null && args.Uri != _localFileURI?.ToString() && args.IsUserInitiated)
|
||||
{
|
||||
args.Cancel = true;
|
||||
await Launcher.LaunchUriAsync(new Uri(args.Uri));
|
||||
}
|
||||
};
|
||||
|
||||
if (_infoBarDisplayed)
|
||||
{
|
||||
_infoBar = GetTextBoxControl(Resources.BlockedImageInfoText);
|
||||
Resize += FormResized;
|
||||
Controls.Add(_infoBar);
|
||||
}
|
||||
e.Response = _browser.CoreWebView2.Environment.CreateWebResourceResponse(null, 403, "Forbidden", null);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
};
|
||||
|
||||
// WebView2.NavigateToString() limitation
|
||||
// See https://learn.microsoft.com/dotnet/api/microsoft.web.webview2.core.corewebview2.navigatetostring?view=webview2-dotnet-1.0.864.35#remarks
|
||||
// While testing the limit, it turned out it is ~1.5MB, so to be on a safe side we go for 1.5m bytes
|
||||
if (markdownHTML.Length > 1_500_000)
|
||||
{
|
||||
string filename = _webView2UserDataFolder + "\\" + Guid.NewGuid().ToString() + ".html";
|
||||
File.WriteAllText(filename, markdownHTML);
|
||||
_localFileURI = new Uri(filename);
|
||||
_browser.Source = _localFileURI;
|
||||
}
|
||||
else
|
||||
{
|
||||
_browser.NavigateToString(markdownHTML);
|
||||
}
|
||||
|
||||
Controls.Add(_browser);
|
||||
|
||||
_browser.NavigationStarting += async (object sender, CoreWebView2NavigationStartingEventArgs args) =>
|
||||
{
|
||||
if (args.Uri != null && args.Uri != _localFileURI?.ToString() && args.IsUserInitiated)
|
||||
{
|
||||
args.Cancel = true;
|
||||
await Launcher.LaunchUriAsync(new Uri(args.Uri));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (_infoBarDisplayed)
|
||||
{
|
||||
_infoBar = GetTextBoxControl(Resources.BlockedImageInfoText);
|
||||
Resize += FormResized;
|
||||
Controls.Add(_infoBar);
|
||||
}
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewed());
|
||||
@@ -256,14 +247,11 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new MarkdownFilePreviewError { Message = ex.Message });
|
||||
|
||||
InvokeOnControlThread(() =>
|
||||
{
|
||||
Controls.Clear();
|
||||
_infoBarDisplayed = true;
|
||||
_infoBar = GetTextBoxControl(Resources.MarkdownNotPreviewedError);
|
||||
Resize += FormResized;
|
||||
Controls.Add(_infoBar);
|
||||
});
|
||||
Controls.Clear();
|
||||
_infoBarDisplayed = true;
|
||||
_infoBar = GetTextBoxControl(Resources.MarkdownNotPreviewedError);
|
||||
Resize += FormResized;
|
||||
Controls.Add(_infoBar);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user