Skip to content

Commit

Permalink
Merge pull request #58 from doki-theme/perfFix
Browse files Browse the repository at this point in the history
Performance Issue Fix
  • Loading branch information
Unthrottled authored Feb 9, 2023
2 parents 872a1cc + 7fe6dc5 commit 977c233
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 34 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 8 additions & 4 deletions doki-theme-visualstudio/DokiThemeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion doki-theme-visualstudio/LocalAssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private LocalAssetService(Dictionary<string, DateTime> 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());
}

Expand Down
13 changes: 6 additions & 7 deletions doki-theme-visualstudio/LocalStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
16 changes: 9 additions & 7 deletions doki-theme-visualstudio/StickerAdornment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -45,6 +45,7 @@ public StickerAdornment(IWpfTextView view) {
} else {
RemoveStickerStuff();
}

_stickerSize = service.StickerRelativeSize;
};

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions doki-theme-visualstudio/TheDokiTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
26 changes: 15 additions & 11 deletions doki-theme-visualstudio/doki_theme_visualstudioPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/// <summary>
Expand All @@ -49,17 +49,21 @@ public sealed class doki_theme_visualstudioPackage : AsyncPackage {
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <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>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
// in background thread, can do things
protected override async Task InitializeAsync(CancellationToken cancellationToken,
IProgress<ServiceProgressData> 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
Expand Down
2 changes: 1 addition & 1 deletion doki-theme-visualstudio/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<Metadata>
<Identity Id="doki_theme_visualstudio.59d36e38-60e0-4571-9901-7971ec61b303" Version="88.1.3" Language="en-US" Publisher="Unthrottled" />
<Identity Id="doki_theme_visualstudio.59d36e38-60e0-4571-9901-7971ec61b303" Version="88.1.4" Language="en-US" Publisher="Unthrottled" />
<DisplayName>Doki Theme</DisplayName>
<Description xml:space="preserve">Cute anime character themes!</Description>
<MoreInfo>https://github.com/doki-theme/doki-theme-visualstudio#the-doki-theme-visual-studio</MoreInfo>
Expand Down

0 comments on commit 977c233

Please sign in to comment.