Skip to content

Add 30 second delay before starting auto-resolution. #246

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
96 changes: 65 additions & 31 deletions source/PlayServicesResolver/src/PlayServicesResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="PlayServicesResolver.cs" company="Google Inc.">
// <copyright file="PlayServicesResolver.cs" company="Google Inc.">
// 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.</param>
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(
44 changes: 38 additions & 6 deletions source/PlayServicesResolver/src/SettingsDialog.cs
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ private class Settings {
internal bool verboseLogging;
internal bool autoResolutionDisabledWarning;
internal bool promptBeforeAutoResolution;
internal int autoResolutionDelay;
internal bool useProjectSettings;

/// <summary>
@@ -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.
/// </summary>
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;

/// <summary>
/// Clamp auto-resolution delay to MAXIMUM_AUTO_RESOLVE_DELAY_TIME seconds.
/// </summary>
/// <param name="delay">Delay to clamp</param>
/// <return>A clamped delay time.</return>
private static int ClampAutoResolutionDelay(int delay) {
return Math.Min(Math.Max(0, delay), MAXIMUM_AUTO_RESOLVE_DELAY_TIME);
}

/// <summary>
/// Delay, in seconds, before starting auto-resolution.
/// </summary>
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();