-
Notifications
You must be signed in to change notification settings - Fork 139
Notification on outdated Rider package #2244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fdcab67
notification on outdated Rider package
van800 f4bef70
simplify
van800 774ee8e
Merge remote-tracking branch 'origin/net221' into net221-notification…
van800 3dd2fe7
switch to UserNotifications
van800 9b0d9f1
Merge branch 'net221' into net221-notification-package
van800 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
...per-unity/src/Unity.Rider/UnityEditorIntegration/RiderPackageUpdateAvailabilityChecker.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using JetBrains.Application.Notifications; | ||
using JetBrains.Application.Settings; | ||
using JetBrains.Application.Threading; | ||
using JetBrains.Collections.Viewable; | ||
using JetBrains.DataFlow; | ||
using JetBrains.Lifetimes; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ProjectModel.DataContext; | ||
using JetBrains.ReSharper.Plugins.Unity.Core.Application.Settings; | ||
using JetBrains.ReSharper.Plugins.Unity.Core.ProjectModel; | ||
using JetBrains.ReSharper.Plugins.Unity.Rider.Protocol; | ||
using JetBrains.ReSharper.Plugins.Unity.UnityEditorIntegration; | ||
using JetBrains.ReSharper.Plugins.Unity.UnityEditorIntegration.Packages; | ||
using JetBrains.ReSharper.Psi.Util; | ||
using JetBrains.Util; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.Rider.UnityEditorIntegration | ||
{ | ||
[SolutionComponent] | ||
public class RiderPackageUpdateAvailabilityChecker | ||
{ | ||
private readonly ILogger myLogger; | ||
private readonly ISolution mySolution; | ||
private readonly IShellLocks myShellLocks; | ||
private readonly PackageManager myPackageManager; | ||
private readonly UnityVersion myUnityVersion; | ||
private readonly ISettingsStore mySettingsStore; | ||
private readonly BackendUnityHost myBackendUnityHost; | ||
private readonly UserNotifications myUserNotifications; | ||
private readonly JetHashSet<VirtualFileSystemPath> myNotificationShown; | ||
private readonly IContextBoundSettingsStoreLive myBoundSettingsStore; | ||
private string packageId = "com.unity.ide.rider"; | ||
private Version leastRiderPackageVersion = new Version(3, 0, 9); | ||
|
||
public RiderPackageUpdateAvailabilityChecker( | ||
Lifetime lifetime, | ||
ILogger logger, | ||
ISolution solution, | ||
IShellLocks shellLocks, | ||
PackageManager packageManager, | ||
UnitySolutionTracker unitySolutionTracker, | ||
UnityVersion unityVersion, | ||
IApplicationWideContextBoundSettingStore applicationWideContextBoundSettingStore, | ||
ISettingsStore settingsStore, | ||
BackendUnityHost backendUnityHost, | ||
UserNotifications userNotifications | ||
) | ||
{ | ||
myLogger = logger; | ||
mySolution = solution; | ||
myShellLocks = shellLocks; | ||
myPackageManager = packageManager; | ||
myUnityVersion = unityVersion; | ||
mySettingsStore = settingsStore; | ||
myBackendUnityHost = backendUnityHost; | ||
myUserNotifications = userNotifications; | ||
myNotificationShown = new JetHashSet<VirtualFileSystemPath>(); | ||
myBoundSettingsStore = applicationWideContextBoundSettingStore.BoundSettingsStore; | ||
unitySolutionTracker.IsUnityGeneratedProject.WhenTrue(lifetime, lt => | ||
{ | ||
ShowNotificationIfNeeded(lt, leastRiderPackageVersion); | ||
BindToInstallationSettingChange(lt, leastRiderPackageVersion); | ||
BindToProtocol(lt); | ||
}); | ||
} | ||
|
||
private void BindToProtocol(Lifetime lt) | ||
{ | ||
myBackendUnityHost.BackendUnityModel.ViewNotNull(lt, (l, model) => | ||
{ | ||
model.RiderPackagePotentialUpdateVersion.Advise(l, result => | ||
{ | ||
if (!string.IsNullOrEmpty(result) && Version.TryParse(result, out var resultVersion)) | ||
{ | ||
ShowNotificationIfNeeded(l, resultVersion); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
private void BindToInstallationSettingChange(Lifetime lifetime, Version version) | ||
{ | ||
var entry = myBoundSettingsStore.Schema.GetScalarEntry((UnitySettings s) => | ||
s.AllowRiderUpdateNotifications); | ||
myBoundSettingsStore.GetValueProperty<bool>(lifetime, entry, null).Change.Advise_NoAcknowledgement(lifetime, | ||
args => | ||
{ | ||
if (!args.GetNewOrNull()) return; | ||
ShowNotificationIfNeeded(lifetime, version); | ||
}); | ||
} | ||
|
||
private void ShowNotificationIfNeeded(Lifetime lifetime, Version expectedVersion) | ||
{ | ||
if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.AllowRiderUpdateNotifications)) | ||
return; | ||
|
||
myPackageManager.IsInitialUpdateFinished.WhenTrue(lifetime, lt => | ||
{ | ||
myUnityVersion.ActualVersionForSolution.AdviseNotNull(lt, version => | ||
{ | ||
if (myNotificationShown.Contains(mySolution.SolutionFilePath)) return; | ||
|
||
// Version before 2019.2 doesn't have Rider package | ||
// 2019.2.0 - 2019.2.5 : version 1.2.1 is the last one | ||
// 2019.2.6 - present : see: leastRiderPackageVersion | ||
if (version < new Version(2019, 2, 6)) return; | ||
|
||
var package = myPackageManager.GetPackageById(packageId); | ||
|
||
if (package == null) | ||
{ | ||
myNotificationShown.Add(mySolution.SolutionFilePath); | ||
myLogger.Info($"{packageId} is missing."); | ||
myShellLocks.ExecuteOrQueueEx(lt, | ||
"RiderPackageUpdateAvailabilityChecker.ShowNotificationIfNeeded", | ||
() => | ||
{ | ||
myUserNotifications.CreateNotification(lt, NotificationSeverity.WARNING, | ||
"JetBrains Rider package in Unity is missing.", | ||
"Make sure JetBrains Rider package is installed in Unity Package Manager."); | ||
}); | ||
} | ||
else if (package.Source == PackageSource.Registry && | ||
new Version(package.PackageDetails.Version) < expectedVersion) | ||
{ | ||
var notificationLifetime = lt.CreateNested(); | ||
myNotificationShown.Add(mySolution.SolutionFilePath); | ||
myLogger.Info($"{packageId} {package.PackageDetails.Version} is older then expected."); | ||
|
||
myShellLocks.ExecuteOrQueueEx(lt, | ||
"RiderPackageUpdateAvailabilityChecker.ShowNotificationIfNeeded", | ||
() => myUserNotifications.CreateNotification(notificationLifetime.Lifetime, | ||
NotificationSeverity.INFO, | ||
"Update available - JetBrains Rider package.", | ||
"Check for JetBrains Rider package updates in Unity Package Manager.", | ||
additionalCommands: new[] | ||
{ | ||
new UserNotificationCommand("Never show for this solution", () => | ||
{ | ||
mySettingsStore.BindToContextTransient( | ||
ContextRange.ManuallyRestrictWritesToOneContext( | ||
mySolution.ToDataContext())) | ||
.SetValue((UnitySettings key) => key.AllowRiderUpdateNotifications, false); | ||
notificationLifetime.Terminate(); | ||
}) | ||
})); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
unity/EditorPlugin/AfterUnity56/Packages/Initialization.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#if UNITY_2019_2 | ||
using System.Linq; | ||
using JetBrains.Diagnostics; | ||
using JetBrains.Rd.Base; | ||
using UnityEditor; | ||
using UnityEditor.PackageManager; | ||
using UnityEditor.PackageManager.Requests; | ||
#endif | ||
|
||
namespace JetBrains.Rider.Unity.Editor.AfterUnity56.Packages | ||
{ | ||
public static class Initialization | ||
{ | ||
#if UNITY_2019_2 | ||
private static string packageId = "com.unity.ide.rider"; | ||
private static readonly ILog ourLogger = Log.GetLog("Packages.Initialization"); | ||
private static SearchRequest ourRequest; | ||
#endif | ||
public static void OnModelInitializationHandler(UnityModelAndLifetime modelAndLifetime) | ||
{ | ||
#if UNITY_2019_2 | ||
ourRequest = Client.Search(packageId); | ||
modelAndLifetime.Lifetime.OnTermination(() => { ourRequest = null; }); | ||
EditorApplication.update += () => Progress(modelAndLifetime); | ||
#endif | ||
} | ||
#if UNITY_2019_2 | ||
static void Progress(UnityModelAndLifetime modelAndLifetime) | ||
{ | ||
if (ourRequest == null) | ||
{ | ||
EditorApplication.update -= () => Progress(modelAndLifetime); | ||
return; | ||
} | ||
|
||
if (!ourRequest.IsCompleted) return; | ||
if (ourRequest.Status == StatusCode.Success) | ||
{ | ||
var latestCompatible = ourRequest.Result.FirstOrDefault()?.versions.latestCompatible; | ||
if (latestCompatible != null) | ||
{ | ||
ourLogger.Info("Found: " + latestCompatible); | ||
modelAndLifetime.Model.RiderPackagePotentialUpdateVersion.Set(latestCompatible); | ||
} | ||
} | ||
else if (ourRequest.Status >= StatusCode.Failure) | ||
{ | ||
ourLogger.Error(ourRequest.Error.message); | ||
} | ||
|
||
EditorApplication.update -= () => Progress(modelAndLifetime); | ||
} | ||
#endif | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.