Skip to content

Commit 977c233

Browse files
authored
Merge pull request #58 from doki-theme/perfFix
Performance Issue Fix
2 parents 872a1cc + 7fe6dc5 commit 977c233

9 files changed

Lines changed: 52 additions & 34 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
---
33

4+
# 88.3-1.0.4 [Perfomance Issue Fix]
5+
6+
- Fixed an issue that causes the extension to make VS very slow/unresponsive.
7+
- Allowed sticker **StickerRelativeSize** to be set to `-1` which disables the autoscaling and removes blurryness of the sticker (if present)
8+
49
# 88.3-1.0.3 [Zoom Scroll Fix]
510

611
- Added **StickerRelativeSize** options to the content settings. Which fixes the sticker's size in place while you zoom scroll. See documentation for more details.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ You can navigate to the settings here
7777
That's why I've allowed you to set your own custom sticker to be used for all doki themes.
7878
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.
7979

80-
**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.
80+
**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.
81+
Set to -1 to allow the sticker to scale with the view port zoom size.
8182

8283
**Note**: stickers go away if you use a non-Doki Theme.
8384

doki-theme-visualstudio/DokiThemeSettings.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,23 @@ public bool DrawWallpaper {
172172
public double WallpaperOpacity {
173173
get { return _wallpaperOpacity; }
174174
set {
175-
var usableOpacity = value < 0 ? -1 : Math.Min(value, 1);
176-
_wallpaperOpacity = usableOpacity;
175+
var usableOpacity = UsableValue(value);
176+
_wallpaperOpacity = usableOpacity;
177177
}
178178
}
179179

180+
private static double UsableValue(double value) {
181+
return value < 0 ? -1 : Math.Min(value, 1);
182+
}
183+
180184
private double _StickerRelativeSize = 0.2;
181185

182-
[DescriptionAttribute("How big should the sticker be relative to your current viewport?")]
186+
[DescriptionAttribute("How big should the sticker be relative to your current viewport? Set to -1.0 to follow scale of viewport")]
183187
[EditorAttribute(typeof(BrowseFile), typeof(UITypeEditor))]
184188
public double StickerRelativeSize
185189
{
186190
get { return _StickerRelativeSize; }
187-
set { _StickerRelativeSize = value; }
191+
set { _StickerRelativeSize = UsableValue(value); }
188192
}
189193

190194
private BackgroundSize _wallpaperFill = BackgroundSize.Filled;

doki-theme-visualstudio/LocalAssetService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private LocalAssetService(Dictionary<string, DateTime> assetChecks) {
2828
_instance ?? throw new Exception("Expected local storage to be initialized!");
2929

3030

31-
public static void Init(Package package) {
31+
public static void Init() {
3232
_instance ??= new LocalAssetService(ReadAssetChecks());
3333
}
3434

doki-theme-visualstudio/LocalStorageService.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ public class LocalStorageService {
1010
_instance ?? throw new Exception("Expected local storage to be initialized!");
1111

1212
public static void Init(Package package) {
13-
_instance ??= new LocalStorageService(package);
13+
_instance ??= new LocalStorageService(package.UserLocalDataPath);
1414
var assetsDirectory = _instance.GetAssetDirectory();
1515
if (!Directory.Exists(assetsDirectory)) {
1616
Directory.CreateDirectory(assetsDirectory);
1717
}
1818
}
1919

20-
private readonly Package _package;
20+
private readonly string _userLocalDataPath;
2121

22-
private LocalStorageService(Package package) {
23-
_package = package;
22+
private LocalStorageService(string userLocalDataPath) {
23+
_userLocalDataPath = userLocalDataPath;
2424
}
2525

2626
public static void CreateDirectories(string fullAssetPath) {
@@ -31,11 +31,10 @@ public static void CreateDirectories(string fullAssetPath) {
3131
}
3232

3333
public string GetAssetDirectory() {
34-
var userLocalDataPath = _package.UserLocalDataPath;
3534
var assetsDirectory =
36-
Path.Combine(userLocalDataPath.Substring(
35+
Path.Combine(_userLocalDataPath.Substring(
3736
0,
38-
userLocalDataPath.LastIndexOf(Path.DirectorySeparatorChar)
37+
_userLocalDataPath.LastIndexOf(Path.DirectorySeparatorChar)
3938
), "dokiThemeAssets");
4039
return assetsDirectory;
4140
}

doki-theme-visualstudio/StickerAdornment.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal sealed class StickerAdornment {
1717

1818
private bool _registeredLayoutListener;
1919

20-
private double _stickerSize = 0.2;
20+
private double _stickerSize;
2121

2222
public StickerAdornment(IWpfTextView view) {
2323
_view = view ?? throw new ArgumentNullException(nameof(view));
@@ -45,6 +45,7 @@ public StickerAdornment(IWpfTextView view) {
4545
} else {
4646
RemoveStickerStuff();
4747
}
48+
4849
_stickerSize = service.StickerRelativeSize;
4950
};
5051

@@ -147,12 +148,13 @@ private void DrawImage() {
147148

148149
RemoveAdornment();
149150

150-
151-
var aspectRatio = _image.Width / _image.Height;
152-
var usableWidth = _view.ViewportWidth * _stickerSize;
153-
var usableHeight = usableWidth * aspectRatio;
154-
_image.Width = usableWidth;
155-
_image.Height = usableHeight;
151+
if (_stickerSize >= 0) {
152+
var aspectRatio = _image.Width / _image.Height;
153+
var usableWidth = _view.ViewportWidth * _stickerSize;
154+
var usableHeight = usableWidth * aspectRatio;
155+
_image.Width = usableWidth;
156+
_image.Height = usableHeight;
157+
}
156158

157159
// place in lower right hand corner
158160
Canvas.SetLeft(_image, _view.ViewportRight - _image.ActualWidth);

doki-theme-visualstudio/TheDokiTheme.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ public static async Task InitializePluginAsync(AsyncPackage package, Cancellatio
1616

1717
SettingsService.Init(package);
1818
ThemeManager.Init(package);
19-
LocalStorageService.Init(package);
2019

2120
// depends on local storage service
22-
LocalAssetService.Init(package);
21+
LocalAssetService.Init();
2322
_isInitialized = true;
2423
PluginInitialized?.Invoke(null, "Dun!");
24+
}
25+
26+
public static async Task InitializePlugin(AsyncPackage package, CancellationToken cancellationToken) {
27+
LocalStorageService.Init(package);
2528
}
2629
}
2730
}

doki-theme-visualstudio/doki_theme_visualstudioPackage.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace doki_theme_visualstudio {
3131
[ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
3232
[ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
3333
[Guid(PackageGuidString)]
34-
[ProvideOptionPage(typeof(DokiThemeSettings), "Doki Theme Settings",
35-
"General", 1000, 1001, false)]
34+
[ProvideOptionPage(typeof(DokiThemeSettings), "Doki Theme Settings",
35+
"General", 1000, 1001, false)]
3636
[ProvideMenuResource("Menus.ctmenu", 1)]
3737
public sealed class doki_theme_visualstudioPackage : AsyncPackage {
3838
/// <summary>
@@ -49,17 +49,21 @@ public sealed class doki_theme_visualstudioPackage : AsyncPackage {
4949
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
5050
/// <param name="progress">A provider for progress updates.</param>
5151
/// <returns>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.</returns>
52-
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
53-
{
54-
await base.InitializeAsync(cancellationToken, progress);
55-
// in background thread, can do things
52+
protected override async Task InitializeAsync(CancellationToken cancellationToken,
53+
IProgress<ServiceProgressData> progress) {
54+
await base.InitializeAsync(cancellationToken, progress);
55+
// When initialized asynchronously, the current thread may be a background thread at this point.
56+
57+
// Do any initialization that requires the UI thread after switching to the UI thread.
58+
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
5659

57-
await TheDokiTheme.InitializePluginAsync(this, cancellationToken);
60+
await TheDokiTheme.InitializePlugin(this, cancellationToken);
5861

59-
60-
// When initialized asynchronously, the current thread may be a background thread at this point.
61-
// Do any initialization that requires the UI thread after switching to the UI thread.
62-
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
62+
await TaskScheduler.Default;
63+
64+
// background thread again
65+
66+
await TheDokiTheme.InitializePluginAsync(this, cancellationToken);
6367
}
6468

6569
#endregion

doki-theme-visualstudio/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="doki_theme_visualstudio.59d36e38-60e0-4571-9901-7971ec61b303" Version="88.1.3" Language="en-US" Publisher="Unthrottled" />
4+
<Identity Id="doki_theme_visualstudio.59d36e38-60e0-4571-9901-7971ec61b303" Version="88.1.4" Language="en-US" Publisher="Unthrottled" />
55
<DisplayName>Doki Theme</DisplayName>
66
<Description xml:space="preserve">Cute anime character themes!</Description>
77
<MoreInfo>https://github.com/doki-theme/doki-theme-visualstudio#the-doki-theme-visual-studio</MoreInfo>

0 commit comments

Comments
 (0)