Skip to content

Commit

Permalink
Auto repaints inspector when version check/trusted URL list is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
JLChnToZ committed Nov 20, 2023
1 parent 29113b4 commit aa47d8b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class PackageSelfUpdater {

public bool IsInstalledManually => isInstalledManually;

public event Action OnVersionRefreshed;

public PackageSelfUpdater(Assembly assembly, string listingsID, string listingsURL) :
this(PackageManagerPackageInfo.FindForAssembly(assembly), listingsID, listingsURL) { }

Expand Down Expand Up @@ -67,6 +69,12 @@ public void CheckInstallation() {
var manifest = VPMProjectManifest.Load(Resolver.ProjectDir);
isInstalledManually = !manifest.locked.ContainsKey(packageName) && !manifest.dependencies.ContainsKey(packageName);
#endif
CheckInstallationCallback().Forget();
}

async UniTask CheckInstallationCallback() {
await UniTask.SwitchToMainThread();
OnVersionRefreshed?.Invoke();
}

public void ResolveInstallation() {
Expand Down
11 changes: 9 additions & 2 deletions Packages/idv.jlchntoz.vvmw/Editor/Common/TrustedUrlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

namespace JLChnToZ.VRC.VVMW.Editors {
public sealed class TrustedUrlUtils {
public static event Action OnTrustedUrlsReady;
static readonly Dictionary<TrustedUrlTypes, TrustedUrlUtils> instances = new Dictionary<TrustedUrlTypes, TrustedUrlUtils>();
static readonly AsyncLazy getTrustedUrlsTask = UniTask.Lazy(GetTrustedUrlsLazy);
static AsyncLazy getTrustedUrlsTask = UniTask.Lazy(GetTrustedUrlsLazy);
static GUIContent tempContent, warningContent;
readonly Dictionary<string, bool> trustedDomains = new Dictionary<string, bool>();
readonly Dictionary<string, string> messageCache = new Dictionary<string, string>();
Expand Down Expand Up @@ -65,7 +66,12 @@ static async UniTask GetTrustedUrlsLazy() {
() => initState.TrySetResult(),
() => initState.TrySetException(new Exception("Failed to initialize VRCSDK config."))
);
await initState.Task;
try {
await initState.Task;
} catch (Exception ex) {
getTrustedUrlsTask = UniTask.Lazy(GetTrustedUrlsLazy); // Retry on next time.
throw ex;
}
}
if (vrcsdkConfig.HasKey("urlList")) {
var trustedUrls = vrcsdkConfig.GetList("urlList");
Expand All @@ -77,6 +83,7 @@ static async UniTask GetTrustedUrlsLazy() {
instances[TrustedUrlTypes.ImageUrl].trustedUrls = vrcsdkConfig.GetList("imageHostUrlList");
if (vrcsdkConfig.HasKey("stringHostUrlList"))
instances[TrustedUrlTypes.StringUrl].trustedUrls = vrcsdkConfig.GetList("stringHostUrlList");
OnTrustedUrlsReady?.Invoke();
}

public static void CopyTrustedUrlsToStringArray(SerializedProperty stringArray, TrustedUrlTypes urlType) =>
Expand Down
5 changes: 5 additions & 0 deletions Packages/idv.jlchntoz.vvmw/Editor/VVMW/EditorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ protected virtual void OnEnable() {
var assetPath = AssetDatabase.GUIDToAssetPath(fontGUID);
if (!string.IsNullOrEmpty(assetPath)) font = AssetDatabase.LoadAssetAtPath<Font>(assetPath);
}
selfUpdater.OnVersionRefreshed += Repaint;
}

protected virtual void OnDisable() {
if (selfUpdater != null) selfUpdater.OnVersionRefreshed -= Repaint;
}

public override void OnInspectorGUI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected override void OnEnable() {
PlayListEditorWindow.OnFrontendUpdated += OnFrontEndUpdated;
}

protected virtual void OnDisable() {
protected override void OnDisable() {
base.OnDisable();
PlayListEditorWindow.OnFrontendUpdated -= OnFrontEndUpdated;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ void OnEnable() {
elementHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing,
showDefaultBackground = false,
};
TrustedUrlUtils.OnTrustedUrlsReady += Repaint;
}

void OnDisable() => SaveIfRequired();
void OnDisable() {
TrustedUrlUtils.OnTrustedUrlsReady -= Repaint;
SaveIfRequired();
}

void OnGUI() {
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) {
Expand Down

0 comments on commit aa47d8b

Please sign in to comment.