Very shitty commit
This commit is contained in:
@ -23,5 +23,9 @@
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="ReactiveUI.Avalonia" Version="11.3.8"/>
|
||||
<PackageReference Include="ReactiveUI.SourceGenerators" Version="2.5.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,6 +1,120 @@
|
||||
namespace MicrosocksGUI.ViewModels;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
namespace MicrosocksGUI.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
public string Greeting { get; } = "Welcome to Avalonia!";
|
||||
[Reactive] private bool _isWorking;
|
||||
[Reactive] private bool _isAutoloading;
|
||||
[Reactive] private string? _ip;
|
||||
[Reactive] private string? _port;
|
||||
|
||||
private Timer _timer;
|
||||
|
||||
private ProcessStartInfo _getStatusProcessInfo = new()
|
||||
{
|
||||
FileName = ".\\nssm.exe",
|
||||
Arguments = "status Microsocks",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(".")
|
||||
};
|
||||
|
||||
private ProcessStartInfo _getStartTypeProcessInfo = new()
|
||||
{
|
||||
FileName = ".\\nssm.exe",
|
||||
Arguments = "get Microsocks Start",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(".")
|
||||
};
|
||||
|
||||
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
// TODO Костыль, таймер запускается через секунду, а должен после инициализации ReactiveUI
|
||||
_timer = new Timer(GetWorkingStatusFromService, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(100));
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private async Task SetWorkingStatusToService()
|
||||
{
|
||||
|
||||
var args = _isWorking ? "start Microsocks" : "stop Microsocks";
|
||||
|
||||
|
||||
ProcessStartInfo processInfo = new()
|
||||
{
|
||||
FileName = ".\\nssm.exe",
|
||||
Arguments = args,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(".")
|
||||
};
|
||||
|
||||
using var process = new Process();
|
||||
process.StartInfo = processInfo;
|
||||
process.Start();
|
||||
}
|
||||
|
||||
private async void GetWorkingStatusFromService(object? state)
|
||||
{
|
||||
using (Process process = new Process())
|
||||
{
|
||||
process.StartInfo = _getStatusProcessInfo;
|
||||
process.Start();
|
||||
|
||||
|
||||
var output = await process.StandardOutput.ReadToEndAsync();
|
||||
var error = await process.StandardError.ReadToEndAsync();
|
||||
|
||||
await process.WaitForExitAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
//Console.WriteLine(error);
|
||||
}
|
||||
|
||||
//Console.WriteLine(output.Replace("\0", "").Trim());
|
||||
|
||||
if (output.Replace("\0", "").Trim() == "SERVICE_RUNNING")
|
||||
{
|
||||
//Console.WriteLine("yes");
|
||||
//IsWorking = true;
|
||||
}
|
||||
|
||||
IsWorking = output.Replace("\0", "").Trim() == "SERVICE_RUNNING";
|
||||
}
|
||||
|
||||
using (Process process = new Process())
|
||||
{
|
||||
process.StartInfo = _getStartTypeProcessInfo;
|
||||
process.Start();
|
||||
|
||||
var output = await process.StandardOutput.ReadToEndAsync();
|
||||
var error = await process.StandardError.ReadToEndAsync();
|
||||
|
||||
await process.WaitForExitAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
Console.WriteLine(error);
|
||||
}
|
||||
|
||||
IsAutoloading = output.Replace("\0", "").Trim() == "SERVICE_AUTO_START";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,14 +27,17 @@
|
||||
<ToggleButton
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">
|
||||
HorizontalContentAlignment="Center"
|
||||
IsChecked="{Binding IsWorking}"
|
||||
Command="{Binding SetWorkingStatusToServiceCommand}">
|
||||
Работа
|
||||
</ToggleButton>
|
||||
|
||||
<ToggleButton
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Center">
|
||||
HorizontalContentAlignment="Center"
|
||||
IsChecked="{Binding IsAutoloading}">
|
||||
Автозапуск
|
||||
</ToggleButton>
|
||||
</Grid>
|
||||
@ -43,12 +46,12 @@
|
||||
|
||||
<StackPanel>
|
||||
<TextBlock Text="IP Aдрес:" FontSize="12"/>
|
||||
<TextBox></TextBox>
|
||||
<TextBox Text="{Binding Ip}"></TextBox>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel>
|
||||
<TextBlock Text="Порт:" FontSize="12"/>
|
||||
<TextBox></TextBox>
|
||||
<TextBox Text="{Binding Port}"></TextBox>
|
||||
</StackPanel>
|
||||
|
||||
<Grid ColumnDefinitions="*, *" ColumnSpacing="5">
|
||||
|
||||
Reference in New Issue
Block a user