diff --git a/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs b/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs index bd76aacc0e..72584840c2 100644 --- a/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs +++ b/src/modules/previewpane/MonacoPreviewHandler/MonacoPreviewHandlerControl.cs @@ -212,6 +212,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco downloadLink.Top = TextRenderer.MeasureText(Resources.WebView2_Not_Installed_Message, errorMessage.Font).Height + 10; downloadLink.Width = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Width + 10; downloadLink.Height = TextRenderer.MeasureText(Resources.Download_WebView2, errorMessage.Font).Height; + downloadLink.ForeColor = Settings.TextColor; Controls.Add(downloadLink); } }); @@ -222,6 +223,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco Controls.Remove(_loadingBar); Controls.Remove(_loadingBackground); Label text = new Label(); + text.ForeColor = Settings.TextColor; text.Text = Resources.Exception_Occurred; text.Text += e.Message; text.Text += "\n" + e.Source; @@ -244,6 +246,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco Controls.Remove(_loadingBackground); Label errorMessage = new Label(); errorMessage.Text = Resources.Max_File_Size_Error.Replace("%1", (_settings.MaxFileSize / 1000).ToString(CultureInfo.CurrentCulture), StringComparison.InvariantCulture); + errorMessage.ForeColor = Settings.TextColor; errorMessage.Width = 500; errorMessage.Height = 50; Controls.Add(errorMessage); diff --git a/src/modules/previewpane/MonacoPreviewHandler/Settings.cs b/src/modules/previewpane/MonacoPreviewHandler/Settings.cs index e03cbcf409..6bc7a11e76 100644 --- a/src/modules/previewpane/MonacoPreviewHandler/Settings.cs +++ b/src/modules/previewpane/MonacoPreviewHandler/Settings.cs @@ -58,11 +58,24 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco } /// - /// Max file size for displaying (in bytes). + /// Gets Max file size for displaying (in bytes). /// - private readonly long _maxFileSize = 50000; - - public long MaxFileSize => _maxFileSize; + public double MaxFileSize + { + get + { + try + { + return moduleSettings.GetSettings(PowerPreviewSettings.ModuleName).Properties.MonacoPreviewMaxFileSize.Value * 1000; + } + catch (FileNotFoundException) + { + // Couldn't read the settings. + // Assume default of 50000. + return 50000; + } + } + } /// /// Gets the color of the window background. diff --git a/src/settings-ui/Settings.UI.Library/PowerPreviewProperties.cs b/src/settings-ui/Settings.UI.Library/PowerPreviewProperties.cs index eee0800e48..2b4d00b248 100644 --- a/src/settings-ui/Settings.UI.Library/PowerPreviewProperties.cs +++ b/src/settings-ui/Settings.UI.Library/PowerPreviewProperties.cs @@ -13,6 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library public class PowerPreviewProperties { public const string DefaultStlThumbnailColor = "#FFC924"; + public const int DefaultMonacoMaxFileSize = 50; private bool enableSvgPreview = true; @@ -116,6 +117,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library } } + [JsonPropertyName("monaco-previewer-max-file-size")] + public IntProperty MonacoPreviewMaxFileSize { get; set; } + private bool enablePdfPreview; [JsonPropertyName("pdf-previewer-toggle-setting")] @@ -207,6 +211,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library public PowerPreviewProperties() { StlThumbnailColor = new StringProperty(DefaultStlThumbnailColor); + MonacoPreviewMaxFileSize = new IntProperty(DefaultMonacoMaxFileSize); } public override string ToString() diff --git a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw index d8a07a7024..a08afd5429 100644 --- a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw @@ -2934,4 +2934,12 @@ Activate by holding the key for the character you want to add an accent to, then Update available + + Maximum file size to preview + Size refers to the disk space used by a file + + + The maximum size, in kilobytes, for files to be displayed. This is a safety mechanism to prevent loading large files into RAM. + "RAM" refers to random access memory; "size" refers to disk space; "bytes" refer to the measurement unit + \ No newline at end of file diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs index a6b5fcdab2..dfeddbc508 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerPreviewViewModel.cs @@ -98,6 +98,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels _monacoWrapText = Settings.Properties.EnableMonacoPreviewWordWrap; _monacoPreviewTryFormat = Settings.Properties.MonacoPreviewTryFormat; + _monacoMaxFileSize = Settings.Properties.MonacoPreviewMaxFileSize.Value; _pdfRenderEnabledGpoRuleConfiguration = GPOWrapper.GetConfiguredPdfPreviewEnabledValue(); if (_pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _pdfRenderEnabledGpoRuleConfiguration == GpoRuleConfigured.Enabled) @@ -175,6 +176,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels private bool _monacoRenderIsEnabled; private bool _monacoWrapText; private bool _monacoPreviewTryFormat; + private int _monacoMaxFileSize; private GpoRuleConfigured _pdfRenderEnabledGpoRuleConfiguration; private bool _pdfRenderEnabledStateIsGPOConfigured; @@ -353,6 +355,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels } } + public int MonacoPreviewMaxFileSize + { + get + { + return _monacoMaxFileSize; + } + + set + { + if (_monacoMaxFileSize != value) + { + _monacoMaxFileSize = value; + Settings.Properties.MonacoPreviewMaxFileSize.Value = value; + RaisePropertyChanged(); + } + } + } + public bool PDFRenderIsEnabled { get diff --git a/src/settings-ui/Settings.UI/Views/PowerPreviewPage.xaml b/src/settings-ui/Settings.UI/Views/PowerPreviewPage.xaml index 3df5647bfa..9d7ee0880a 100644 --- a/src/settings-ui/Settings.UI/Views/PowerPreviewPage.xaml +++ b/src/settings-ui/Settings.UI/Views/PowerPreviewPage.xaml @@ -78,6 +78,16 @@ IsChecked="{x:Bind ViewModel.MonacoPreviewTryFormat, Mode=TwoWay}" IsEnabled="{x:Bind ViewModel.MonacoRenderIsEnabled, Mode=OneWay}" /> + + +