11using System ;
22using System . Collections . Generic ;
3- using System . IO ;
43using System . Linq ;
54using System . Reflection ;
65using System . Runtime . InteropServices ;
1312using Microsoft . VisualStudio . ComponentModelHost ;
1413using Microsoft . VisualStudio . Imaging ;
1514using Microsoft . VisualStudio . Shell ;
16- using Microsoft . VisualStudio . Shell . Interop ;
17- using Microsoft . Win32 ;
1815using CommunityVS = Community . VisualStudio . Toolkit . VS ;
1916using Constants = KS . RustAnalyzer . TestAdapter . Constants ;
2017
@@ -37,6 +34,7 @@ namespace KS.RustAnalyzer;
3734public sealed class RustAnalyzerPackage : ToolkitPackage
3835{
3936 private TL _tl ;
37+ private IRegistrySettingsService _regSettings ;
4038 private IPreReqsCheckService _preReqs ;
4139
4240 protected override async Task InitializeAsync ( CancellationToken cancellationToken , IProgress < ServiceProgressData > progress )
@@ -51,6 +49,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
5149 L = cmServiceProvider ? . GetService < ILogger > ( ) ,
5250 T = cmServiceProvider ? . GetService < ITelemetryService > ( ) ,
5351 } ;
52+ _regSettings = cmServiceProvider ? . GetService < IRegistrySettingsService > ( ) ;
5453 _preReqs = cmServiceProvider ? . GetService < IPreReqsCheckService > ( ) ;
5554 }
5655
@@ -60,7 +59,7 @@ protected override async Task OnAfterPackageLoadedAsync(CancellationToken cancel
6059
6160 await JoinableTaskFactory . SwitchToMainThreadAsync ( cancellationToken ) ;
6261
63- await ReleaseSummaryNotification . ShowAsync ( this , _tl ) ;
62+ await ReleaseSummaryNotification . ShowAsync ( _regSettings , _tl ) ;
6463 await SearchAndDisableIncompatibleExtensionsAsync ( ) ;
6564 await _preReqs . SatisfyAsync ( ) ;
6665 }
@@ -148,14 +147,13 @@ public static class ReleaseSummaryNotification
148147 private const string ActionContextGetHelp = "get_help" ;
149148 private const string ActionContextRateExtension = "rate_extension" ;
150149 private const string ActionContextTestExperienceDemo = "test_experience_demo" ;
151- private const string DismissedRegKeyName = "release_notes_dismissed" ;
152150
153- public static async Task ShowAsync ( IServiceProvider sp , TL tl )
151+ public static async Task ShowAsync ( IRegistrySettingsService regSettings , TL tl )
154152 {
155153 await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
156154
157155 tl . L . WriteLine ( "Attempting to show release notes..." ) ;
158- if ( HasBeenDismissedByUser ( sp ) )
156+ if ( regSettings . InfoBarDismissedByUser )
159157 {
160158 tl . L . WriteLine ( "... Not showing release notes as it has already been dismissed by the user." ) ;
161159 return ;
@@ -173,11 +171,11 @@ public static async Task ShowAsync(IServiceProvider sp, TL tl)
173171 image : KnownMonikers . StatusInformation ,
174172 isCloseButtonVisible : true ) ;
175173 var infoBar = await CommunityVS . InfoBar . CreateAsync ( model ) ;
176- infoBar . ActionItemClicked += ( s , ea ) => InfoBar_ActionItemClicked ( s , ea , sp , tl ) ;
174+ infoBar . ActionItemClicked += ( s , ea ) => InfoBar_ActionItemClicked ( s , ea , regSettings , tl ) ;
177175 await infoBar . TryShowInfoBarUIAsync ( ) ;
178176 }
179177
180- private static void InfoBar_ActionItemClicked ( object sender , InfoBarActionItemEventArgs e , IServiceProvider sp , TL tl )
178+ private static void InfoBar_ActionItemClicked ( object sender , InfoBarActionItemEventArgs e , IRegistrySettingsService regSettings , TL tl )
181179 {
182180 ThreadHelper . ThrowIfNotOnUIThread ( ) ;
183181
@@ -197,7 +195,7 @@ private static void InfoBar_ActionItemClicked(object sender, InfoBarActionItemEv
197195 break ;
198196
199197 case ActionContextDismiss :
200- MarkDismissedByUser ( sp ) ;
198+ regSettings . InfoBarDismissedByUser = true ;
201199 ( sender as InfoBar ) ? . Close ( ) ;
202200 break ;
203201
@@ -207,42 +205,6 @@ private static void InfoBar_ActionItemClicked(object sender, InfoBarActionItemEv
207205
208206 tl . T . TrackEvent ( "InfoBarAction" , ( "Context" , actionContext ) ) ;
209207 }
210-
211- private static void MarkDismissedByUser ( IServiceProvider sp )
212- {
213- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
214-
215- if ( GetPackageRegistryRoot ( sp , out string regRoot ) )
216- {
217- Registry . SetValue ( regRoot , DismissedRegKeyName , Vsix . Version ) ;
218- }
219- }
220-
221- private static bool HasBeenDismissedByUser ( IServiceProvider sp )
222- {
223- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
224-
225- if ( GetPackageRegistryRoot ( sp , out string regRoot ) )
226- {
227- return Registry . GetValue ( regRoot , DismissedRegKeyName , null ) ? . ToString ( ) == Vsix . Version ;
228- }
229-
230- return false ;
231- }
232-
233- private static bool GetPackageRegistryRoot ( IServiceProvider sp , out string packageRegistryRoot )
234- {
235- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
236-
237- packageRegistryRoot = null ;
238- if ( sp . GetService ( typeof ( SLocalRegistry ) ) is ILocalRegistry2 localReg && ErrorHandler . Succeeded ( localReg . GetLocalRegistryRoot ( out var localRegRoot ) ) )
239- {
240- packageRegistryRoot = Path . Combine ( "HKEY_CURRENT_USER" , localRegRoot , Vsix . Name ) ;
241- return true ;
242- }
243-
244- return false ;
245- }
246208 }
247209
248210 #endregion
0 commit comments