From b2299d4f054512f3b28ccb330eb9260f8dc72fa6 Mon Sep 17 00:00:00 2001 From: DATBOI Date: Tue, 7 Feb 2023 20:07:16 -0600 Subject: [PATCH 1/3] Capturing user local path once on initialization & on ui thread (fixes #57) --- doki-theme-visualstudio/LocalAssetService.cs | 2 +- .../LocalStorageService.cs | 13 +++++----- doki-theme-visualstudio/TheDokiTheme.cs | 7 +++-- .../doki_theme_visualstudioPackage.cs | 26 +++++++++++-------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/doki-theme-visualstudio/LocalAssetService.cs b/doki-theme-visualstudio/LocalAssetService.cs index b22ce4f..dc9fa0d 100644 --- a/doki-theme-visualstudio/LocalAssetService.cs +++ b/doki-theme-visualstudio/LocalAssetService.cs @@ -28,7 +28,7 @@ private LocalAssetService(Dictionary assetChecks) { _instance ?? throw new Exception("Expected local storage to be initialized!"); - public static void Init(Package package) { + public static void Init() { _instance ??= new LocalAssetService(ReadAssetChecks()); } diff --git a/doki-theme-visualstudio/LocalStorageService.cs b/doki-theme-visualstudio/LocalStorageService.cs index 274dd8c..aed0b86 100644 --- a/doki-theme-visualstudio/LocalStorageService.cs +++ b/doki-theme-visualstudio/LocalStorageService.cs @@ -10,17 +10,17 @@ public class LocalStorageService { _instance ?? throw new Exception("Expected local storage to be initialized!"); public static void Init(Package package) { - _instance ??= new LocalStorageService(package); + _instance ??= new LocalStorageService(package.UserLocalDataPath); var assetsDirectory = _instance.GetAssetDirectory(); if (!Directory.Exists(assetsDirectory)) { Directory.CreateDirectory(assetsDirectory); } } - private readonly Package _package; + private readonly string _userLocalDataPath; - private LocalStorageService(Package package) { - _package = package; + private LocalStorageService(string userLocalDataPath) { + _userLocalDataPath = userLocalDataPath; } public static void CreateDirectories(string fullAssetPath) { @@ -31,11 +31,10 @@ public static void CreateDirectories(string fullAssetPath) { } public string GetAssetDirectory() { - var userLocalDataPath = _package.UserLocalDataPath; var assetsDirectory = - Path.Combine(userLocalDataPath.Substring( + Path.Combine(_userLocalDataPath.Substring( 0, - userLocalDataPath.LastIndexOf(Path.DirectorySeparatorChar) + _userLocalDataPath.LastIndexOf(Path.DirectorySeparatorChar) ), "dokiThemeAssets"); return assetsDirectory; } diff --git a/doki-theme-visualstudio/TheDokiTheme.cs b/doki-theme-visualstudio/TheDokiTheme.cs index 3bac29c..b7802a2 100644 --- a/doki-theme-visualstudio/TheDokiTheme.cs +++ b/doki-theme-visualstudio/TheDokiTheme.cs @@ -16,12 +16,15 @@ public static async Task InitializePluginAsync(AsyncPackage package, Cancellatio SettingsService.Init(package); ThemeManager.Init(package); - LocalStorageService.Init(package); // depends on local storage service - LocalAssetService.Init(package); + LocalAssetService.Init(); _isInitialized = true; PluginInitialized?.Invoke(null, "Dun!"); + } + + public static async Task InitializePlugin(AsyncPackage package, CancellationToken cancellationToken) { + LocalStorageService.Init(package); } } } diff --git a/doki-theme-visualstudio/doki_theme_visualstudioPackage.cs b/doki-theme-visualstudio/doki_theme_visualstudioPackage.cs index bb0d578..3352488 100644 --- a/doki-theme-visualstudio/doki_theme_visualstudioPackage.cs +++ b/doki-theme-visualstudio/doki_theme_visualstudioPackage.cs @@ -31,8 +31,8 @@ namespace doki_theme_visualstudio { [ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)] [ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] [Guid(PackageGuidString)] - [ProvideOptionPage(typeof(DokiThemeSettings), "Doki Theme Settings", - "General", 1000, 1001, false)] + [ProvideOptionPage(typeof(DokiThemeSettings), "Doki Theme Settings", + "General", 1000, 1001, false)] [ProvideMenuResource("Menus.ctmenu", 1)] public sealed class doki_theme_visualstudioPackage : AsyncPackage { /// @@ -49,17 +49,21 @@ public sealed class doki_theme_visualstudioPackage : AsyncPackage { /// A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down. /// A provider for progress updates. /// A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method. - protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) - { - await base.InitializeAsync(cancellationToken, progress); - // in background thread, can do things + protected override async Task InitializeAsync(CancellationToken cancellationToken, + IProgress progress) { + await base.InitializeAsync(cancellationToken, progress); + // When initialized asynchronously, the current thread may be a background thread at this point. + + // Do any initialization that requires the UI thread after switching to the UI thread. + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - await TheDokiTheme.InitializePluginAsync(this, cancellationToken); + await TheDokiTheme.InitializePlugin(this, cancellationToken); - - // When initialized asynchronously, the current thread may be a background thread at this point. - // Do any initialization that requires the UI thread after switching to the UI thread. - await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + await TaskScheduler.Default; + + // background thread again + + await TheDokiTheme.InitializePluginAsync(this, cancellationToken); } #endregion From 6bd73b11f2a94898c8abab43bf542c5ee0d6503c Mon Sep 17 00:00:00 2001 From: DATBOI Date: Tue, 7 Feb 2023 20:19:26 -0600 Subject: [PATCH 2/3] Allow users to ignore sticker scaling. --- README.md | 3 ++- doki-theme-visualstudio/DokiThemeSettings.cs | 12 ++++++++---- doki-theme-visualstudio/StickerAdornment.cs | 16 +++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b9601ea..9685550 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,8 @@ You can navigate to the settings here That's why I've allowed you to set your own custom sticker to be used for all doki themes. The value provided _must_ be an absolute path to the local file on your machine to be used. Feel free to use the `...` to pick a file. -**StickerRelativeSize** because I do not know the Visual Studio SDK very well, this is my solution to fixing issues with zoom scrolling. When the viewport size changes, the sticker would either grow or shrink relative to the viewport. This is the relative size the sticker should be relative to the current view port. 1 being the same size as the viewport and 0.01 being 1 percent the size of the current viewport. +**StickerRelativeSize** Value Range: `[-1.0, 1]` (eg: 0.5 for half size of viewport) because I do not know the Visual Studio SDK very well, this is my solution to fixing issues with zoom scrolling. When the viewport size changes, the sticker would either grow or shrink relative to the viewport. This is the relative size the sticker should be relative to the current view port. 1 being the same size as the viewport and 0.01 being 1 percent the size of the current viewport. +Set to -1 to allow the sticker to scale with the view port zoom size. **Note**: stickers go away if you use a non-Doki Theme. diff --git a/doki-theme-visualstudio/DokiThemeSettings.cs b/doki-theme-visualstudio/DokiThemeSettings.cs index 51cf07b..4727fc9 100644 --- a/doki-theme-visualstudio/DokiThemeSettings.cs +++ b/doki-theme-visualstudio/DokiThemeSettings.cs @@ -172,19 +172,23 @@ public bool DrawWallpaper { public double WallpaperOpacity { get { return _wallpaperOpacity; } set { - var usableOpacity = value < 0 ? -1 : Math.Min(value, 1); - _wallpaperOpacity = usableOpacity; + var usableOpacity = UsableValue(value); + _wallpaperOpacity = usableOpacity; } } + private static double UsableValue(double value) { + return value < 0 ? -1 : Math.Min(value, 1); + } + private double _StickerRelativeSize = 0.2; - [DescriptionAttribute("How big should the sticker be relative to your current viewport?")] + [DescriptionAttribute("How big should the sticker be relative to your current viewport? Set to -1.0 to follow scale of viewport")] [EditorAttribute(typeof(BrowseFile), typeof(UITypeEditor))] public double StickerRelativeSize { get { return _StickerRelativeSize; } - set { _StickerRelativeSize = value; } + set { _StickerRelativeSize = UsableValue(value); } } private BackgroundSize _wallpaperFill = BackgroundSize.Filled; diff --git a/doki-theme-visualstudio/StickerAdornment.cs b/doki-theme-visualstudio/StickerAdornment.cs index 5d3777d..29eca32 100644 --- a/doki-theme-visualstudio/StickerAdornment.cs +++ b/doki-theme-visualstudio/StickerAdornment.cs @@ -17,7 +17,7 @@ internal sealed class StickerAdornment { private bool _registeredLayoutListener; - private double _stickerSize = 0.2; + private double _stickerSize; public StickerAdornment(IWpfTextView view) { _view = view ?? throw new ArgumentNullException(nameof(view)); @@ -45,6 +45,7 @@ public StickerAdornment(IWpfTextView view) { } else { RemoveStickerStuff(); } + _stickerSize = service.StickerRelativeSize; }; @@ -147,12 +148,13 @@ private void DrawImage() { RemoveAdornment(); - - var aspectRatio = _image.Width / _image.Height; - var usableWidth = _view.ViewportWidth * _stickerSize; - var usableHeight = usableWidth * aspectRatio; - _image.Width = usableWidth; - _image.Height = usableHeight; + if (_stickerSize >= 0) { + var aspectRatio = _image.Width / _image.Height; + var usableWidth = _view.ViewportWidth * _stickerSize; + var usableHeight = usableWidth * aspectRatio; + _image.Width = usableWidth; + _image.Height = usableHeight; + } // place in lower right hand corner Canvas.SetLeft(_image, _view.ViewportRight - _image.ActualWidth); From 7fe6dc54950cd04b74b8aad05e9989b7fb761006 Mon Sep 17 00:00:00 2001 From: DATBOI Date: Wed, 8 Feb 2023 19:50:54 -0600 Subject: [PATCH 3/3] Updated changelog & bumped version to 88.1.4 --- CHANGELOG.md | 5 +++++ doki-theme-visualstudio/source.extension.vsixmanifest | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eabd871..76127e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog --- +# 88.3-1.0.4 [Perfomance Issue Fix] + +- Fixed an issue that causes the extension to make VS very slow/unresponsive. +- Allowed sticker **StickerRelativeSize** to be set to `-1` which disables the autoscaling and removes blurryness of the sticker (if present) + # 88.3-1.0.3 [Zoom Scroll Fix] - Added **StickerRelativeSize** options to the content settings. Which fixes the sticker's size in place while you zoom scroll. See documentation for more details. diff --git a/doki-theme-visualstudio/source.extension.vsixmanifest b/doki-theme-visualstudio/source.extension.vsixmanifest index a726c44..b418be9 100644 --- a/doki-theme-visualstudio/source.extension.vsixmanifest +++ b/doki-theme-visualstudio/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + Doki Theme Cute anime character themes! https://github.com/doki-theme/doki-theme-visualstudio#the-doki-theme-visual-studio