diff --git a/App/App.csproj b/App/App.csproj index ca3d3c9..3ec9a25 100644 --- a/App/App.csproj +++ b/App/App.csproj @@ -36,6 +36,10 @@ false + + + + @@ -90,4 +94,10 @@ + + + + MSBuild:Compile + + diff --git a/App/App.xaml b/App/App.xaml index c614e0e..253b5ff 100644 --- a/App/App.xaml +++ b/App/App.xaml @@ -9,6 +9,8 @@ + diff --git a/App/Models/Settings.cs b/App/Models/Settings.cs index ec4c61b..814b6da 100644 --- a/App/Models/Settings.cs +++ b/App/Models/Settings.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace Coder.Desktop.App.Models; public interface ISettings : ICloneable @@ -34,6 +36,8 @@ public class CoderConnectSettings : ISettings /// public bool ConnectOnLaunch { get; set; } + public List PortForwards { get; set; } = []; + /// /// CoderConnect current settings version. Increment this when the settings schema changes. /// In future iterations we will be able to handle migrations when the user has @@ -60,3 +64,10 @@ public CoderConnectSettings Clone() return new CoderConnectSettings(Version, ConnectOnLaunch); } } + +public class PortForward +{ + public string Workspace { get; set; } = string.Empty; + public int LocalPort { get; set; } + public int RemotePort { get; set; } +} diff --git a/App/ViewModels/SettingsViewModel.cs b/App/ViewModels/SettingsViewModel.cs index 721ea95..b91db3e 100644 --- a/App/ViewModels/SettingsViewModel.cs +++ b/App/ViewModels/SettingsViewModel.cs @@ -1,8 +1,16 @@ using Coder.Desktop.App.Models; using Coder.Desktop.App.Services; +using Coder.Desktop.App.Views.Pages; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.Logging; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using static Coder.Desktop.App.Models.CoderConnectSettings; namespace Coder.Desktop.App.ViewModels; @@ -22,12 +30,19 @@ public partial class SettingsViewModel : ObservableObject private ISettingsManager _connectSettingsManager; private CoderConnectSettings _connectSettings = new CoderConnectSettings(); private IStartupManager _startupManager; + private IRpcController _rpcController; - public SettingsViewModel(ILogger logger, ISettingsManager settingsManager, IStartupManager startupManager) + private Window? _window; + + public IEnumerable PortForwards => _connectSettings.PortForwards; + + public SettingsViewModel(ILogger logger, ISettingsManager settingsManager, IStartupManager startupManager, + IRpcController rpcController) { _connectSettingsManager = settingsManager; _startupManager = startupManager; _logger = logger; + _rpcController = rpcController; _connectSettings = settingsManager.Read().GetAwaiter().GetResult(); StartOnLogin = startupManager.IsEnabled(); ConnectOnLaunch = _connectSettings.ConnectOnLaunch; @@ -43,6 +58,11 @@ public SettingsViewModel(ILogger logger, ISettingsManager(rpcModel.Agents.Count); + // Agents will only contain started agents. + foreach (var agent in rpcModel.Agents) + { + var fqdn = agent.Fqdn + .Select(a => a.Trim('.')) + .Where(a => !string.IsNullOrWhiteSpace(a)) + .Aggregate((a, b) => a.Count(c => c == '.') < b.Count(c => c == '.') ? a : b); + if (string.IsNullOrWhiteSpace(fqdn)) + continue; + hosts.Add(fqdn); + } + var dialog = new ContentDialog(); + + dialog.XamlRoot = _window?.Content.XamlRoot ?? throw new InvalidOperationException("Window content XamlRoot is null."); + dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style; + dialog.Title = "Save your work?"; + dialog.PrimaryButtonText = "Save"; + dialog.CloseButtonText = "Cancel"; + dialog.DefaultButton = ContentDialogButton.Primary; + dialog.Content = new PortForwardCreation(hosts); + + var result = await dialog.ShowAsync(); + + if (result == ContentDialogResult.Primary) + { + var portForwardCreation = dialog.Content as PortForwardCreation; + if (portForwardCreation != null) + { + _connectSettings.PortForwards.Add(portForwardCreation.PortForward); + _connectSettingsManager.Write(_connectSettings).GetAwaiter().GetResult(); + } + } + } } diff --git a/App/Views/Pages/PortForwardCreation.xaml b/App/Views/Pages/PortForwardCreation.xaml new file mode 100644 index 0000000..49c3a3a --- /dev/null +++ b/App/Views/Pages/PortForwardCreation.xaml @@ -0,0 +1,21 @@ + + + + + + + + + diff --git a/App/Views/Pages/PortForwardCreation.xaml.cs b/App/Views/Pages/PortForwardCreation.xaml.cs new file mode 100644 index 0000000..f143ba9 --- /dev/null +++ b/App/Views/Pages/PortForwardCreation.xaml.cs @@ -0,0 +1,24 @@ +using Coder.Desktop.App.Models; +using Microsoft.UI.Xaml.Controls; +using System.Collections.Generic; + +namespace Coder.Desktop.App.Views.Pages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class PortForwardCreation : Page + { + public PortForward PortForward { get; set; } = new(); + public List Hosts { get; set; } = []; + public PortForwardCreation() + { + InitializeComponent(); + } + + public PortForwardCreation(List hosts) : this() + { + Hosts = hosts; + } + } +} diff --git a/App/Views/Pages/SettingsMainPage.xaml b/App/Views/Pages/SettingsMainPage.xaml index 36b471d..d5f1d51 100644 --- a/App/Views/Pages/SettingsMainPage.xaml +++ b/App/Views/Pages/SettingsMainPage.xaml @@ -11,6 +11,7 @@ xmlns:ui="using:CommunityToolkit.WinUI" xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:controls="using:CommunityToolkit.WinUI.Controls" + xmlns:models="using:Coder.Desktop.App.Models" mc:Ignorable="d"> @@ -44,6 +45,28 @@ > + + + + + + + + + + + + + + + + diff --git a/App/Views/SettingsWindow.xaml b/App/Views/SettingsWindow.xaml index 512f0f5..f9e26f9 100644 --- a/App/Views/SettingsWindow.xaml +++ b/App/Views/SettingsWindow.xaml @@ -10,7 +10,7 @@ mc:Ignorable="d" Title="Coder Settings" Width="600" Height="350" - MinWidth="600" MinHeight="350"> + MinWidth="600" MinHeight="450"> diff --git a/App/Views/SettingsWindow.xaml.cs b/App/Views/SettingsWindow.xaml.cs index f2a0fdb..3577c7f 100644 --- a/App/Views/SettingsWindow.xaml.cs +++ b/App/Views/SettingsWindow.xaml.cs @@ -13,6 +13,7 @@ public sealed partial class SettingsWindow : WindowEx public SettingsWindow(SettingsViewModel viewModel) { ViewModel = viewModel; + ViewModel.Initialize(this); InitializeComponent(); TitleBarIcon.SetTitlebarIcon(this); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy