diff --git a/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs b/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs index 6e10b9b..3932650 100644 --- a/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs +++ b/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs @@ -8,6 +8,11 @@ namespace ProxySuper.Core.Models.Projects { public class TrojanGoSettings : IProjectSettings { + public TrojanGoSettings() + { + Port = 443; + } + public List FreePorts { get diff --git a/ProxySuper.Core/Models/Projects/XraySettings.cs b/ProxySuper.Core/Models/Projects/XraySettings.cs index 9fe47fc..d9fe96f 100644 --- a/ProxySuper.Core/Models/Projects/XraySettings.cs +++ b/ProxySuper.Core/Models/Projects/XraySettings.cs @@ -8,6 +8,34 @@ namespace ProxySuper.Core.Models.Projects { public partial class XraySettings : IProjectSettings { + public XraySettings() + { + var guid = Guid.NewGuid().ToString(); + Port = 443; + VLESS_KCP_Port = 2001; + VLESS_gRPC_Port = 2002; + VMESS_KCP_Port = 3001; + ShadowSocksPort = 4001; + + UUID = guid; + Types = new List(); + + VLESS_WS_Path = "/vlessws"; + VLESS_KCP_Type = "none"; + VLESS_KCP_Seed = guid; + VLESS_gRPC_ServiceName = "xray_gRPC"; + + VMESS_WS_Path = "/vmessws"; + VMESS_TCP_Path = "/vmesstcp"; + VMESS_KCP_Seed = guid; + VMESS_KCP_Type = "none"; + + TrojanPassword = guid; + + ShadowSocksPassword = guid; + ShadowSocksMethod = "aes-128-gcm"; + } + public List FreePorts { get diff --git a/ProxySuper.Core/Models/Record.cs b/ProxySuper.Core/Models/Record.cs index 8aacd44..2480b21 100644 --- a/ProxySuper.Core/Models/Record.cs +++ b/ProxySuper.Core/Models/Record.cs @@ -16,13 +16,24 @@ using System.Threading.Tasks; namespace ProxySuper.Core.Models { + [JsonObject] public class Record : MvxViewModel { + private Host _host; + [JsonProperty("id")] public string Id { get; set; } [JsonProperty("host")] - public Host Host { get; set; } + public Host Host + { + get { return _host; } + set + { + _host = value; + RaisePropertyChanged("Host"); + } + } [JsonProperty("settings")] public XraySettings XraySettings { get; set; } @@ -41,76 +52,6 @@ namespace ProxySuper.Core.Models } } - [JsonIgnore] - public IMvxNavigationService _navigationService; - [JsonIgnore] - public IMvxNavigationService NavigationService - { - get - { - if (_navigationService == null) - { - _navigationService = Mvx.IoCProvider.Resolve(); - } - return _navigationService; - } - } - - [JsonIgnore] - public IMvxCommand NavToInstallerCommand => new MvxAsyncCommand(NavigateToInstaller); - - [JsonIgnore] - public IMvxCommand NavToEditorCommand => new MvxAsyncCommand(NavigateToEditor); - - [JsonIgnore] - public IMvxCommand NavToConfigCommand => new MvxAsyncCommand(NavigateToConfig); - - public async Task NavigateToEditor() - { - if (Type == ProjectType.Xray) - { - var result = await NavigationService.Navigate(this); - if (result == null) return; - - this.Host = result.Host; - this.XraySettings = result.XraySettings; - - } - - if (Type == ProjectType.TrojanGo) - { - var result = await NavigationService.Navigate(this); - if (result == null) return; - - this.Host = result.Host; - this.TrojanGoSettings = result.TrojanGoSettings; - } - await RaisePropertyChanged("Host"); - } - - public async Task NavigateToInstaller() - { - if (Type == ProjectType.Xray) - { - await NavigationService.Navigate(this); - } - if (Type == ProjectType.TrojanGo) - { - await NavigationService.Navigate(this); - } - } - - public async Task NavigateToConfig() - { - if (Type == ProjectType.Xray) - { - await NavigationService.Navigate(this.XraySettings); - } - if (Type == ProjectType.TrojanGo) - { - await NavigationService.Navigate(this.TrojanGoSettings); - } - } } } diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs index 4f09de9..055f46f 100644 --- a/ProxySuper.Core/ViewModels/HomeViewModel.cs +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -2,6 +2,7 @@ using MvvmCross.Navigation; using MvvmCross.ViewModels; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using ProxySuper.Core.Models; using ProxySuper.Core.Models.Hosts; using ProxySuper.Core.Models.Projects; @@ -12,6 +13,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using System.Windows; namespace ProxySuper.Core.ViewModels { @@ -23,17 +25,9 @@ namespace ProxySuper.Core.ViewModels { _navigationService = navigationService; ReadRecords(); - _navigationService.AfterClose += _navigationService_AfterClose; } - private void _navigationService_AfterClose(object sender, MvvmCross.Navigation.EventArguments.IMvxNavigateEventArgs e) - { - if (e.ViewModel is XrayEditorViewModel || - e.ViewModel is TrojanGoEditorViewModel) - { - SaveToJson(); - } - } + public void ReadRecords() { @@ -58,7 +52,10 @@ namespace ProxySuper.Core.ViewModels public void SaveToJson() { - var json = JsonConvert.SerializeObject(this); + var json = JsonConvert.SerializeObject(Records, Formatting.Indented, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }); File.WriteAllText("Data/Record.json", json); } @@ -68,6 +65,14 @@ namespace ProxySuper.Core.ViewModels public IMvxCommand AddTrojanGoCommand => new MvxAsyncCommand(AddTrojanGoRecord); + public IMvxCommand RemoveCommand => new MvxAsyncCommand(DeleteRecord); + + public IMvxCommand EditCommand => new MvxAsyncCommand(EditRecord); + + public IMvxCommand ViewConfigCommand => new MvxAsyncCommand(ViewConfig); + + public IMvxCommand InstallCommand => new MvxAsyncCommand(GoToInstall); + public async Task AddXrayRecord() { Record record = new Record(); @@ -80,8 +85,6 @@ namespace ProxySuper.Core.ViewModels Records.Add(result); SaveToJson(); - - } public async Task AddTrojanGoRecord() @@ -95,6 +98,74 @@ namespace ProxySuper.Core.ViewModels if (result == null) return; Records.Add(result); + + SaveToJson(); + } + + public async Task EditRecord(string id) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record == null) return; + + Record result = null; + if (record.Type == ProjectType.Xray) + { + result = await _navigationService.Navigate(record); + } + else + { + result = await _navigationService.Navigate(record); + } + if (result == null) return; + + record.Host = result.Host; + record.XraySettings = result.XraySettings; + SaveToJson(); + } + + public async Task DeleteRecord(string id) + { + var result = MessageBox.Show($"您确认删除主机吗?", "提示", MessageBoxButton.OKCancel); + if (result == MessageBoxResult.OK) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record != null) + { + Records.Remove(record); + SaveToJson(); + } + } + await Task.CompletedTask; + } + + public async Task ViewConfig(string id) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record == null) return; + + if (record.Type == ProjectType.Xray) + { + await _navigationService.Navigate(record.XraySettings); + } + if (record.Type == ProjectType.TrojanGo) + { + await _navigationService.Navigate(record.TrojanGoSettings); + } + } + + public async Task GoToInstall(string id) + { + var record = Records.FirstOrDefault(x => x.Id == id); + if (record == null) return; + + if (record.Type == ProjectType.Xray) + { + await _navigationService.Navigate(record); + } + if (record.Type == ProjectType.TrojanGo) + { + await _navigationService.Navigate(record); + } } } } diff --git a/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs b/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs index d96a841..8074b25 100644 --- a/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs +++ b/ProxySuper.Core/ViewModels/XrayInstallerViewModel.cs @@ -43,5 +43,7 @@ namespace ProxySuper.Core.ViewModels } public string CommandText { get; set; } + + public string OutputText { get; set; } } } diff --git a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml index 7d0a7e7..ec97a36 100644 --- a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml +++ b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml @@ -15,7 +15,7 @@ 导出配置 导出配置 - 语言 + 语言(Language) English 中文 帮助 diff --git a/ProxySuper.WPF/Views/HomeView.xaml b/ProxySuper.WPF/Views/HomeView.xaml index 8784b99..7c1578d 100644 --- a/ProxySuper.WPF/Views/HomeView.xaml +++ b/ProxySuper.WPF/Views/HomeView.xaml @@ -20,10 +20,10 @@ - + @@ -53,37 +53,50 @@ + Width="120"> + + + + + Width="200"> + + + + + Width="200"> + + + + -