|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using KS.RustAnalyzer; |
| 4 | +using KS.RustAnalyzer.TestAdapter.Common; |
| 5 | +using Microsoft.VisualStudio.Imaging; |
| 6 | +using Microsoft.VisualStudio.Shell; |
| 7 | +using Microsoft.VisualStudio.Shell.Interop; |
| 8 | +using CommunityVS = Community.VisualStudio.Toolkit.VS; |
| 9 | + |
| 10 | +public static class RlsUpdatedNotification |
| 11 | +{ |
| 12 | + public const string RLSUPDATEDENVVARNAME = "RA.VS_RLS_UPDATED"; |
| 13 | + |
| 14 | + private static int _counter = 0; |
| 15 | + |
| 16 | + public static bool Enabled |
| 17 | + { |
| 18 | + private get |
| 19 | + { |
| 20 | + return Environment.GetEnvironmentVariable(RLSUPDATEDENVVARNAME, EnvironmentVariableTarget.Process).IsNullOrEmpty(); |
| 21 | + } |
| 22 | + |
| 23 | + set |
| 24 | + { |
| 25 | + Environment.SetEnvironmentVariable(RLSUPDATEDENVVARNAME, true.ToString(), EnvironmentVariableTarget.Process); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + public static async Task ShowAsync() |
| 30 | + { |
| 31 | + if (Enabled) |
| 32 | + { |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + if (IsTimeToShowAgain()) |
| 37 | + { |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); |
| 42 | + |
| 43 | + var model = new InfoBarModel( |
| 44 | + textSpans: new[] { new InfoBarTextSpan($"{Vsix.Name}: Rust Langugage Server was updated in the background. Restart VS to start using the new version. Using the old version may lead to degraded editor experience."), }, |
| 45 | + Array.Empty<IVsInfoBarActionItem>(), |
| 46 | + image: KnownMonikers.StatusWarning, |
| 47 | + isCloseButtonVisible: true); |
| 48 | + var infoBar = await CommunityVS.InfoBar.CreateAsync(model); |
| 49 | + await infoBar.TryShowInfoBarUIAsync(); |
| 50 | + } |
| 51 | + |
| 52 | + private static bool IsTimeToShowAgain() |
| 53 | + { |
| 54 | + return _counter++ % 10 != 0; |
| 55 | + } |
| 56 | +} |
0 commit comments