-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bitbucket: add Avalonia-based UI helper for BB
Add a new UI helper for Bitbucket using Avalonia.
- Loading branch information
1 parent
1047184
commit bfe20a9
Showing
14 changed files
with
604 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
src/shared/Atlassian.Bitbucket.UI/Atlassian.Bitbucket.UI.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<RuntimeIdentifiers>osx-x64;linux-x64</RuntimeIdentifiers> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Atlassian.Bitbucket\Atlassian.Bitbucket.csproj" /> | ||
<ProjectReference Include="..\Microsoft.Git.CredentialManager.UI\Microsoft.Git.CredentialManager.UI.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Controls\TesterWindow.axaml.cs"> | ||
<DependentUpon>TesterWindow.axaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<AvaloniaResource Include="Assets\**" /> | ||
</ItemGroup> | ||
|
||
</Project> |
49 changes: 49 additions & 0 deletions
49
src/shared/Atlassian.Bitbucket.UI/Commands/CredentialsCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Atlassian.Bitbucket.UI.ViewModels; | ||
using Atlassian.Bitbucket.UI.Views; | ||
using Microsoft.Git.CredentialManager; | ||
using Microsoft.Git.CredentialManager.UI; | ||
|
||
namespace Atlassian.Bitbucket.UI.Commands | ||
{ | ||
internal class CredentialsCommand : HelperCommand | ||
{ | ||
public CredentialsCommand(CommandContext context) | ||
: base(context, "userpass", "Show authentication prompt.") | ||
{ | ||
AddOption( | ||
new Option<string>("--username", "Username or email.") | ||
); | ||
|
||
Handler = CommandHandler.Create<string>(ExecuteAsync); | ||
} | ||
|
||
private async Task<int> ExecuteAsync(string userName) | ||
{ | ||
var viewModel = new CredentialsViewModel(Context.Environment) | ||
{ | ||
UserName = userName | ||
}; | ||
|
||
await AvaloniaUi.ShowViewAsync<CredentialsView>(viewModel, GetParentHandle(), CancellationToken.None); | ||
|
||
if (!viewModel.WindowResult) | ||
{ | ||
throw new Exception("User cancelled dialog."); | ||
} | ||
|
||
WriteResult(new Dictionary<string, string> | ||
{ | ||
["username"] = viewModel.UserName, | ||
["password"] = viewModel.Password, | ||
}); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/shared/Atlassian.Bitbucket.UI/Commands/OAuthCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Atlassian.Bitbucket.UI.ViewModels; | ||
using Atlassian.Bitbucket.UI.Views; | ||
using Microsoft.Git.CredentialManager; | ||
using Microsoft.Git.CredentialManager.UI; | ||
|
||
namespace Atlassian.Bitbucket.UI.Commands | ||
{ | ||
internal class OAuthCommand : HelperCommand | ||
{ | ||
public OAuthCommand(CommandContext context) | ||
: base(context, "oauth", "Show OAuth required prompt.") | ||
{ | ||
Handler = CommandHandler.Create(ExecuteAsync); | ||
} | ||
|
||
private async Task<int> ExecuteAsync() | ||
{ | ||
var viewModel = new OAuthViewModel(Context.Environment); | ||
await AvaloniaUi.ShowViewAsync<OAuthView>(viewModel, GetParentHandle(), CancellationToken.None); | ||
|
||
if (!viewModel.WindowResult) | ||
{ | ||
throw new Exception("User cancelled dialog."); | ||
} | ||
|
||
WriteResult(new Dictionary<string, string> | ||
{ | ||
["continue"] = "true" | ||
}); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/shared/Atlassian.Bitbucket.UI/Controls/TesterWindow.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="Atlassian.Bitbucket.UI.Controls.TesterWindow" | ||
Title="Bitbucket Authentication Dialog Tester" | ||
Height="240" Width="420" CanResize="False"> | ||
<DockPanel> | ||
<Button Content="Show Credentials Dialog" Padding="10" Click="ShowCredentials" /> | ||
<Button Content="Show OAuth Dialog" Padding="10" Click="ShowOAuth" /> | ||
</DockPanel> | ||
</Window> |
68 changes: 68 additions & 0 deletions
68
src/shared/Atlassian.Bitbucket.UI/Controls/TesterWindow.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Atlassian.Bitbucket.UI.ViewModels; | ||
using Atlassian.Bitbucket.UI.Views; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Markup.Xaml; | ||
using Microsoft.Git.CredentialManager; | ||
using Microsoft.Git.CredentialManager.Interop.Linux; | ||
using Microsoft.Git.CredentialManager.Interop.MacOS; | ||
using Microsoft.Git.CredentialManager.Interop.Posix; | ||
using Microsoft.Git.CredentialManager.Interop.Windows; | ||
using Microsoft.Git.CredentialManager.UI.Controls; | ||
|
||
namespace Atlassian.Bitbucket.UI.Controls | ||
{ | ||
public class TesterWindow : Window | ||
{ | ||
private readonly IEnvironment _environment; | ||
|
||
public TesterWindow() | ||
{ | ||
InitializeComponent(); | ||
#if DEBUG | ||
this.AttachDevTools(); | ||
#endif | ||
|
||
if (PlatformUtils.IsWindows()) | ||
{ | ||
_environment = new WindowsEnvironment(new WindowsFileSystem()); | ||
} | ||
else | ||
{ | ||
IFileSystem fs; | ||
if (PlatformUtils.IsMacOS()) | ||
{ | ||
fs = new MacOSFileSystem(); | ||
} | ||
else | ||
{ | ||
fs = new LinuxFileSystem(); | ||
} | ||
|
||
_environment = new PosixEnvironment(fs); | ||
} | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
private void ShowCredentials(object sender, RoutedEventArgs e) | ||
{ | ||
var vm = new CredentialsViewModel(_environment); | ||
var view = new CredentialsView(); | ||
var window = new DialogWindow(view) {DataContext = vm}; | ||
window.ShowDialog(this); | ||
} | ||
|
||
private void ShowOAuth(object sender, RoutedEventArgs e) | ||
{ | ||
var vm = new OAuthViewModel(_environment); | ||
var view = new OAuthView(); | ||
var window = new DialogWindow(view) {DataContext = vm}; | ||
window.ShowDialog(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.CommandLine; | ||
using System.Threading; | ||
using Atlassian.Bitbucket.UI.Commands; | ||
using Atlassian.Bitbucket.UI.Controls; | ||
using Avalonia; | ||
using Microsoft.Git.CredentialManager; | ||
using Microsoft.Git.CredentialManager.UI; | ||
|
||
namespace Atlassian.Bitbucket.UI | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
// If we have no arguments then just start the app with the test window. | ||
if (args.Length == 0) | ||
{ | ||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); | ||
return; | ||
} | ||
|
||
// Create the dispatcher on the main thread. This is required | ||
// for some platform UI services such as macOS that mandates | ||
// all controls are created/accessed on the initial thread | ||
// created by the process (the process entry thread). | ||
Dispatcher.Initialize(); | ||
|
||
// Run AppMain in a new thread and keep the main thread free | ||
// to process the dispatcher's job queue. | ||
var appMain = new Thread(AppMain) {Name = nameof(AppMain)}; | ||
appMain.Start(args); | ||
|
||
// Process the dispatcher job queue (aka: message pump, run-loop, etc...) | ||
// We must ensure to run this on the same thread that it was created on | ||
// (the main thread) so we cannot use any async/await calls between | ||
// Dispatcher.Create and Run. | ||
Dispatcher.MainThread.Run(); | ||
|
||
// Execution should never reach here as AppMain terminates the process on completion. | ||
throw new InvalidOperationException("Main dispatcher job queue shutdown unexpectedly"); | ||
} | ||
|
||
private static void AppMain(object o) | ||
{ | ||
string[] args = (string[]) o; | ||
|
||
string appPath = ApplicationBase.GetEntryApplicationPath(); | ||
using (var context = new CommandContext(appPath)) | ||
using (var app = new HelperApplication(context)) | ||
{ | ||
app.RegisterCommand(new CredentialsCommand(context)); | ||
app.RegisterCommand(new OAuthCommand(context)); | ||
|
||
// Run! | ||
int exitCode = app.RunAsync(args) | ||
.ConfigureAwait(false) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
Environment.Exit(exitCode); | ||
} | ||
} | ||
|
||
public static AppBuilder BuildAvaloniaApp() | ||
=> AppBuilder.Configure(() => new AvaloniaApp(() => new TesterWindow())) | ||
.UsePlatformDetect() | ||
.LogToTrace(); | ||
} | ||
} |
Oops, something went wrong.
{B5F00B46-FE93-45F2-B283-52B74B3E13B9}.LinuxRelease|Any CPU.Build.0 = Release|Any CPU