Skip to content

Osx tray #124

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 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 3 additions & 3 deletions docs/diff-tool.custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var resolvedTool = DiffTools.AddTool(
exePath: diffToolPath,
binaryExtensions: new[] {"jpg"})!;
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L24-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-addtool' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L26-L36' title='Snippet source file'>snippet source</a> | <a href='#snippet-addtool' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Add a tool based on existing resolved tool:
Expand All @@ -35,7 +35,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(
name: "MyCustomDiffTool",
arguments: (temp, target) => $"\"custom args {temp}\" \"{target}\"");
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L63-L68' title='Snippet source file'>snippet source</a> | <a href='#snippet-addtoolbasedon' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L87-L92' title='Snippet source file'>snippet source</a> | <a href='#snippet-addtoolbasedon' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -63,7 +63,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(

await DiffRunner.LaunchAsync(resolvedTool!, "PathToTempFile", "PathToTargetFile");
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L77-L84' title='Snippet source file'>snippet source</a> | <a href='#snippet-addtoolandlaunch' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L101-L108' title='Snippet source file'>snippet source</a> | <a href='#snippet-addtoolandlaunch' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion docs/diff-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Setting the `DiffEngine_MaxInstances` environment variable to the number of inst
```cs
DiffRunner.MaxInstancesToLaunch(10);
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L13-L17' title='Snippet source file'>snippet source</a> | <a href='#snippet-maxinstancestolaunch' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L15-L19' title='Snippet source file'>snippet source</a> | <a href='#snippet-maxinstancestolaunch' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
2 changes: 1 addition & 1 deletion docs/diff-tool.order.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ For example `VisualStudio,Meld` will result in VisualStudio then Meld then all o
```cs
DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge);
```
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L114-L116' title='Snippet source file'>snippet source</a> | <a href='#snippet-useorder' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L138-L140' title='Snippet source file'>snippet source</a> | <a href='#snippet-useorder' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
24 changes: 24 additions & 0 deletions src/DiffEngine.Tests/DiffToolsTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using DiffEngine;
using DiffEngine.Tests;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -37,6 +39,28 @@ public void AddTool()
Assert.Equal(resolvedTool.Name, forExtension!.Name);
}

[Fact]
public void MacDiffOrderShouldNotMessWithAddTool()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var diffToolPath = MacDiffTool.Exe;
var resolvedTool = DiffTools.AddTool(
name: "MacDiffTool",
autoRefresh: true,
isMdi: false,
supportsText: true,
requiresTarget: true,
arguments: (tempFile, targetFile) => $"\"{tempFile}\" \"{targetFile}\"",
exePath: diffToolPath,
binaryExtensions: Enumerable.Empty<string>())!;
DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge);
Assert.Equal(resolvedTool.Name, DiffTools.Resolved.First().Name);
Assert.True(DiffTools.TryFind("txt", out var forExtension));
Assert.Equal(resolvedTool.Name, forExtension!.Name);
}
}

[Fact]
public void OrderShouldNotMessWithAddTool()
{
Expand Down
22 changes: 22 additions & 0 deletions src/DiffEngine.Tests/MacDiffTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace DiffEngine.Tests
{
public class MacDiffTool
{
public static string Exe;

static MacDiffTool()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Exe = Path.GetFullPath(Path.Combine(AssemblyLocation.CurrentDirectory, "../../../../DiffEngineTray.Mac/bin/Debug/DiffEngineTray.Mac.app"));
return;
}

throw new Exception();
}
}
}
8 changes: 8 additions & 0 deletions src/DiffEngine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiffEngine.Tests", "DiffEng
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiffEngineTray.Tests", "DiffEngineTray.Tests\DiffEngineTray.Tests.csproj", "{E339AB28-21B2-47DB-B995-EB2C4CE8BA99}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiffEngineTray.Common", "DiffEngineTray.Common\DiffEngineTray.Common.csproj", "{B62FBE96-EB1E-4621-AA31-8971862FC4FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,12 @@ Global
{E339AB28-21B2-47DB-B995-EB2C4CE8BA99}.MacOS|Any CPU.ActiveCfg = MacOS|Any CPU
{E339AB28-21B2-47DB-B995-EB2C4CE8BA99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E339AB28-21B2-47DB-B995-EB2C4CE8BA99}.Release|Any CPU.Build.0 = Release|Any CPU
{B62FBE96-EB1E-4621-AA31-8971862FC4FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B62FBE96-EB1E-4621-AA31-8971862FC4FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B62FBE96-EB1E-4621-AA31-8971862FC4FB}.MacOS|Any CPU.ActiveCfg = Debug|Any CPU
{B62FBE96-EB1E-4621-AA31-8971862FC4FB}.MacOS|Any CPU.Build.0 = Debug|Any CPU
{B62FBE96-EB1E-4621-AA31-8971862FC4FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B62FBE96-EB1E-4621-AA31-8971862FC4FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions src/DiffEngine/DiffEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net461</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\DiffEngineTray\JsonEscaping.cs" Link="Tray\JsonEscaping.cs" />
<Compile Include="..\DiffEngineTray\PiperClient.cs" Link="Tray\PiperClient.cs" />
<Compile Include="..\DiffEngineTray.Common\JsonEscaping.cs" Link="Tray\JsonEscaping.cs" />
<Compile Include="..\DiffEngineTray.Common\PiperClient.cs" Link="Tray\PiperClient.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Caseless.Fody" Version="1.9.0" PrivateAssets="All" />
Expand Down
19 changes: 19 additions & 0 deletions src/DiffEngineTray.Common/DiffEngineTray.Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8</LangVersion>
<SignAssembly>false</SignAssembly>
<Description>A utility that runs in the windows tray and handles the results of file differences.</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="ProjectDefaults" Version="1.0.46" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.7.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" Condition="$(Configuration) == 'Release'" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static async Task<bool> FilesAreEqual(string file1, string file2)
return false;
}

await using var fs1 = OpenRead(file1);
await using var fs2 = OpenRead(file2);
using var fs1 = OpenRead(file1);
using var fs2 = OpenRead(file2);
return await StreamsAreEqual(fs1, fs2);
}

Expand Down
25 changes: 25 additions & 0 deletions src/DiffEngineTray.Common/IMessageBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace DiffEngineTray.Common
{
public enum MessageBoxIcon
{
Error
}

public enum MessageBoxButtons
{
YesNo,
OK
}

public enum AlertResult
{
NSAlertFirstButtonReturn = 1000,
NSAlertSecondButtonReturn = 1001,
NSAlertThirdButtonReturn = 1002
}

public interface IMessageBox
{
public bool? Show(string message, string title, MessageBoxIcon icon, MessageBoxButtons buttons = MessageBoxButtons.YesNo);
}
}
7 changes: 7 additions & 0 deletions src/DiffEngineTray.Common/IUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DiffEngineTray.Common
{
public interface IUpdater
{
void Run();
}
}
7 changes: 7 additions & 0 deletions src/DiffEngineTray.Common/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("DiffEngineTray.Tests")]
[assembly:InternalsVisibleTo("DiffEngineTray")]
[assembly:InternalsVisibleTo("DiffEngineTray.Mac")]
[assembly:InternalsVisibleTo("DiffEngineTray.Mac.Tests")]
[assembly:InternalsVisibleTo("DiffEngine")]
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
using System.Collections.Concurrent;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using DiffEngineTray.Common;

static class IssueLauncher
class IssueLauncher
{
static ConcurrentBag<string> recorded = new ConcurrentBag<string>();
static string defaultBody;

static IMessageBox? messageBox;

static IssueLauncher()
{
defaultBody = WebUtility.UrlEncode($@" * DiffEngineTray Version: {VersionReader.VersionString}
* OS: {Environment.OSVersion.VersionString}");
}

public static void Initialize(IMessageBox message)
{
messageBox = message;
}

public static void Launch()
{
LinkLauncher.LaunchUrl($"https://github.com/VerifyTests/DiffEngine/issues/new?title=TODO&body={defaultBody}");
Expand All @@ -28,7 +34,7 @@ public static void LaunchForException(string message, Exception exception)
}
recorded.Add(message);

var result = MessageBox.Show(
var result = messageBox?.Show(
$@"An error occurred: {message}

Logged to: {Logging.Directory}
Expand All @@ -37,9 +43,8 @@ public static void LaunchForException(string message, Exception exception)

Open an issue on GitHub?",
"DiffEngineTray Error",
MessageBoxButtons.YesNo,
MessageBoxIcon.Error);
if (result == DialogResult.No)
if (result != true)
{
return;
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static void InnerMove(TrackedMove move)
{
if (File.Exists(move.Temp))
{
File.Move(move.Temp, move.Target, true);
File.Move(move.Temp, move.Target); //Overload not available here
}

KillProcesses(move);
Expand Down
122 changes: 122 additions & 0 deletions src/DiffEngineTray.Mac.Tests/AsyncTimerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.Threading.Tasks;
using Xunit;

public class AsyncTimerTests
{
[Fact]
public async Task It_calls_error_callback()
{
var errorCallbackInvoked = new TaskCompletionSource<bool>();

var timer = new AsyncTimer(
callback: (time, token) => throw new Exception("Simulated!"),
interval: TimeSpan.Zero,
errorCallback: e => { errorCallbackInvoked.SetResult(true); });

Assert.True(await errorCallbackInvoked.Task);
}

[Fact]
public async Task It_continues_to_run_after_an_error()
{
var callbackInvokedAfterError = new TaskCompletionSource<bool>();

var fail = true;
var exceptionThrown = false;
var timer = new AsyncTimer(
callback: (time, token) =>
{
if (fail)
{
fail = false;
throw new Exception("Simulated!");
}

Assert.True(exceptionThrown);
callbackInvokedAfterError.SetResult(true);
return Task.FromResult(0);
},
interval: TimeSpan.Zero,
errorCallback: e => { exceptionThrown = true; });

Assert.True(await callbackInvokedAfterError.Task);
}

[Fact]
public async Task Stop_cancels_token_while_waiting()
{
var waitCanceled = false;
var delayStarted = new TaskCompletionSource<bool>();
var timer = new AsyncTimer(
callback: (time, token) => throw new Exception("Simulated!"),
interval: TimeSpan.FromDays(7),
delayStrategy: async (delayTime, token) =>
{
delayStarted.SetResult(true);
try
{
await Task.Delay(delayTime, token);
}
catch (OperationCanceledException)
{
waitCanceled = true;
}
});

await delayStarted.Task;
await timer.DisposeAsync();

Assert.True(waitCanceled);
}

[Fact]
public async Task Stop_cancels_token_while_in_callback()
{
var callbackCanceled = false;
var callbackStarted = new TaskCompletionSource<bool>();
var stopInitiated = new TaskCompletionSource<bool>();
var timer = new AsyncTimer(
callback: async (time, token) =>
{
callbackStarted.SetResult(true);
await stopInitiated.Task;
if (token.IsCancellationRequested)
{
callbackCanceled = true;
}
},
interval: TimeSpan.Zero);

await callbackStarted.Task;
var stopTask = timer.DisposeAsync();
stopInitiated.SetResult(true);
await stopTask;
Assert.True(callbackCanceled);
}

[Fact]
public async Task Stop_waits_for_callback_to_complete()
{
var callbackCompleted = new TaskCompletionSource<bool>();
var callbackTaskStarted = new TaskCompletionSource<bool>();
var timer = new AsyncTimer(
callback: (time, token) =>
{
callbackTaskStarted.SetResult(true);
return callbackCompleted.Task;
},
interval: TimeSpan.Zero);

await callbackTaskStarted.Task;

var stopTask = timer.DisposeAsync().AsTask();
var delayTask = Task.Delay(1000);

var firstToComplete = await Task.WhenAny(stopTask, delayTask);
Assert.Equal(delayTask, firstToComplete);
callbackCompleted.SetResult(true);

await stopTask;
}
}
Loading