Skip to content

Commit

Permalink
added fail guard
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnSur committed Jan 5, 2024
1 parent 962d2a3 commit 819364f
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ namespace QuickEye.Utility.Editor.AssemblyReloading
{
internal static class StatusBarExtender
{
private const int MaxRetries = 5;
public static event Action<VisualElement> StatusBarCreated;
private static GUIView _statusBarInstance;
private static int _retries;

[InitializeOnLoadMethod]
private static void Initialize()
Expand All @@ -20,18 +22,29 @@ private static void Initialize()

private static void OnUpdate()
{
if (_statusBarInstance != null)
if (_statusBarInstance != null || _retries >= MaxRetries)
return;
_statusBarInstance = Resources.FindObjectsOfTypeAll<AppStatusBar>().FirstOrDefault();
if(_statusBarInstance == null)
return; // todo: prevent FindObjectsOfTypeAll on every tick

var visualTree = _statusBarInstance.windowBackend.visualTree as VisualElement;
visualTree.styleSheets.Add(UIElementsEditorUtility.GetCommonDarkStyleSheet());
{
_retries++;
return;
}

try
{
var visualTree = _statusBarInstance.windowBackend.visualTree as VisualElement;
visualTree.styleSheets.Add(UIElementsEditorUtility.GetCommonDarkStyleSheet());

var originalBar = visualTree.Q<IMGUIContainer>();
originalBar.AddToClassList("status-bar");
StatusBarCreated?.Invoke(visualTree);
var originalBar = visualTree.Q<IMGUIContainer>();
originalBar.AddToClassList("status-bar");
StatusBarCreated?.Invoke(visualTree);
}
catch (Exception e)
{
Debug.LogError($"Failed to extend status bar: {e}");
_retries = MaxRetries;
}
}
}
}

0 comments on commit 819364f

Please sign in to comment.