Skip to content

Delay auto resolve skippable dialog #219

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ project.ext {
(OperatingSystem.WINDOWS):
["\\Program Files\\Unity\\Editor\\Unity.exe"] +
(new FileNameFinder()).getFileNames(
"\\", "Program Files\\Unity\\Hub\\Editor\\*\\Editor\\Unity.exe"),
"\\Program Files\\Unity\\Hub\\Editor", "*\\Editor\\Unity.exe"), // previously don't work on windows
(OperatingSystem.LINUX): ["/opt/Unity/Editor/Unity"]][operatingSystem]

// Search for the Unity editor executable.
Expand All @@ -61,9 +61,10 @@ project.ext {
(OperatingSystem.MAC_OSX): "Unity.app/Contents/MacOS",
(OperatingSystem.WINDOWS): "Editor",
(OperatingSystem.LINUX): "Editor"][operatingSystem]
File unityRootDir = findFileProperty(
"UNITY_DIR", new File(unityExe.parentFile.absolutePath -
unityExeParentPath), true)

// (string - string) will remove first occurance. We need to remove last occurance
File unityRootDir = findFileProperty("UNITY_DIR",
new File(unityExe.parentFile.absolutePath.substring(0,unityExe.parentFile.absolutePath.lastIndexOf(unityExeParentPath))), true)
if (unityRootDir == null) {
throw new StopActionException("Unity root directory (UNITY_DIR) not found.")
}
Expand Down
Binary file modified source/PlayServicesResolver/scripts/gradle-template.zip
Binary file not shown.
78 changes: 47 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 @@ -170,14 +170,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 @@ -1058,32 +1056,52 @@ 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;
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;
RunOnMainThread.PollOnUpdateUntilComplete(() => {
// 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)
return true;

DateTimeOffset now = DateTimeOffset.Now;
if (resolveTime > now && PlayServicesResolver.AutomaticResolutionEnabled) {
float countDown = (float)(resolveTime - now).TotalSeconds;
if(EditorUtility.DisplayCancelableProgressBar("Skip dependency?","Auto Resolve Dependency in : " + (int)countDown,countDown / delaySec)) {
resolveTime = now;
shouldResolve = false;
}
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;
}
});

return false;
}

EditorUtility.ClearProgressBar();

if (EditorApplication.isCompiling) return false;
if (shouldResolve) {
AutoResolve(() => {
lock (typeof(PlayServicesResolver)) {
autoResolving = false;
autoResolveJobId = 0;
}
return true;
});
},
delayInMilliseconds);
}
}
return true;
});
},delayInMilliseconds);
}
}

Expand Down Expand Up @@ -1550,9 +1568,7 @@ private static void ScheduleResolve(bool forceResolution, bool closeWindowOnComp
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
28 changes: 19 additions & 9 deletions source/PlayServicesResolver/src/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private class Settings {
internal bool verboseLogging;
internal bool autoResolutionDisabledWarning;
internal bool promptBeforeAutoResolution;
internal int autoResolutionDelay;
internal bool useProjectSettings;

/// <summary>
Expand All @@ -59,6 +60,7 @@ internal Settings() {
verboseLogging = SettingsDialog.VerboseLogging;
autoResolutionDisabledWarning = SettingsDialog.AutoResolutionDisabledWarning;
promptBeforeAutoResolution = SettingsDialog.PromptBeforeAutoResolution;
autoResolutionDelay = SettingsDialog.AutoResolutionDelay;
useProjectSettings = SettingsDialog.UseProjectSettings;
}

Expand All @@ -78,6 +80,7 @@ internal void Save() {
SettingsDialog.VerboseLogging = verboseLogging;
SettingsDialog.AutoResolutionDisabledWarning = autoResolutionDisabledWarning;
SettingsDialog.PromptBeforeAutoResolution = promptBeforeAutoResolution;
SettingsDialog.AutoResolutionDelay = autoResolutionDelay;
SettingsDialog.UseProjectSettings = useProjectSettings;
}
}
Expand All @@ -92,10 +95,9 @@ internal void Save() {
private const string PatchMainTemplateGradleKey = Namespace + "PatchMainTemplateGradle";
private const string UseJetifierKey = Namespace + "UseJetifier";
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 @@ -189,12 +191,16 @@ 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); }
}

const int MAXIMUM_AUTO_RESOLVE_DELAY_TIME = 30;
internal static int AutoResolutionDelay {
set { projectSettings.SetInt(AutoResolutionDelayKey,Math.Min(Math.Max(0,value),MAXIMUM_AUTO_RESOLVE_DELAY_TIME)); }
get { return Math.Min(Math.Max(0,projectSettings.GetInt(AutoResolutionDelayKey,0)),MAXIMUM_AUTO_RESOLVE_DELAY_TIME); }
}

internal static bool UseProjectSettings {
get { return projectSettings.UseProjectSettings; }
set { projectSettings.UseProjectSettings = value; }
Expand Down Expand Up @@ -375,8 +381,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 = Mathf.Clamp(EditorGUILayout.IntField(settings.autoResolutionDelay),0,MAXIMUM_AUTO_RESOLVE_DELAY_TIME);
GUILayout.EndHorizontal();
EditorGUI.EndDisabledGroup();

Expand Down