1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-21 20:56:08 +03:00

fix some issue

This commit is contained in:
nuxt-autumn 2021-05-23 14:24:13 +08:00
parent 970843f561
commit b71d1f2bc2
8 changed files with 157 additions and 96 deletions

View File

@ -8,6 +8,11 @@ namespace ProxySuper.Core.Models.Projects
{
public class TrojanGoSettings : IProjectSettings
{
public TrojanGoSettings()
{
Port = 443;
}
public List<int> FreePorts
{
get

View File

@ -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<XrayType>();
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<int> FreePorts
{
get

View File

@ -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<IMvxNavigationService>();
}
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<XrayEditorViewModel, Record, Record>(this);
if (result == null) return;
this.Host = result.Host;
this.XraySettings = result.XraySettings;
}
if (Type == ProjectType.TrojanGo)
{
var result = await NavigationService.Navigate<TrojanGoEditorViewModel, Record, Record>(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<XrayInstallerViewModel, Record>(this);
}
if (Type == ProjectType.TrojanGo)
{
await NavigationService.Navigate<TrojanGoInstallerViewModel, Record>(this);
}
}
public async Task NavigateToConfig()
{
if (Type == ProjectType.Xray)
{
await NavigationService.Navigate<XrayConfigViewModel, XraySettings>(this.XraySettings);
}
if (Type == ProjectType.TrojanGo)
{
await NavigationService.Navigate<TrojanGoConfigViewModel, TrojanGoSettings>(this.TrojanGoSettings);
}
}
}
}

View File

@ -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<string>(DeleteRecord);
public IMvxCommand EditCommand => new MvxAsyncCommand<string>(EditRecord);
public IMvxCommand ViewConfigCommand => new MvxAsyncCommand<string>(ViewConfig);
public IMvxCommand InstallCommand => new MvxAsyncCommand<string>(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<XrayEditorViewModel, Record, Record>(record);
}
else
{
result = await _navigationService.Navigate<TrojanGoEditorViewModel, Record, Record>(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<XrayConfigViewModel, XraySettings>(record.XraySettings);
}
if (record.Type == ProjectType.TrojanGo)
{
await _navigationService.Navigate<TrojanGoConfigViewModel, TrojanGoSettings>(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<XrayInstallerViewModel, Record>(record);
}
if (record.Type == ProjectType.TrojanGo)
{
await _navigationService.Navigate<TrojanGoInstallerViewModel, Record>(record);
}
}
}
}

View File

@ -43,5 +43,7 @@ namespace ProxySuper.Core.ViewModels
}
public string CommandText { get; set; }
public string OutputText { get; set; }
}
}

View File

@ -15,7 +15,7 @@
<sys:String x:Key="MainMenuActionsExportSettings">导出配置</sys:String>
<sys:String x:Key="MainMenuActionsExportSubscribe">导出配置</sys:String>
<sys:String x:Key="MainMenuLanguage">语言</sys:String>
<sys:String x:Key="MainMenuLanguage">语言(Language)</sys:String>
<sys:String x:Key="MainMenuLanguageEn">English</sys:String>
<sys:String x:Key="MainMenuLanguageCn">中文</sys:String>
<sys:String x:Key="MainMenuHelper">帮助</sys:String>

View File

@ -20,10 +20,10 @@
<MenuItem Padding="0,5" Header="NaiveProxy"></MenuItem>
</MenuItem>
<MenuItem Header="{DynamicResource MainMenuActions}" Padding="10,3">
<!--<MenuItem Header="{DynamicResource MainMenuActions}" Padding="10,3">
<MenuItem Padding="0,5" Header="{DynamicResource MainMenuActionsExportSettings}"></MenuItem>
<MenuItem Padding="0,5" Header="{DynamicResource MainMenuActionsExportSubscribe}"></MenuItem>
</MenuItem>
</MenuItem>-->
<MenuItem Header="{DynamicResource MainMenuLanguage}" Padding="10,3">
<MenuItem Padding="0,5" Header="{DynamicResource MainMenuLanguageEn}" Click="SetEnglish"></MenuItem>
@ -53,37 +53,50 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Host.Tag}"
Header="{DynamicResource MainDataGridColumnTag}"
Width="120" />
Width="120">
<DataGridTextColumn.Header>
<TextBlock Text="{DynamicResource MainDataGridColumnTag}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Host.Address}"
Header="{DynamicResource MainDataGridColumnAddress}"
Width="200" />
Width="200">
<DataGridTextColumn.Header>
<TextBlock Text="{DynamicResource MainDataGridColumnAddress}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Type}"
Header="{DynamicResource MainDataGridColumnType}"
Width="200" />
Width="200">
<DataGridTextColumn.Header>
<TextBlock Text="{DynamicResource MainDataGridColumnType}" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTemplateColumn Header="{DynamicResource MainDataGridColumnAction}" Width="400">
<DataGridTemplateColumn.CellTemplate>
<ItemContainerTemplate>
<StackPanel Orientation="Horizontal">
<Button Command="{Binding NavToInstallerCommand}"
<Button Command="{Binding DataContext.InstallCommand,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"
CommandParameter="{Binding Id}"
Margin="5,0"
Padding="12,3"
Content="{DynamicResource MainDataGridColumnActionInstall}" />
<Button Command="{Binding NavToEditorCommand}"
<Button Command="{Binding DataContext.EditCommand,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"
CommandParameter="{Binding Id}"
Margin="5,0"
Padding="12,3"
Content="{DynamicResource MainDataGridColumnActionEdit}" />
<Button Command="{Binding NavToConfigCommand}"
<Button Command="{Binding DataContext.ViewConfigCommand,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"
CommandParameter="{Binding Id}"
Margin="5,0"
Padding="12,3"
Content="{DynamicResource MainDataGridColumnActionViewConfig}" />
<Button Command="{Binding NavToEditorCommand}"
<Button Command="{Binding DataContext.RemoveCommand,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"
CommandParameter="{Binding Id}"
Margin="5,0"
Padding="12,3"
Content="{DynamicResource MainDataGridColumnActionDelete}" />

View File

@ -74,6 +74,7 @@ namespace ProxySuper.WPF.Views
outShell += "\n";
}
ViewModel.OutputText += outShell;
Dispatcher.Invoke(() =>
{
OutputTextBox.AppendText(outShell);