diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a51f2c..100dbd56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# Version TBD +## New Features +* Android Resolver: Auto-resolution now displays a window for a few seconds + allowing the user to skip the resolution process. The delay time can be + configured via the settings menu. + # Version 1.2.116 - Jun 7, 2019 ## Bug Fixes * Android Resolver: Fixed resolution of Android dependencies without version diff --git a/source/PlayServicesResolver/src/PlayServicesResolver.cs b/source/PlayServicesResolver/src/PlayServicesResolver.cs index e53cf37d..7a0a77d2 100644 --- a/source/PlayServicesResolver/src/PlayServicesResolver.cs +++ b/source/PlayServicesResolver/src/PlayServicesResolver.cs @@ -1,4 +1,4 @@ -// +// // Copyright (C) 2015 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -149,14 +149,12 @@ public static DependencyState ReadFromFile() { return true; } else if (elementName == "package" && parentElementName == "packages") { - if (isStart && reader.Read() && - reader.NodeType == XmlNodeType.Text) { + if (reader.Read() && reader.NodeType == XmlNodeType.Text) { packages.Add(reader.ReadContentAsString()); } return true; } else if (elementName == "file" && parentElementName == "files") { - if (isStart && reader.Read() && - reader.NodeType == XmlNodeType.Text) { + if (reader.Read() && reader.NodeType == XmlNodeType.Text) { files.Add(reader.ReadContentAsString()); } return true; @@ -980,32 +978,70 @@ private static void OnPostProcessScene() { /// Defaults to 1 second. private static void ScheduleAutoResolve(double delayInMilliseconds = 1000.0) { lock (typeof(PlayServicesResolver)) { - if (!autoResolving) { - RunOnMainThread.Cancel(autoResolveJobId); - autoResolveJobId = RunOnMainThread.Schedule( - () => { - lock (typeof(PlayServicesResolver)) { - autoResolving = true; - } - RunOnMainThread.PollOnUpdateUntilComplete(() => { - if (EditorApplication.isCompiling) return false; - // Only run AutoResolve() if we have a valid autoResolveJobId. - // If autoResolveJobId is 0, ScheduleResolve() - // has already been run and we should not run AutoResolve() - // again. - if (autoResolveJobId != 0) { - AutoResolve(() => { - lock (typeof(PlayServicesResolver)) { - autoResolving = false; - autoResolveJobId = 0; + if (autoResolving) { + return; + } + + RunOnMainThread.Cancel(autoResolveJobId); + autoResolveJobId = RunOnMainThread.Schedule(() => { + lock (typeof(PlayServicesResolver)) { + autoResolving = true; + } + + int delaySec = GooglePlayServices.SettingsDialog.AutoResolutionDelay; + DateTimeOffset resolveTime = DateTimeOffset.Now.AddSeconds(delaySec); + bool shouldResolve = true; + AlertModal alert = null; + RunOnMainThread.PollOnUpdateUntilComplete(() => { + if (resolveTime > DateTimeOffset.Now && + Resolver.AutomaticResolutionEnabled()) { + int countDown = (int)(resolveTime - DateTimeOffset.Now).TotalSeconds; + string message = String.Format("Auto Resolve Dependencies in {0}s", + countDown); + if (alert == null) { + alert = new AlertModal { + Title = "Android Resolver: Resolve or skip resolution?", + Message = message, + Ok = new AlertModal.LabeledAction { + Label = "Resolve", + DelegateAction = () => { + resolveTime = DateTimeOffset.Now; + shouldResolve = true; } - }); + }, + Cancel = new AlertModal.LabeledAction { + Label = "Skip", + DelegateAction = () => { + resolveTime = DateTimeOffset.Now; + shouldResolve = false; + } + } + }; + alert.Display(); + } + if (alert != null) { + alert.Message = message; + return false; + } + } + + if (EditorApplication.isCompiling) return false; + // Only run AutoResolve() if we have a valid autoResolveJobId. + // If autoResolveJobId is 0, ScheduleResolve() + // has already been run and we should not run AutoResolve() + // again. + + if (shouldResolve && autoResolveJobId != 0) { + AutoResolve(() => { + lock (typeof(PlayServicesResolver)) { + autoResolving = false; + autoResolveJobId = 0; } - return true; }); - }, - delayInMilliseconds); - } + } + return true; + }); + }, delayInMilliseconds); } } @@ -1457,9 +1493,7 @@ private static void ScheduleResolve(bool forceResolution, RunOnMainThread.Cancel(autoResolveJobId); autoResolveJobId = 0; // Remove any enqueued auto-resolve jobs. - resolutionJobs.RemoveAll((jobInfo) => { - return jobInfo != null && jobInfo.IsAutoResolveJob; - }); + resolutionJobs.RemoveAll((jobInfo) => jobInfo == null || jobInfo.IsAutoResolveJob); firstJob = resolutionJobs.Count == 0; resolutionJobs.Add( diff --git a/source/PlayServicesResolver/src/SettingsDialog.cs b/source/PlayServicesResolver/src/SettingsDialog.cs index a0769cf4..0c07a217 100644 --- a/source/PlayServicesResolver/src/SettingsDialog.cs +++ b/source/PlayServicesResolver/src/SettingsDialog.cs @@ -40,6 +40,7 @@ private class Settings { internal bool verboseLogging; internal bool autoResolutionDisabledWarning; internal bool promptBeforeAutoResolution; + internal int autoResolutionDelay; internal bool useProjectSettings; /// @@ -57,6 +58,7 @@ internal Settings() { verboseLogging = SettingsDialog.VerboseLogging; autoResolutionDisabledWarning = SettingsDialog.AutoResolutionDisabledWarning; promptBeforeAutoResolution = SettingsDialog.PromptBeforeAutoResolution; + autoResolutionDelay = SettingsDialog.AutoResolutionDelay; useProjectSettings = SettingsDialog.UseProjectSettings; } @@ -75,6 +77,7 @@ internal void Save() { SettingsDialog.VerboseLogging = verboseLogging; SettingsDialog.AutoResolutionDisabledWarning = autoResolutionDisabledWarning; SettingsDialog.PromptBeforeAutoResolution = promptBeforeAutoResolution; + SettingsDialog.AutoResolutionDelay = autoResolutionDelay; SettingsDialog.UseProjectSettings = useProjectSettings; } } @@ -88,10 +91,9 @@ internal void Save() { private const string PatchAndroidManifestKey = Namespace + "PatchAndroidManifest"; private const string PatchMainTemplateGradleKey = Namespace + "PatchMainTemplateGradle"; private const string VerboseLoggingKey = Namespace + "VerboseLogging"; - private const string AutoResolutionDisabledWarningKey = - Namespace + "AutoResolutionDisabledWarning"; - private const string PromptBeforeAutoResolutionKey = - Namespace + "PromptBeforeAutoResolution"; + private const string AutoResolutionDisabledWarningKey = Namespace + "AutoResolutionDisabledWarning"; + private const string PromptBeforeAutoResolutionKey = Namespace + "PromptBeforeAutoResolution"; + private const string AutoResolutionDelayKey = Namespace + "AutoResolutionDelay"; private const string UseGradleDaemonKey = Namespace + "UseGradleDaemon"; // List of preference keys, used to restore default settings. @@ -184,10 +186,33 @@ internal static bool AutoResolutionDisabledWarning { /// display a prompt. /// internal static bool PromptBeforeAutoResolution { + set { projectSettings.SetBool(PromptBeforeAutoResolutionKey, value); } + get { return projectSettings.GetBool(PromptBeforeAutoResolutionKey, true); } + } + + // Maximum delay time before starting auto-resolution. + const int MAXIMUM_AUTO_RESOLVE_DELAY_TIME = 30; + + /// + /// Clamp auto-resolution delay to MAXIMUM_AUTO_RESOLVE_DELAY_TIME seconds. + /// + /// Delay to clamp + /// A clamped delay time. + private static int ClampAutoResolutionDelay(int delay) { + return Math.Min(Math.Max(0, delay), MAXIMUM_AUTO_RESOLVE_DELAY_TIME); + } + + /// + /// Delay, in seconds, before starting auto-resolution. + /// + internal static int AutoResolutionDelay { set { - projectSettings.SetBool(PromptBeforeAutoResolutionKey, value); + projectSettings.SetInt(AutoResolutionDelayKey, + ClampAutoResolutionDelay(value)); + } + get { + return ClampAutoResolutionDelay(projectSettings.GetInt(AutoResolutionDelayKey, 0)); } - get { return projectSettings.GetBool(PromptBeforeAutoResolutionKey, true); } } internal static bool UseProjectSettings { @@ -368,6 +393,13 @@ public void OnGUI() { settings.promptBeforeAutoResolution = EditorGUILayout.Toggle(settings.promptBeforeAutoResolution); GUILayout.EndHorizontal(); + + GUILayout.BeginHorizontal(); + GUILayout.Label("Auto Resolution Delay", EditorStyles.boldLabel); + settings.autoResolutionDelay = ClampAutoResolutionDelay( + EditorGUILayout.IntField(settings.autoResolutionDelay)); + GUILayout.EndHorizontal(); + GUILayout.Label("Time, in seconds, to wait before auto-resolution."); EditorGUI.EndDisabledGroup(); GUILayout.BeginHorizontal();