Add restart toggler on client.

This commit is contained in:
Captain ALM 2021-03-19 18:40:50 +00:00
parent eb15e46408
commit b59d2727f3
3 changed files with 46 additions and 10 deletions

View File

@ -21,8 +21,10 @@ public partial class MainWindow : Window
private ThreadWrapper wrapper; private ThreadWrapper wrapper;
private Indicator trayIcon; private Indicator trayIcon;
private PopupMenu trayMenu; private PopupMenu trayMenu;
private Button restartToggleBtn;
private bool ConnectedToVPN; private bool ConnectedToVPN;
private bool IsHidden; private bool IsHidden;
private bool RestartMode = false;
public static readonly string MelonIconImg = "MiniMelonVPNIcon.png"; public static readonly string MelonIconImg = "MiniMelonVPNIcon.png";
public static readonly string MelonOnlineImg = "MiniMelonVPNOnline.png"; public static readonly string MelonOnlineImg = "MiniMelonVPNOnline.png";
@ -77,6 +79,15 @@ public partial class MainWindow : Window
refreshBtn.Clicked += OnRefreshClicked; refreshBtn.Clicked += OnRefreshClicked;
fixed1.Put(refreshBtn, 190, 40); fixed1.Put(refreshBtn, 190, 40);
restartToggleBtn = new Button
{
Visible = true,
Label = "-"
};
restartToggleBtn.SetSizeRequest(80, 30);
restartToggleBtn.Clicked += RestartToggleBtn_Clicked;
fixed1.Put(restartToggleBtn, 190, 5);
clientsListText = new TextView clientsListText = new TextView
{ {
Visible = true, Visible = true,
@ -181,7 +192,7 @@ public partial class MainWindow : Window
} }
} }
} }
return ""; return "-";
} }
void StartupCheckMethod() void StartupCheckMethod()
@ -233,7 +244,7 @@ public partial class MainWindow : Window
ConnectedToVPN = false; ConnectedToVPN = false;
break; break;
case ClientResponseState.Online: case ClientResponseState.Online:
statusLabel.Text = "Online - " + GetVpnInternalIp(); statusLabel.Text = "Online : " + GetVpnInternalIp();
ConnectedToVPN = true; ConnectedToVPN = true;
break; break;
case ClientResponseState.Offline: case ClientResponseState.Offline:
@ -247,6 +258,14 @@ public partial class MainWindow : Window
case ClientResponseState.Restarting: case ClientResponseState.Restarting:
statusLabel.Text = "Restarting"; statusLabel.Text = "Restarting";
ConnectedToVPN = true; ConnectedToVPN = true;
break;
case ClientResponseState.RestartOn:
RestartMode = true;
restartToggleBtn.Label = "Restart [#]";
break;
case ClientResponseState.RestartOff:
RestartMode = false;
restartToggleBtn.Label = "Restart [ ]";
break; break;
} }
if (ConnectedToVPN) UpdateIcon(MelonOnlineImg); if (ConnectedToVPN) UpdateIcon(MelonOnlineImg);
@ -394,4 +413,24 @@ public partial class MainWindow : Window
}; };
thread.Start(); thread.Start();
} }
void RestartToggleBtn_Clicked(object sender, EventArgs e)
{
ClientResponseState s = (RestartMode) ? Client.SendDataMessage(DataMessage.RestartOff) : Client.SendDataMessage(DataMessage.RestartOn);
switch (s)
{
case ClientResponseState.Error:
case ClientResponseState.ServerError:
case ClientResponseState.RestartOn:
RestartMode = true;
restartToggleBtn.Label = "Restart [#]";
break;
case ClientResponseState.RestartOff:
RestartMode = false;
restartToggleBtn.Label = "Restart [ ]";
break;
}
}
} }

View File

@ -11,7 +11,7 @@ namespace MelonVPNCore
{ {
private static Process currentVpnProcess = null; private static Process currentVpnProcess = null;
private static bool shouldBeRunning = false; private static bool shouldBeRunning = false;
private static bool shouldRestart = true; private static bool shouldRestart = false;
private static int startingTime = 3000; private static int startingTime = 3000;
private static int restartDelay = 250; private static int restartDelay = 250;
@ -25,7 +25,7 @@ namespace MelonVPNCore
{ {
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(localEndPoint); listener.Bind(localEndPoint);
listener.Listen(10); listener.Listen(32);
string lastClientUpdate = Messages.EOF; string lastClientUpdate = Messages.EOF;

View File

@ -9,7 +9,6 @@ namespace MelonVPNCore
{ {
public static event EventHandler<ClientResponseState> Receive; public static event EventHandler<ClientResponseState> Receive;
public static event EventHandler<ConnectedClient[]> ClientListUpdate; public static event EventHandler<ConnectedClient[]> ClientListUpdate;
public static event EventHandler<bool> RestartModeSync;
public static void StartServer() public static void StartServer()
{ {
@ -21,7 +20,7 @@ namespace MelonVPNCore
{ {
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(localEndPoint); listener.Bind(localEndPoint);
listener.Listen(10); listener.Listen(32);
while (true) while (true)
{ {
@ -44,9 +43,8 @@ namespace MelonVPNCore
if (data == Messages.ErrorMsg) ret = ClientResponseState.ServerError; if (data == Messages.ErrorMsg) ret = ClientResponseState.ServerError;
if (data == Messages.StartingMsg) ret = ClientResponseState.Starting; if (data == Messages.StartingMsg) ret = ClientResponseState.Starting;
if (data == Messages.RestartingMsg) ret = ClientResponseState.Restarting; if (data == Messages.RestartingMsg) ret = ClientResponseState.Restarting;
bool rsm = false; if (data == Messages.RestartOnMsg) ret = ClientResponseState.RestartOn;
if (data == Messages.RestartOnMsg) rsm = true; if (data == Messages.RestartOffMsg) ret = ClientResponseState.RestartOff;
if (data == Messages.RestartOffMsg) rsm = false;
Console.WriteLine(data); Console.WriteLine(data);
if (data.StartsWith(Messages.ClientListStartMsg, StringComparison.CurrentCulture)) if (data.StartsWith(Messages.ClientListStartMsg, StringComparison.CurrentCulture))
{ {
@ -61,7 +59,6 @@ namespace MelonVPNCore
handler.Close(); handler.Close();
Receive?.Invoke(null, ret); Receive?.Invoke(null, ret);
RestartModeSync?.Invoke(null, rsm);
} }
} }
catch (Exception e) catch (Exception e)