Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e66dfc4

Browse files
committed
Merge branch 'fixes/gui_enabled' of https://github.com/MunchyYDL/Unity into fixes/gui_enabled
2 parents bbd969f + a88c32c commit e66dfc4

File tree

10 files changed

+125
-59
lines changed

10 files changed

+125
-59
lines changed

common/SolutionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
namespace System
3232
{
3333
internal static class AssemblyVersionInformation {
34-
internal const string Version = "0.18.0.0";
34+
internal const string Version = "0.19.0.0";
3535
}
3636
}

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ protected void Initialize()
3939
Logging.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
4040
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4141
Platform.Initialize(ProcessManager, TaskManager);
42-
if (Environment.GitExecutablePath != null)
43-
{
44-
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
45-
}
42+
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
4643
SetupMetrics();
4744
}
4845

49-
public virtual async Task Run(bool firstRun)
46+
public void Run(bool firstRun)
47+
{
48+
new ActionTask(SetupGit())
49+
.Then(RestartRepository)
50+
.ThenInUI(InitializeUI)
51+
.Start();
52+
}
53+
54+
private async Task SetupGit()
5055
{
5156
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
5257

5358
if (Environment.GitExecutablePath == null)
5459
{
55-
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
5660
Environment.GitExecutablePath = await DetermineGitExecutablePath();
5761

5862
Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", Environment.GitExecutablePath, Environment.GitExecutablePath.FileExists());
@@ -67,8 +71,6 @@ public virtual async Task Run(bool firstRun)
6771
}
6872
}
6973

70-
RestartRepository();
71-
InitializeUI();
7274
}
7375

7476
public ITask InitializeRepository()

src/GitHub.Api/Application/IApplicationManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ interface IApplicationManager : IDisposable
1717
ITaskManager TaskManager { get; }
1818
IGitClient GitClient { get; }
1919
IUsageTracker UsageTracker { get; }
20+
21+
void Run(bool firstRun);
2022
void RestartRepository();
2123
ITask InitializeRepository();
2224
}

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,18 @@ public static NPath CreateTempDirectory(string myprefix)
697697
}
698698
}
699699

700+
public static NPath GetTempFilename(string myprefix = "")
701+
{
702+
var random = new Random();
703+
var prefix = FileSystem.GetTempPath() + "/" + (String.IsNullOrEmpty(myprefix) ? "" : myprefix + "_");
704+
while (true)
705+
{
706+
var candidate = new NPath(prefix + random.Next());
707+
if (!candidate.Exists())
708+
return candidate;
709+
}
710+
}
711+
700712
public NPath Move(string dest)
701713
{
702714
return Move(new NPath(dest));

src/GitHub.Api/NewTaskSystem/ProcessTask.cs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ProcessWrapper
5656
private readonly Action onEnd;
5757
private readonly Action<Exception, string> onError;
5858
private readonly CancellationToken token;
59+
private readonly List<string> errors = new List<string>();
5960

6061
public Process Process { get; }
6162
public StreamWriter Input { get; private set; }
@@ -77,6 +78,24 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor,
7778

7879
public void Run()
7980
{
81+
if (Process.StartInfo.RedirectStandardError)
82+
{
83+
Process.ErrorDataReceived += (s, e) =>
84+
{
85+
//if (e.Data != null)
86+
//{
87+
// Logger.Trace("ErrorData \"" + (e.Data == null ? "'null'" : e.Data) + "\"");
88+
//}
89+
90+
string encodedData = null;
91+
if (e.Data != null)
92+
{
93+
encodedData = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Data));
94+
errors.Add(encodedData);
95+
}
96+
};
97+
}
98+
8099
try
81100
{
82101
Process.Start();
@@ -101,60 +120,48 @@ public void Run()
101120

102121
if (Process.StartInfo.RedirectStandardInput)
103122
Input = new StreamWriter(Process.StandardInput.BaseStream, new UTF8Encoding(false));
104-
105-
var errors = new List<string>();
123+
if (Process.StartInfo.RedirectStandardError)
124+
Process.BeginErrorReadLine();
106125

107126
onStart?.Invoke();
108-
if (Process.StartInfo.CreateNoWindow)
127+
128+
if (Process.StartInfo.RedirectStandardOutput)
109129
{
110-
if (Process.StartInfo.RedirectStandardOutput)
130+
var outputStream = Process.StandardOutput;
131+
var line = outputStream.ReadLine();
132+
while (line != null)
111133
{
112-
var outputStream = Process.StandardOutput;
113-
var line = outputStream.ReadLine();
114-
while (line != null)
115-
{
116-
outputProcessor.LineReceived(line);
117-
118-
if (token.IsCancellationRequested)
119-
{
120-
if (!Process.HasExited)
121-
Process.Kill();
134+
outputProcessor.LineReceived(line);
122135

123-
Process.Close();
124-
onEnd?.Invoke();
125-
token.ThrowIfCancellationRequested();
126-
}
136+
if (token.IsCancellationRequested)
137+
{
138+
if (!Process.HasExited)
139+
Process.Kill();
127140

128-
line = outputStream.ReadLine();
141+
Process.Close();
142+
onEnd?.Invoke();
143+
token.ThrowIfCancellationRequested();
129144
}
130-
outputProcessor.LineReceived(null);
145+
146+
line = outputStream.ReadLine();
131147
}
148+
outputProcessor.LineReceived(null);
149+
}
132150

133-
if (Process.StartInfo.RedirectStandardError)
151+
if (Process.StartInfo.CreateNoWindow)
152+
{
153+
while (!WaitForExit(500))
134154
{
135-
var errorStream = Process.StandardError;
136-
var errorLine = errorStream.ReadLine();
137-
while (errorLine != null)
138-
{
139-
errors.Add(errorLine);
140-
141-
if (token.IsCancellationRequested)
142-
{
143-
if (!Process.HasExited)
144-
Process.Kill();
145-
146-
Process.Close();
147-
onEnd?.Invoke();
148-
token.ThrowIfCancellationRequested();
149-
}
150-
151-
errorLine = errorStream.ReadLine();
152-
}
155+
if (token.IsCancellationRequested)
156+
Process.Kill();
157+
Process.Close();
158+
onEnd?.Invoke();
159+
token.ThrowIfCancellationRequested();
160+
}
153161

154-
if (Process.ExitCode != 0 && errors.Count > 0)
155-
{
156-
onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray()));
157-
}
162+
if (Process.ExitCode != 0 && errors.Count > 0)
163+
{
164+
onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray()));
158165
}
159166
}
160167

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,32 @@ public void RunCommandLineWindow(NPath workingDirectory)
7171
if (environment.IsWindows)
7272
{
7373
startInfo.FileName = "cmd";
74+
gitEnvironment.Configure(startInfo, workingDirectory);
7475
}
7576
else if (environment.IsMac)
7677
{
7778
// we need to create a temp bash script to set up the environment properly, because
7879
// osx terminal app doesn't inherit the PATH env var and there's no way to pass it in
79-
var envVarFile = environment.FileSystem.GetRandomFileName();
80-
environment.FileSystem.WriteAllLines(envVarFile, new string[] { "cd $GHU_WORKINGDIR", "PATH=$GHU_FULLPATH:$PATH /bin/bash" });
81-
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
80+
81+
var envVarFile = NPath.GetTempFilename();
8282
startInfo.FileName = "open";
8383
startInfo.Arguments = $"-a Terminal {envVarFile}";
84+
gitEnvironment.Configure(startInfo, workingDirectory);
85+
86+
var envVars = startInfo.EnvironmentVariables;
87+
var scriptContents = new[] {
88+
$"cd {envVars["GHU_WORKINGDIR"]}",
89+
$"PATH={envVars["GHU_FULLPATH"]}:$PATH /bin/bash"
90+
};
91+
environment.FileSystem.WriteAllLines(envVarFile, scriptContents);
92+
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
8493
}
8594
else
8695
{
8796
startInfo.FileName = "sh";
97+
gitEnvironment.Configure(startInfo, workingDirectory);
8898
}
8999

90-
gitEnvironment.Configure(startInfo, workingDirectory);
91100
Process.Start(startInfo);
92101
}
93102

src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private static void Initialize()
5858
Logging.LogAdapter = new FileLogAdapter(logPath);
5959
Logging.Info("Initializing GitHub for Unity version " + ApplicationInfo.Version);
6060

61-
((ApplicationManager)ApplicationManager).Run(ApplicationCache.Instance.FirstRun).Forget();
61+
ApplicationManager.Run(ApplicationCache.Instance.FirstRun);
6262
}
6363

6464
private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate,

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private void OnLogUpdate(List<GitLogEntry> entries)
224224

225225
private void MaybeUpdateData()
226226
{
227-
isPublished = Repository.CurrentRemote.HasValue;
227+
isPublished = Repository != null && Repository.CurrentRemote.HasValue;
228228
currentRemote = isPublished ? Repository.CurrentRemote.Value.Name : "placeholder";
229229

230230
if (!updated)

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PublishView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void PopulateView()
9191
.OrderBy(organization => organization.Login)
9292
.Select(organization => organization.Login);
9393

94-
owners = new[] { username }.Union(organizationLogins).ToArray();
94+
owners = new[] { OwnersDefaultText, username }.Union(organizationLogins).ToArray();
9595

9696
isBusy = false;
9797
});

unity/PackageProject/Assets/Editor/GitHub/Mono.Posix.dll.meta

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)