Skip to content
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

[SDK-563] Add breaking change dialog #136

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Editor/Module Management/ModuleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ private static void DisplayUpdateDialog(string packageName, Version currentVersi
{
// Update
case 0:
packageUrl += "#v" + latestVersion;
UpdateModule(packageName, packageUrl, currentVersion, latestVersion);
CheckIfMajorRelease(packageName, currentVersion, latestVersion, packageUrl);
break;
// Cancel
case 1:
Expand All @@ -161,6 +160,23 @@ private static void DisplayUpdateDialog(string packageName, Version currentVersi
}
}

private static void CheckIfMajorRelease(string packageName, Version currentVersion, Version latestVersion,
string packageUrl)
{
if (latestVersion.Major > currentVersion.Major)
{
BreakingChangeDialog.ShowDialog(() =>
{
UpdateModule(packageName, packageUrl, currentVersion, latestVersion);
});

}
else
{
UpdateModule(packageName, packageUrl, currentVersion, latestVersion);
}
}

/// <summary>
/// Update the specified module by removing the current version and then adding the specified version.
/// </summary>
Expand All @@ -170,6 +186,7 @@ private static void DisplayUpdateDialog(string packageName, Version currentVersi
/// <param name="latest">The new version of the package.</param>
private static void UpdateModule(string name, string url, Version current, Version latest)
{
url += "#v" + latest;
CleanRedundantAvatarLoader();
RemoveRequest removeRequest = Client.Remove(name);
while (!removeRequest.IsCompleted) Thread.Sleep(MILLISECONDS_TIMEOUT);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions Editor/UI/BreakingChangeDialog/BreakingChangeDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace ReadyPlayerMe.Core.Editor
{
public class BreakingChangeDialog : EditorWindow
{
private const string MIGRATION_GUIDE_URL = "https://docs.readyplayer.me/ready-player-me/integration-guides/unity/troubleshooting/updating-from-earlier-versions";
private const string TITLE = "Update Packages";

[SerializeField] private VisualTreeAsset visualTreeAsset;

private static Action updateClicked;

public static void ShowDialog(Action onUpdate)
{
updateClicked = onUpdate;

var window = GetWindow<BreakingChangeDialog>();
window.titleContent = new GUIContent(TITLE);
window.minSize = new Vector2(500, 140);
window.maxSize = new Vector2(500, 140);
window.ShowModalUtility();
}

public void CreateGUI()
{
visualTreeAsset.CloneTree(rootVisualElement);

var migrationLink = rootVisualElement.Q<Label>("MigrationLink");
migrationLink.RegisterCallback<MouseUpEvent>(x =>
{
Application.OpenURL(MIGRATION_GUIDE_URL);
});

rootVisualElement.Q<Button>("UpdateButton").clicked += () =>
{
updateClicked?.Invoke();
Close();
};

rootVisualElement.Q<Button>("CancelButton").clicked += Close;
}
}
}
14 changes: 14 additions & 0 deletions Editor/UI/BreakingChangeDialog/BreakingChangeDialog.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Editor/UI/BreakingChangeDialog/BreakingChangeDialog.uxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<Style src="../EditorWindows/CommonStyle.uss" />
<ui:VisualElement style="flex-direction: row; align-items: stretch; justify-content: flex-start; margin-left: 20px; margin-right: 20px; margin-top: 20px; margin-bottom: 20px; flex-shrink: 0;">
<ui:VisualElement name="IconContainer" style="width: 60px; height: 60px; flex-direction: row; align-items: center; justify-content: center; background-color: rgb(0, 0, 0);">
<ui:VisualElement name="Icon" style="background-image: resource(&apos;rpm_logo&apos;); width: 50px; height: 50px; flex-direction: row; flex-shrink: 0; -unity-background-scale-mode: scale-to-fit; background-color: rgba(0, 0, 0, 0);" />
</ui:VisualElement>
<ui:VisualElement name="Description" style="align-items: flex-start; justify-content: center; margin-left: 10px; flex-shrink: 0;">
<ui:Label text="This is a breaking change! Do you still want to update? " name="Text" style="margin-top: 0; margin-right: 0; margin-left: 0; margin-bottom: 0; white-space: normal; -unity-text-align: middle-left;" />
<ui:Label text="Link to Migration Guide" name="MigrationLink" class="link" style="margin-top: 5px; margin-right: 0; margin-left: 0; margin-bottom: 0; white-space: normal; -unity-text-align: middle-left; color: rgb(0, 104, 255);" />
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="Buttons" style="flex-direction: row-reverse; padding-right: 10px; padding-left: 10px; padding-top: 10px; padding-bottom: 10px; flex-shrink: 0; height: 44px;">
<ui:Button text="Cancel" display-tooltip-when-elided="true" name="CancelButton" />
<ui:Button text="Update" display-tooltip-when-elided="true" name="UpdateButton" style="white-space: nowrap;" />
</ui:VisualElement>
</ui:UXML>
10 changes: 10 additions & 0 deletions Editor/UI/BreakingChangeDialog/BreakingChangeDialog.uxml.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed Editor/UI/Visuals/rpm_editor_window_banner.png
Binary file not shown.
128 changes: 0 additions & 128 deletions Editor/UI/Visuals/rpm_editor_window_banner.png.meta

This file was deleted.

Loading