From eeada87602f538fc02dcda7613eb4142455b6953 Mon Sep 17 00:00:00 2001 From: nuxt-autumn Date: Sun, 16 May 2021 16:29:37 +0800 Subject: [PATCH] update --- ProxySuper.Core/Models/Record.cs | 9 +++ ProxySuper.Core/ProxySuper.Core.csproj | 1 + ProxySuper.Core/ViewModels/HomeViewModel.cs | 24 ++++++- .../ViewModels/TrojanGoEditorViewModel.cs | 54 ++++++++++++++++ .../ViewModels/XrayEditorViewModel.cs | 27 +++----- ProxySuper.WPF/Controls/HostControl.xaml | 1 - ProxySuper.WPF/ProxySuper.WPF.csproj | 7 ++ ProxySuper.WPF/Views/HomeView.xaml | 2 +- ProxySuper.WPF/Views/HomeView.xaml.cs | 33 ++++++++-- ProxySuper.WPF/Views/TrojanGoEditorView.xaml | 64 +++++++++++++++++++ .../Views/TrojanGoEditorView.xaml.cs | 30 +++++++++ ProxySuper.WPF/Views/XrayEditorView.xaml | 2 +- ProxySuper.WPF/Views/XrayEditorView.xaml.cs | 4 +- 13 files changed, 230 insertions(+), 28 deletions(-) create mode 100644 ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs create mode 100644 ProxySuper.WPF/Views/TrojanGoEditorView.xaml create mode 100644 ProxySuper.WPF/Views/TrojanGoEditorView.xaml.cs diff --git a/ProxySuper.Core/Models/Record.cs b/ProxySuper.Core/Models/Record.cs index 8b94828..992be07 100644 --- a/ProxySuper.Core/Models/Record.cs +++ b/ProxySuper.Core/Models/Record.cs @@ -56,6 +56,15 @@ namespace ProxySuper.Core.Models await RaisePropertyChanged("Host"); } + + if (Type == ProjectType.TrojanGo) + { + var result = await nav.Navigate(this); + if (result == null) return; + + this.Host = result.Host; + this.TrojanGoSettings = result.TrojanGoSettings; + } } } } diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj index a060376..a2ea264 100644 --- a/ProxySuper.Core/ProxySuper.Core.csproj +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -85,6 +85,7 @@ + diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs index fa20fc7..8cfb762 100644 --- a/ProxySuper.Core/ViewModels/HomeViewModel.cs +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -24,7 +25,7 @@ namespace ProxySuper.Core.ViewModels ReadRecords(); } - private void ReadRecords() + public void ReadRecords() { var json = File.ReadAllText("Data/Record.json"); var records = JsonConvert.DeserializeObject>(json); @@ -40,10 +41,18 @@ namespace ProxySuper.Core.ViewModels }); } + public void SaveRecords() + { + var json = JsonConvert.SerializeObject(Records); + File.WriteAllText("Data/Record.json", json); + } + public MvxObservableCollection Records { get; set; } public IMvxCommand AddXrayCommand => new MvxAsyncCommand(AddXrayRecord); + public IMvxCommand AddTrojanGoCommand => new MvxAsyncCommand(AddTrojanGoRecord); + public async Task AddXrayRecord() { Record record = new Record(); @@ -56,5 +65,18 @@ namespace ProxySuper.Core.ViewModels Records.Add(result); } + + public async Task AddTrojanGoRecord() + { + Record record = new Record(); + record.Id = Guid.NewGuid().ToString(); + record.Host = new Host(); + record.TrojanGoSettings = new TrojanGoSettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + } } } diff --git a/ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs b/ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs new file mode 100644 index 0000000..84b19f5 --- /dev/null +++ b/ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs @@ -0,0 +1,54 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class TrojanGoEditorViewModel : MvxViewModel + { + public TrojanGoEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + public IMvxNavigationService NavigationService { get; } + + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public string Id { get; set; } + + public Host Host { get; set; } + + public TrojanGoSettings Settings { get; set; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + + Id = record.Id; + Host = record.Host; + Settings = record.TrojanGoSettings; + } + + private void Save() + { + NavigationService.Close(this, new Record + { + Id = this.Id, + Host = this.Host, + TrojanGoSettings = Settings, + }); + } + } + + +} diff --git a/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs index c08dfc6..bc8c7b9 100644 --- a/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs +++ b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs @@ -19,12 +19,9 @@ namespace ProxySuper.Core.ViewModels { public partial class XrayEditorViewModel : MvxViewModel { - private IMvxNavigationService _navigationService; - public XrayEditorViewModel(IMvxNavigationService mvxNavigationService) + public XrayEditorViewModel(IMvxNavigationService navigationService) { - _navigationService = mvxNavigationService; - _randomUuid = new MvxCommand(() => GetUuid()); - SaveCommand = new MvxCommand(() => Save()); + NavigationService = navigationService; } @@ -34,7 +31,9 @@ namespace ProxySuper.Core.ViewModels public XraySettings Settings { get; set; } - public IMvxCommand SaveCommand { get; } + public IMvxCommand SaveCommand => new MvxCommand(() => Save()); + + public IMvxNavigationService NavigationService { get; } public override void Prepare(Record parameter) { @@ -46,28 +45,18 @@ namespace ProxySuper.Core.ViewModels public void Save() { - var result = new Record() + NavigationService.Close(this, new Record() { Id = Id, Host = Host, XraySettings = Settings, - }; - _navigationService.Close(this, result); + }); } } public partial class XrayEditorViewModel { - private readonly ICommand _randomUuid; - - - public ICommand RandomUuid - { - get - { - return _randomUuid; - } - } + public IMvxCommand RandomUuid => new MvxCommand(() => GetUuid()); public int Port diff --git a/ProxySuper.WPF/Controls/HostControl.xaml b/ProxySuper.WPF/Controls/HostControl.xaml index 0515293..b86fb33 100644 --- a/ProxySuper.WPF/Controls/HostControl.xaml +++ b/ProxySuper.WPF/Controls/HostControl.xaml @@ -6,7 +6,6 @@ xmlns:local="clr-namespace:ProxySuper.WPF.Controls" xmlns:convert="clr-namespace:ProxySuper.Core.Converters;assembly=ProxySuper.Core" xmlns:host="clr-namespace:ProxySuper.Core.Models.Hosts;assembly=ProxySuper.Core" - mc:Ignorable="d"> diff --git a/ProxySuper.WPF/ProxySuper.WPF.csproj b/ProxySuper.WPF/ProxySuper.WPF.csproj index afc069c..03bb44f 100644 --- a/ProxySuper.WPF/ProxySuper.WPF.csproj +++ b/ProxySuper.WPF/ProxySuper.WPF.csproj @@ -85,6 +85,9 @@ HomeView.xaml + + TrojanGoEditorView.xaml + XrayEditorView.xaml @@ -123,6 +126,10 @@ MSBuild:Compile PreserveNewest + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ProxySuper.WPF/Views/HomeView.xaml b/ProxySuper.WPF/Views/HomeView.xaml index 7203623..dc91294 100644 --- a/ProxySuper.WPF/Views/HomeView.xaml +++ b/ProxySuper.WPF/Views/HomeView.xaml @@ -16,7 +16,7 @@ - + diff --git a/ProxySuper.WPF/Views/HomeView.xaml.cs b/ProxySuper.WPF/Views/HomeView.xaml.cs index 78a45e0..737abd4 100644 --- a/ProxySuper.WPF/Views/HomeView.xaml.cs +++ b/ProxySuper.WPF/Views/HomeView.xaml.cs @@ -3,6 +3,7 @@ using MvvmCross.Navigation; using MvvmCross.Platforms.Wpf.Views; using ProxySuper.Core.Models; using ProxySuper.Core.ViewModels; +using System; using System.Windows; namespace ProxySuper.WPF.Views @@ -18,6 +19,26 @@ namespace ProxySuper.WPF.Views InitializeComponent(); } + private IMvxNavigationService _navigationService; + + public IMvxNavigationService NavigationService + { + get + { + if (_navigationService == null) + { + _navigationService = Mvx.IoCProvider.Resolve(); + } + return _navigationService; + } + + } + + public HomeViewModel VM + { + get { return (HomeViewModel)ViewModel; } + } + private void LaunchGitHubSite(object sender, RoutedEventArgs e) { System.Diagnostics.Process.Start("explorer.exe", "https://github.com/proxysu/ProxySU"); @@ -25,10 +46,14 @@ namespace ProxySuper.WPF.Views private void NavToEditor(object sender, RoutedEventArgs e) { - var navSrv = Mvx.IoCProvider.Resolve(); - - var vm = ViewModel as HomeViewModel; - navSrv.Navigate(vm.Records[0]); + NavigationService.Navigate(VM.Records[0]); } + + protected override void Dispose(bool disposing) + { + VM.SaveRecords(); + base.Dispose(disposing); + } + } } diff --git a/ProxySuper.WPF/Views/TrojanGoEditorView.xaml b/ProxySuper.WPF/Views/TrojanGoEditorView.xaml new file mode 100644 index 0000000..414fa0b --- /dev/null +++ b/ProxySuper.WPF/Views/TrojanGoEditorView.xaml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +