1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-25 14:46:08 +03:00
This commit is contained in:
nuxt-autumn 2021-05-16 16:29:37 +08:00
parent 3b79a7ca44
commit eeada87602
13 changed files with 230 additions and 28 deletions

View File

@ -56,6 +56,15 @@ namespace ProxySuper.Core.Models
await RaisePropertyChanged("Host");
}
if (Type == ProjectType.TrojanGo)
{
var result = await nav.Navigate<TrojanGoEditorViewModel, Record, Record>(this);
if (result == null) return;
this.Host = result.Host;
this.TrojanGoSettings = result.TrojanGoSettings;
}
}
}
}

View File

@ -85,6 +85,7 @@
<Compile Include="Services\XrayConfigBuilder.cs" />
<Compile Include="Services\XrayProject.cs" />
<Compile Include="ViewModels\HomeViewModel.cs" />
<Compile Include="ViewModels\TrojanGoEditorViewModel.cs" />
<Compile Include="ViewModels\XrayEditorViewModel.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -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<List<Record>>(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<Record> 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<TrojanGoEditorViewModel, Record, Record>(record);
if (result == null) return;
Records.Add(result);
}
}
}

View File

@ -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<Record, Record>
{
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,
});
}
}
}

View File

@ -19,12 +19,9 @@ namespace ProxySuper.Core.ViewModels
{
public partial class XrayEditorViewModel : MvxViewModel<Record, Record>
{
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

View File

@ -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">

View File

@ -85,6 +85,9 @@
<Compile Include="Views\HomeView.xaml.cs">
<DependentUpon>HomeView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\TrojanGoEditorView.xaml.cs">
<DependentUpon>TrojanGoEditorView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\XrayEditorView.xaml.cs">
<DependentUpon>XrayEditorView.xaml</DependentUpon>
</Compile>
@ -123,6 +126,10 @@
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
<Page Include="Views\TrojanGoEditorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\XrayEditorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -16,7 +16,7 @@
<Menu Background="White" Grid.Row="0" BorderThickness="0,0,0,2" BorderBrush="#eee">
<MenuItem Header="{DynamicResource MainMenuAddHost}" Padding="10,3">
<MenuItem Padding="0,5" Header="Xray" Command="{Binding AddXrayCommand}"></MenuItem>
<MenuItem Padding="0,5" Header="Trojan-Go"></MenuItem>
<MenuItem Padding="0,5" Header="Trojan-Go" Command="{Binding AddTrojanGoCommand}"></MenuItem>
<MenuItem Padding="0,5" Header="NaiveProxy"></MenuItem>
</MenuItem>

View File

@ -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<IMvxNavigationService>();
}
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<IMvxNavigationService>();
var vm = ViewModel as HomeViewModel;
navSrv.Navigate<XrayEditorViewModel, Record, Record>(vm.Records[0]);
NavigationService.Navigate<XrayEditorViewModel, Record, Record>(VM.Records[0]);
}
protected override void Dispose(bool disposing)
{
VM.SaveRecords();
base.Dispose(disposing);
}
}
}

View File

@ -0,0 +1,64 @@
<views:MvxWindow x:Class="ProxySuper.WPF.Views.TrojanGoEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:MvvmCross.Platforms.Wpf.Views;assembly=MvvmCross.Platforms.Wpf"
xmlns:local="clr-namespace:ProxySuper.WPF.Views"
xmlns:ctrl="clr-namespace:ProxySuper.WPF.Controls"
mc:Ignorable="d"
BorderThickness="0,1,0,0"
BorderBrush="#eee"
WindowStartupLocation="CenterScreen"
Title="Trojan-Go" Height="600" Width="1000">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="310" />
<ColumnDefinition Width="1" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="10">
<ctrl:HostControl />
</StackPanel>
<StackPanel Grid.Column="1" Background="#EEE"></StackPanel>
<StackPanel Grid.Column="2">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition Height="36" />
<RowDefinition Height="36" />
<RowDefinition Height="36" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Content="域名" Grid.Row="0" Grid.Column="0" />
<TextBox Text="{Binding Settings.Domain}" Grid.Row="0" Grid.Column="1" />
<Label Content="端口" Grid.Row="1" Grid.Column="0" />
<TextBox Text="{Binding Settings.Port}" Grid.Row="1" Grid.Column="1" />
<Label Content="密码" Grid.Row="2" Grid.Column="0" />
<TextBox Text="{Binding Settings.Password}" Grid.Row="2" Grid.Column="1" />
<Label Content="伪装域名" Grid.Row="3" Grid.Column="0" />
<TextBox Text="{Binding Settings.MaskDomain}" Grid.Row="3" Grid.Column="1" />
</Grid>
<Border BorderBrush="#eee" BorderThickness="0,1,0,0">
<Button Content="{DynamicResource Save}"
Command="{Binding SaveCommand}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Height="30"
Width="100"
Margin="40,20" />
</Border>
</StackPanel>
</Grid>
</views:MvxWindow>

View File

@ -0,0 +1,30 @@
using MvvmCross.Platforms.Wpf.Presenters.Attributes;
using MvvmCross.Platforms.Wpf.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ProxySuper.WPF.Views
{
/// <summary>
/// TrojanEditorView.xaml 的交互逻辑
/// </summary>
[MvxWindowPresentation(Identifier = nameof(XrayEditorView), Modal = true)]
public partial class TrojanGoEditorView : MvxWindow
{
public TrojanGoEditorView()
{
InitializeComponent();
}
}
}

View File

@ -11,7 +11,7 @@
Icon="/Resources/ProxySU.ico"
BorderThickness="0,1,0,0"
BorderBrush="#EEE"
Title="XrayEditorView" Height="610" Width="1015">
Title="Xray" Height="610" Width="1015">
<Grid>
<Grid.ColumnDefinitions>

View File

@ -1,4 +1,5 @@
using MvvmCross.Platforms.Wpf.Views;
using MvvmCross.Platforms.Wpf.Presenters.Attributes;
using MvvmCross.Platforms.Wpf.Views;
using System;
using System.Collections.Generic;
using System.Linq;
@ -18,6 +19,7 @@ namespace ProxySuper.WPF.Views
/// <summary>
/// XrayEditorView.xaml 的交互逻辑
/// </summary>
[MvxWindowPresentation(Identifier = nameof(XrayEditorView), Modal = true)]
public partial class XrayEditorView : MvxWindow
{
public XrayEditorView()