Skip to content
95 changes: 64 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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -928,32 +926,69 @@ 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(Math.Min(30,delaySec));
bool shouldResolve = true;
AlertModal alert = null;
RunOnMainThread.PollOnUpdateUntilComplete(() => {
int countDown = (int)(resolveTime - DateTimeOffset.Now).TotalSeconds;
if (countDown > 0) {
if(alert == null) {
alert = new AlertModal {
Title = "Resolve or Skip dependency?",
Message = "Auto Resolve Dependency in : " + countDown,
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 = "Auto Resolve Dependency in : " + countDown;
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);
}
}

Expand Down Expand Up @@ -1397,9 +1432,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(
Expand Down
27 changes: 18 additions & 9 deletions source/PlayServicesResolver/src/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private class Settings {
internal bool verboseLogging;
internal bool autoResolutionDisabledWarning;
internal bool promptBeforeAutoResolution;
internal int autoResolutionDelay;
internal bool useProjectSettings;

/// <summary>
Expand All @@ -55,6 +56,7 @@ internal Settings() {
verboseLogging = SettingsDialog.VerboseLogging;
autoResolutionDisabledWarning = SettingsDialog.AutoResolutionDisabledWarning;
promptBeforeAutoResolution = SettingsDialog.PromptBeforeAutoResolution;
autoResolutionDelay = Math.Min(Math.Max(0,SettingsDialog.AutoResolutionDelay),30);
useProjectSettings = SettingsDialog.UseProjectSettings;
}

Expand All @@ -72,6 +74,7 @@ internal void Save() {
SettingsDialog.VerboseLogging = verboseLogging;
SettingsDialog.AutoResolutionDisabledWarning = autoResolutionDisabledWarning;
SettingsDialog.PromptBeforeAutoResolution = promptBeforeAutoResolution;
SettingsDialog.AutoResolutionDelay = autoResolutionDelay;
SettingsDialog.UseProjectSettings = useProjectSettings;
}
}
Expand All @@ -84,10 +87,9 @@ internal void Save() {
private const string ExplodeAarsKey = Namespace + "ExplodeAars";
private const string PatchAndroidManifestKey = Namespace + "PatchAndroidManifest";
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.
Expand Down Expand Up @@ -177,12 +179,15 @@ internal static bool AutoResolutionDisabledWarning {
/// display a prompt.
/// </summary>
internal static bool PromptBeforeAutoResolution {
set {
projectSettings.SetBool(PromptBeforeAutoResolutionKey, value);
}
set { projectSettings.SetBool(PromptBeforeAutoResolutionKey, value); }
get { return projectSettings.GetBool(PromptBeforeAutoResolutionKey, true); }
}

internal static int AutoResolutionDelay {
set { projectSettings.SetInt(AutoResolutionDelayKey, value); }
get { return projectSettings.GetInt(AutoResolutionDelayKey,0); }
}

internal static bool UseProjectSettings {
get { return projectSettings.UseProjectSettings; }
set { projectSettings.UseProjectSettings = value; }
Expand Down Expand Up @@ -351,8 +356,12 @@ public void OnGUI() {
EditorGUI.BeginDisabledGroup(!settings.enableAutoResolution);
GUILayout.BeginHorizontal();
GUILayout.Label("Prompt Before Auto-Resolution", EditorStyles.boldLabel);
settings.promptBeforeAutoResolution =
EditorGUILayout.Toggle(settings.promptBeforeAutoResolution);
settings.promptBeforeAutoResolution = EditorGUILayout.Toggle(settings.promptBeforeAutoResolution);
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Auto Resolution Delay", EditorStyles.boldLabel);
settings.autoResolutionDelay = Math.Min(Math.Max(0,EditorGUILayout.IntField(settings.autoResolutionDelay),30));
GUILayout.EndHorizontal();
EditorGUI.EndDisabledGroup();

Expand Down