1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-24 22:26:07 +03:00
ProxySU/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs

103 lines
2.9 KiB
C#
Raw Normal View History

2021-07-02 13:35:25 +03:00
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;
namespace ProxySuper.Core.ViewModels
{
public class BrookEditorViewModel : MvxViewModel<Record, Record>
{
2021-07-06 13:30:14 +03:00
public BrookEditorViewModel(IMvxNavigationService navigationService)
{
NavigationService = navigationService;
}
public IMvxNavigationService NavigationService { get; }
2021-07-02 13:35:25 +03:00
public string Id { get; set; }
public Host Host { get; set; }
public BrookSettings Settings { get; set; }
public List<string> BrookTypes
{
get
{
return new List<string> {
BrookType.server.ToString(),
BrookType.wsserver.ToString(),
BrookType.wssserver.ToString(),
2021-07-06 13:30:14 +03:00
BrookType.socks5.ToString(),
2021-07-02 13:35:25 +03:00
};
}
}
public string CheckedBrookType
{
get
{
return Settings.BrookType.ToString();
}
set
{
Settings.BrookType = (BrookType)Enum.Parse(typeof(BrookType), value);
2021-07-07 07:01:41 +03:00
if (Settings.BrookType == BrookType.wssserver)
{
Settings.Port = 443;
RaisePropertyChanged("Settings");
}
2021-07-02 13:35:25 +03:00
RaisePropertyChanged("EnablePort");
RaisePropertyChanged("EnableDomain");
2021-07-07 11:56:53 +03:00
RaisePropertyChanged("EnableIP");
2021-07-02 13:35:25 +03:00
}
}
public bool EnablePort => Settings.BrookType != BrookType.wssserver;
public bool EnableDomain => Settings.BrookType == BrookType.wssserver;
2021-07-07 11:56:53 +03:00
public bool EnableIP => Settings.BrookType != BrookType.wssserver;
2021-07-02 13:35:25 +03:00
public IMvxCommand SaveCommand => new MvxCommand(() => Save());
2021-08-19 12:54:23 +03:00
public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall);
2021-07-02 13:35:25 +03:00
public override void Prepare(Record parameter)
{
var record = Utils.DeepClone(parameter);
Id = record.Id;
Host = record.Host;
Settings = record.BrookSettings;
}
public void Save()
{
NavigationService.Close(this, new Record()
{
Id = Id,
Host = Host,
BrookSettings = Settings,
});
}
2021-08-19 12:54:23 +03:00
private void SaveAndInstall()
{
var record = new Record
{
Id = this.Id,
Host = this.Host,
BrookSettings = Settings,
};
NavigationService.Close(this, record);
NavigationService.Navigate<BrookInstallViewModel, Record>(record);
}
2021-07-02 13:35:25 +03:00
}
}