Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
next-autumn committed May 16, 2021
1 parent 3b79a7c commit eeada87
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 27 deletions.
9 changes: 9 additions & 0 deletions ProxySuper.Core/Models/Record.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public async Task NavigateToEditor()

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;
}
}
}
}
1 change: 1 addition & 0 deletions ProxySuper.Core/ProxySuper.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
24 changes: 23 additions & 1 deletion ProxySuper.Core/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -24,7 +25,7 @@ public HomeViewModel(IMvxNavigationService navigationService)
ReadRecords();
}

private void ReadRecords()
public void ReadRecords()
{
var json = File.ReadAllText("Data/Record.json");
var records = JsonConvert.DeserializeObject<List<Record>>(json);
Expand All @@ -40,10 +41,18 @@ private void ReadRecords()
});
}

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();
Expand All @@ -56,5 +65,18 @@ public async Task AddXrayRecord()

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);
}
}
}
54 changes: 54 additions & 0 deletions ProxySuper.Core/ViewModels/TrojanGoEditorViewModel.cs
Original file line number Diff line number Diff line change
@@ -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,
});
}
}


}
27 changes: 8 additions & 19 deletions ProxySuper.Core/ViewModels/XrayEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -34,7 +31,9 @@ public XrayEditorViewModel(IMvxNavigationService mvxNavigationService)

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)
{
Expand All @@ -46,28 +45,18 @@ public override void Prepare(Record parameter)

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
Expand Down
1 change: 0 additions & 1 deletion ProxySuper.WPF/Controls/HostControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">


Expand Down
7 changes: 7 additions & 0 deletions ProxySuper.WPF/ProxySuper.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion ProxySuper.WPF/Views/HomeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
31 changes: 28 additions & 3 deletions ProxySuper.WPF/Views/HomeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MvvmCross.Platforms.Wpf.Views;
using ProxySuper.Core.Models;
using ProxySuper.Core.ViewModels;
using System;
using System.Windows;

namespace ProxySuper.WPF.Views
Expand All @@ -18,17 +19,41 @@ public HomeView()
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");
}

private void NavToEditor(object sender, RoutedEventArgs e)
{
var navSrv = Mvx.IoCProvider.Resolve<IMvxNavigationService>();
NavigationService.Navigate<XrayEditorViewModel, Record, Record>(VM.Records[0]);
}

var vm = ViewModel as HomeViewModel;
navSrv.Navigate<XrayEditorViewModel, Record, Record>(vm.Records[0]);
protected override void Dispose(bool disposing)
{
VM.SaveRecords();
base.Dispose(disposing);
}

}
}
64 changes: 64 additions & 0 deletions ProxySuper.WPF/Views/TrojanGoEditorView.xaml
Original file line number Diff line number Diff line change
@@ -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>
30 changes: 30 additions & 0 deletions ProxySuper.WPF/Views/TrojanGoEditorView.xaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
2 changes: 1 addition & 1 deletion ProxySuper.WPF/Views/XrayEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Loading

0 comments on commit eeada87

Please sign in to comment.