Skip to content

Commit 7c484f0

Browse files
committed
Merge branch 'main' into spike/sign-in-views
2 parents 1980713 + 88a4a97 commit 7c484f0

File tree

62 files changed

+1976
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1976
-674
lines changed

.idea/.idea.Coder.Desktop/.idea/codeStyles/Project.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.Coder.Desktop/.idea/codeStyles/codeStyleConfig.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

App/App.csproj

+8-30
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<Nullable>enable</Nullable>
1313
<EnableMsixTooling>true</EnableMsixTooling>
1414
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
15+
<!-- To use CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute: -->
16+
<LangVersion>preview</LangVersion>
1517
</PropertyGroup>
1618

1719
<ItemGroup>
@@ -37,40 +39,11 @@
3739
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3840
</PackageReference>
3941
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.2.0" />
42+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
4043
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
4144
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.250108002" />
4245
</ItemGroup>
4346

44-
<ItemGroup>
45-
<Page Update="SignInTokenPage.xaml">
46-
<Generator>MSBuild:Compile</Generator>
47-
</Page>
48-
</ItemGroup>
49-
50-
<ItemGroup>
51-
<Page Update="SignInWindow.xaml">
52-
<Generator>MSBuild:Compile</Generator>
53-
</Page>
54-
</ItemGroup>
55-
56-
<ItemGroup>
57-
<Page Update="SignInURLPage.xaml">
58-
<Generator>MSBuild:Compile</Generator>
59-
</Page>
60-
</ItemGroup>
61-
62-
<ItemGroup>
63-
<Page Update="TrayIcon.xaml">
64-
<Generator>MSBuild:Compile</Generator>
65-
</Page>
66-
</ItemGroup>
67-
68-
<ItemGroup>
69-
<Page Update="HorizontalRule.xaml">
70-
<Generator>MSBuild:Compile</Generator>
71-
</Page>
72-
</ItemGroup>
73-
7447
<!--
7548
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
7649
Tools extension to be activated for this project even if the Windows App SDK Nuget
@@ -79,6 +52,11 @@
7952
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
8053
<ProjectCapability Include="Msix" />
8154
</ItemGroup>
55+
<ItemGroup>
56+
<ProjectReference Include="..\CoderSdk\CoderSdk.csproj" />
57+
<ProjectReference Include="..\Vpn.Proto\Vpn.Proto.csproj" />
58+
<ProjectReference Include="..\Vpn\Vpn.csproj" />
59+
</ItemGroup>
8260

8361
<!--
8462
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution

App/App.xaml.cs

+37-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,59 @@
1+
using System;
2+
using System.Diagnostics;
3+
using Coder.Desktop.App.Services;
14
using Coder.Desktop.App.ViewModels;
5+
using Coder.Desktop.App.Views;
6+
using Coder.Desktop.App.Views.Pages;
7+
using Microsoft.Extensions.DependencyInjection;
28
using Microsoft.UI.Xaml;
39

410
namespace Coder.Desktop.App;
511

612
public partial class App : Application
713
{
8-
private TrayWindow? TrayWindow;
9-
public SignInViewModel SignInViewModel { get; }
14+
private readonly IServiceProvider _services;
15+
private readonly bool _handleClosedEvents = true;
1016

1117
public App()
1218
{
13-
SignInViewModel = new SignInViewModel();
19+
var services = new ServiceCollection();
20+
services.AddSingleton<ICredentialManager, CredentialManager>();
21+
services.AddSingleton<IRpcController, RpcController>();
22+
23+
// SignInWindow views and view models
24+
services.AddTransient<SignInViewModel>();
25+
services.AddTransient<SignInWindow>();
26+
27+
// TrayWindow views and view models
28+
services.AddTransient<TrayWindowDisconnectedViewModel>();
29+
services.AddTransient<TrayWindowDisconnectedPage>();
30+
services.AddTransient<TrayWindowLoginRequiredViewModel>();
31+
services.AddTransient<TrayWindowLoginRequiredPage>();
32+
services.AddTransient<TrayWindowLoginRequiredViewModel>();
33+
services.AddTransient<TrayWindowLoginRequiredPage>();
34+
services.AddTransient<TrayWindowViewModel>();
35+
services.AddTransient<TrayWindowMainPage>();
36+
services.AddTransient<TrayWindow>();
37+
38+
_services = services.BuildServiceProvider();
39+
40+
#if DEBUG
41+
UnhandledException += (_, e) => { Debug.WriteLine(e.Exception.ToString()); };
42+
#endif
43+
1444
InitializeComponent();
1545
}
1646

17-
private bool HandleClosedEvents { get; } = true;
18-
1947
protected override void OnLaunched(LaunchActivatedEventArgs args)
2048
{
21-
TrayWindow = new TrayWindow(SignInViewModel);
22-
TrayWindow.Closed += (sender, args) =>
49+
var trayWindow = _services.GetRequiredService<TrayWindow>();
50+
trayWindow.Closed += (sender, args) =>
2351
{
2452
// TODO: wire up HandleClosedEvents properly
25-
if (HandleClosedEvents)
53+
if (_handleClosedEvents)
2654
{
2755
args.Handled = true;
28-
TrayWindow.AppWindow.Hide();
56+
trayWindow.AppWindow.Hide();
2957
}
3058
};
3159
}

App/HorizontalRule.xaml renamed to App/Controls/HorizontalRule.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<UserControl
4-
x:Class="Coder.Desktop.App.HorizontalRule"
4+
x:Class="Coder.Desktop.App.Controls.HorizontalRule"
55
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
66
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
77
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

App/HorizontalRule.xaml.cs renamed to App/Controls/HorizontalRule.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.UI.Xaml.Controls;
22

3-
namespace Coder.Desktop.App;
3+
namespace Coder.Desktop.App.Controls;
44

55
public sealed partial class HorizontalRule : UserControl
66
{

App/TrayIcon.xaml renamed to App/Controls/TrayIcon.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<UserControl
4-
x:Class="Coder.Desktop.App.TrayIcon"
4+
x:Class="Coder.Desktop.App.Controls.TrayIcon"
55
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
66
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
77
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

App/TrayIcon.xaml.cs renamed to App/Controls/TrayIcon.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Microsoft.UI.Xaml.Controls;
77
using Microsoft.UI.Xaml.Media.Imaging;
88

9-
namespace Coder.Desktop.App;
9+
namespace Coder.Desktop.App.Controls;
1010

1111
[DependencyProperty<ICommand>("OpenCommand")]
1212
[DependencyProperty<ICommand>("ExitCommand")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using Windows.UI;
3+
using Coder.Desktop.App.ViewModels;
4+
using Microsoft.UI.Xaml.Data;
5+
using Microsoft.UI.Xaml.Media;
6+
7+
namespace Coder.Desktop.App.Converters;
8+
9+
public class AgentStatusToColorConverter : IValueConverter
10+
{
11+
private static readonly SolidColorBrush Green = new(Color.FromArgb(255, 52, 199, 89));
12+
private static readonly SolidColorBrush Red = new(Color.FromArgb(255, 255, 59, 48));
13+
private static readonly SolidColorBrush Gray = new(Color.FromArgb(255, 142, 142, 147));
14+
15+
public object Convert(object value, Type targetType, object parameter, string language)
16+
{
17+
if (value is not AgentConnectionStatus status) return Gray;
18+
19+
return status switch
20+
{
21+
AgentConnectionStatus.Green => Green,
22+
AgentConnectionStatus.Red => Red,
23+
_ => Gray,
24+
};
25+
}
26+
27+
public object ConvertBack(object value, Type targetType, object parameter, string language)
28+
{
29+
throw new NotImplementedException();
30+
}
31+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using DependencyPropertyGenerator;
3+
using Microsoft.UI.Xaml;
4+
using Microsoft.UI.Xaml.Data;
5+
6+
namespace Coder.Desktop.App.Converters;
7+
8+
[DependencyProperty<object>("TrueValue", DefaultValue = true)]
9+
[DependencyProperty<object>("FalseValue", DefaultValue = true)]
10+
public partial class BoolToObjectConverter : DependencyObject, IValueConverter
11+
{
12+
public object Convert(object value, Type targetType, object parameter, string language)
13+
{
14+
return value is true ? TrueValue : FalseValue;
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, string language)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.UI.Xaml;
2+
3+
namespace Coder.Desktop.App.Converters;
4+
5+
public partial class BoolToVisibilityConverter : BoolToObjectConverter
6+
{
7+
public BoolToVisibilityConverter()
8+
{
9+
TrueValue = Visibility.Visible;
10+
FalseValue = Visibility.Collapsed;
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.UI.Xaml;
2+
3+
namespace Coder.Desktop.App.Converters;
4+
5+
public partial class InverseBoolToVisibilityConverter : BoolToObjectConverter
6+
{
7+
public InverseBoolToVisibilityConverter()
8+
{
9+
TrueValue = Visibility.Collapsed;
10+
FalseValue = Visibility.Visible;
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Coder.Desktop.App.Models;
3+
using DependencyPropertyGenerator;
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Data;
6+
7+
namespace Coder.Desktop.App.Converters;
8+
9+
[DependencyProperty<bool>("Starting", DefaultValue = false)]
10+
[DependencyProperty<bool>("Started", DefaultValue = false)]
11+
[DependencyProperty<bool>("Stopping", DefaultValue = false)]
12+
[DependencyProperty<bool>("Stopped", DefaultValue = false)]
13+
public partial class VpnLifecycleToBoolConverter : DependencyObject, IValueConverter
14+
{
15+
public object Convert(object value, Type targetType, object parameter, string language)
16+
{
17+
if (value is not VpnLifecycle lifecycle) return Stopped;
18+
19+
return lifecycle switch
20+
{
21+
VpnLifecycle.Starting => Starting,
22+
VpnLifecycle.Started => Started,
23+
VpnLifecycle.Stopping => Stopping,
24+
VpnLifecycle.Stopped => Stopped,
25+
_ => Visibility.Collapsed,
26+
};
27+
}
28+
29+
public object ConvertBack(object value, Type targetType, object parameter, string language)
30+
{
31+
throw new NotImplementedException();
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using Microsoft.UI.Xaml;
3+
using Microsoft.UI.Xaml.Data;
4+
5+
namespace Coder.Desktop.App.Converters;
6+
7+
public partial class VpnLifecycleToVisibilityConverter : VpnLifecycleToBoolConverter, IValueConverter
8+
{
9+
public new object Convert(object value, Type targetType, object parameter, string language)
10+
{
11+
var boolValue = base.Convert(value, targetType, parameter, language);
12+
return boolValue is true ? Visibility.Visible : Visibility.Collapsed;
13+
}
14+
}

App/DisplayScale.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
2+
using System.Runtime.InteropServices;
23
using Microsoft.UI.Xaml;
34
using WinRT.Interop;
4-
using System.Runtime.InteropServices;
55

66
namespace Coder.Desktop.App;
77

88
/// <summary>
9-
/// A static utility class to house methods related to the visual scale of the display monitor.
9+
/// A static utility class to house methods related to the visual scale of the display monitor.
1010
/// </summary>
1111
public static class DisplayScale
1212
{

App/Models/CredentialModel.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace Coder.Desktop.App.Models;
2+
3+
public enum CredentialState
4+
{
5+
Invalid,
6+
Valid,
7+
}
8+
9+
public class CredentialModel
10+
{
11+
public CredentialState State { get; set; } = CredentialState.Invalid;
12+
13+
public string? CoderUrl { get; set; }
14+
public string? ApiToken { get; set; }
15+
16+
public CredentialModel Clone()
17+
{
18+
return new CredentialModel
19+
{
20+
State = State,
21+
CoderUrl = CoderUrl,
22+
ApiToken = ApiToken,
23+
};
24+
}
25+
}

App/Models/RpcModel.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
3+
namespace Coder.Desktop.App.Models;
4+
5+
public enum RpcLifecycle
6+
{
7+
Disconnected,
8+
Connecting,
9+
Connected,
10+
}
11+
12+
public enum VpnLifecycle
13+
{
14+
Stopped,
15+
Starting,
16+
Started,
17+
Stopping,
18+
}
19+
20+
public class RpcModel
21+
{
22+
public RpcLifecycle RpcLifecycle { get; set; } = RpcLifecycle.Disconnected;
23+
24+
public VpnLifecycle VpnLifecycle { get; set; } = VpnLifecycle.Stopped;
25+
26+
public List<object> Agents { get; set; } = [];
27+
28+
public RpcModel Clone()
29+
{
30+
return new RpcModel
31+
{
32+
RpcLifecycle = RpcLifecycle,
33+
VpnLifecycle = VpnLifecycle,
34+
Agents = Agents,
35+
};
36+
}
37+
}

0 commit comments

Comments
 (0)