Add restart toggler on client.
This commit is contained in:
parent
eb15e46408
commit
b59d2727f3
@ -21,8 +21,10 @@ public partial class MainWindow : Window
|
||||
private ThreadWrapper wrapper;
|
||||
private Indicator trayIcon;
|
||||
private PopupMenu trayMenu;
|
||||
private Button restartToggleBtn;
|
||||
private bool ConnectedToVPN;
|
||||
private bool IsHidden;
|
||||
private bool RestartMode = false;
|
||||
public static readonly string MelonIconImg = "MiniMelonVPNIcon.png";
|
||||
public static readonly string MelonOnlineImg = "MiniMelonVPNOnline.png";
|
||||
|
||||
@ -77,6 +79,15 @@ public partial class MainWindow : Window
|
||||
refreshBtn.Clicked += OnRefreshClicked;
|
||||
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
|
||||
{
|
||||
Visible = true,
|
||||
@ -181,7 +192,7 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return "-";
|
||||
}
|
||||
|
||||
void StartupCheckMethod()
|
||||
@ -233,7 +244,7 @@ public partial class MainWindow : Window
|
||||
ConnectedToVPN = false;
|
||||
break;
|
||||
case ClientResponseState.Online:
|
||||
statusLabel.Text = "Online - " + GetVpnInternalIp();
|
||||
statusLabel.Text = "Online : " + GetVpnInternalIp();
|
||||
ConnectedToVPN = true;
|
||||
break;
|
||||
case ClientResponseState.Offline:
|
||||
@ -248,6 +259,14 @@ public partial class MainWindow : Window
|
||||
statusLabel.Text = "Restarting";
|
||||
ConnectedToVPN = true;
|
||||
break;
|
||||
case ClientResponseState.RestartOn:
|
||||
RestartMode = true;
|
||||
restartToggleBtn.Label = "Restart [#]";
|
||||
break;
|
||||
case ClientResponseState.RestartOff:
|
||||
RestartMode = false;
|
||||
restartToggleBtn.Label = "Restart [ ]";
|
||||
break;
|
||||
}
|
||||
if (ConnectedToVPN) UpdateIcon(MelonOnlineImg);
|
||||
else UpdateIcon(MelonIconImg);
|
||||
@ -394,4 +413,24 @@ public partial class MainWindow : Window
|
||||
};
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace MelonVPNCore
|
||||
{
|
||||
private static Process currentVpnProcess = null;
|
||||
private static bool shouldBeRunning = false;
|
||||
private static bool shouldRestart = true;
|
||||
private static bool shouldRestart = false;
|
||||
private static int startingTime = 3000;
|
||||
private static int restartDelay = 250;
|
||||
|
||||
@ -25,7 +25,7 @@ namespace MelonVPNCore
|
||||
{
|
||||
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
listener.Bind(localEndPoint);
|
||||
listener.Listen(10);
|
||||
listener.Listen(32);
|
||||
|
||||
string lastClientUpdate = Messages.EOF;
|
||||
|
||||
|
@ -9,7 +9,6 @@ namespace MelonVPNCore
|
||||
{
|
||||
public static event EventHandler<ClientResponseState> Receive;
|
||||
public static event EventHandler<ConnectedClient[]> ClientListUpdate;
|
||||
public static event EventHandler<bool> RestartModeSync;
|
||||
|
||||
public static void StartServer()
|
||||
{
|
||||
@ -21,7 +20,7 @@ namespace MelonVPNCore
|
||||
{
|
||||
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
listener.Bind(localEndPoint);
|
||||
listener.Listen(10);
|
||||
listener.Listen(32);
|
||||
|
||||
while (true)
|
||||
{
|
||||
@ -44,9 +43,8 @@ namespace MelonVPNCore
|
||||
if (data == Messages.ErrorMsg) ret = ClientResponseState.ServerError;
|
||||
if (data == Messages.StartingMsg) ret = ClientResponseState.Starting;
|
||||
if (data == Messages.RestartingMsg) ret = ClientResponseState.Restarting;
|
||||
bool rsm = false;
|
||||
if (data == Messages.RestartOnMsg) rsm = true;
|
||||
if (data == Messages.RestartOffMsg) rsm = false;
|
||||
if (data == Messages.RestartOnMsg) ret = ClientResponseState.RestartOn;
|
||||
if (data == Messages.RestartOffMsg) ret = ClientResponseState.RestartOff;
|
||||
Console.WriteLine(data);
|
||||
if (data.StartsWith(Messages.ClientListStartMsg, StringComparison.CurrentCulture))
|
||||
{
|
||||
@ -61,7 +59,6 @@ namespace MelonVPNCore
|
||||
handler.Close();
|
||||
|
||||
Receive?.Invoke(null, ret);
|
||||
RestartModeSync?.Invoke(null, rsm);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
Loading…
Reference in New Issue
Block a user