Some minor improvements
This commit is contained in:
parent
d6116f45b8
commit
080b1e8b2c
@ -22,6 +22,7 @@ public partial class MainWindow : Window
|
||||
private Indicator trayIcon;
|
||||
private PopupMenu trayMenu;
|
||||
private bool ConnectedToVPN;
|
||||
private bool IsHidden;
|
||||
public static readonly string MelonIconImg = "MiniMelonVPNIcon.png";
|
||||
public static readonly string MelonOnlineImg = "MiniMelonVPNOnline.png";
|
||||
|
||||
@ -122,8 +123,8 @@ public partial class MainWindow : Window
|
||||
|
||||
private void OnActivateTrayIcon()
|
||||
{
|
||||
Visible = !Visible;
|
||||
UpdateTrayMenu();
|
||||
if (IsHidden) JumpFromTray();
|
||||
else SendToTray();
|
||||
}
|
||||
|
||||
void OnToggleMenuItem()
|
||||
@ -134,7 +135,7 @@ public partial class MainWindow : Window
|
||||
|
||||
void UpdateTrayMenu()
|
||||
{
|
||||
if (trayMenu != null) trayMenu.Update(ConnectedToVPN, Visible);
|
||||
if (trayMenu != null) trayMenu.Update(ConnectedToVPN, !IsHidden);
|
||||
}
|
||||
|
||||
void UpdateIcon(string file)
|
||||
@ -249,23 +250,18 @@ public partial class MainWindow : Window
|
||||
{
|
||||
if (old != current)
|
||||
{
|
||||
if (current == true)
|
||||
{
|
||||
Notification pop = new Notification("Melon VPN", "Connected to the VPN");
|
||||
pop.Show();
|
||||
CloseNotificationAfterWait(pop, 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
Notification pop = new Notification("Melon VPN", "Disconnected from the VPN");
|
||||
pop.Show();
|
||||
CloseNotificationAfterWait(pop, 1000);
|
||||
}
|
||||
string msg = (current ? "Connected to" : "Disconnected from")+" the VPN";
|
||||
string icon = "/usr/lib/melon-vpn/MiniMelonVPN" + (current ? "Online" : "Icon") + ".png";
|
||||
Notification pop = new Notification("Melon VPN", msg, icon);
|
||||
pop.Show();
|
||||
CloseNotificationAfterWait(pop, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
void CloseNotificationAfterWait(Notification pop, int timeout)
|
||||
{
|
||||
// Close the notification after a wait
|
||||
// so it doesn't hang around
|
||||
Thread wait = new Thread(() =>
|
||||
{
|
||||
Thread.Sleep(timeout);
|
||||
@ -277,24 +273,75 @@ public partial class MainWindow : Window
|
||||
wait.Start();
|
||||
}
|
||||
|
||||
void SendToTray()
|
||||
{
|
||||
IsHidden = true;
|
||||
|
||||
// Try hiding the window
|
||||
Iconify();
|
||||
SkipPagerHint = true;
|
||||
SkipTaskbarHint = true;
|
||||
|
||||
// Changing the visible property needs to be
|
||||
// delayed for the window to start minimizing
|
||||
Thread thread = new Thread(() =>
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
Visible = false;
|
||||
})
|
||||
{
|
||||
IsBackground = true
|
||||
};
|
||||
thread.Start();
|
||||
|
||||
UpdateTrayMenu();
|
||||
}
|
||||
|
||||
void JumpFromTray()
|
||||
{
|
||||
IsHidden = false;
|
||||
|
||||
Visible = true;
|
||||
SkipPagerHint = false;
|
||||
SkipTaskbarHint = false;
|
||||
|
||||
// Just wait before triggering these to get
|
||||
// the right effect
|
||||
Thread thread = new Thread(() =>
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
// Deiconify and Present seem to do the same
|
||||
// thing but sometimes Deiconify doesn't work
|
||||
Deiconify();
|
||||
Present();
|
||||
})
|
||||
{
|
||||
IsBackground = true
|
||||
};
|
||||
thread.Start();
|
||||
|
||||
UpdateTrayMenu();
|
||||
}
|
||||
|
||||
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
|
||||
{
|
||||
if (ConnectedToVPN)
|
||||
{
|
||||
Visible = false;
|
||||
UpdateTrayMenu();
|
||||
}
|
||||
// Try to prevent destroying the tray icon
|
||||
// while connected to VPN
|
||||
if (ConnectedToVPN) SendToTray();
|
||||
else QuitApp();
|
||||
a.RetVal = true;
|
||||
}
|
||||
|
||||
protected void QuitApp()
|
||||
{
|
||||
// Kill this thread if it exists
|
||||
if (wrapper != null)
|
||||
{
|
||||
wrapper.Kill();
|
||||
wrapper.Join();
|
||||
}
|
||||
|
||||
// Destroy the tray icon first
|
||||
if (trayIcon != null) trayIcon.Dispose();
|
||||
Application.Quit();
|
||||
}
|
||||
@ -339,9 +386,4 @@ public partial class MainWindow : Window
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void OnViewClientsClicked(object sender, EventArgs e)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
</configuration>
|
||||
<import>
|
||||
<widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
|
||||
<widget-library name="../net-libs/appindicator3-sharp.dll" />
|
||||
<widget-library name="../bin/Release/MelonVPNClient.exe" internal="true" />
|
||||
</import>
|
||||
<widget class="Gtk.Window" id="MainWindow" design-size="204 86">
|
||||
|
Loading…
Reference in New Issue
Block a user