Minor improvements to the hide and show effect

This commit is contained in:
Melon 2020-10-23 11:45:59 +01:00
parent 080b1e8b2c
commit ee26a51b34
3 changed files with 48 additions and 47 deletions

View File

@ -5,7 +5,7 @@ using System.Reflection;
using System.Threading;
using AppIndicator3;
using Gtk;
using MelonVPNClient;
using MelonVPNClient;
using MelonVPNCore;
using Notify;
@ -114,10 +114,10 @@ public partial class MainWindow : Window
startupCheckThread.Start();
trayMenu = new PopupMenu(OnActivateTrayIcon, OnToggleMenuItem, QuitApp);
trayIcon = new Indicator("melonvpn", "MiniMelonVPNIcon", (int)IndicatorCategory.ApplicationStatus)
{
Menu = trayMenu.GetMenu(),
Status = (int)IndicatorStatus.Active
trayIcon = new Indicator("melonvpn", "MiniMelonVPNIcon", (int)IndicatorCategory.ApplicationStatus)
{
Menu = trayMenu.GetMenu(),
Status = (int)IndicatorStatus.Active
};
}
@ -125,17 +125,17 @@ public partial class MainWindow : Window
{
if (IsHidden) JumpFromTray();
else SendToTray();
}
}
void OnToggleMenuItem()
{
if (ConnectedToVPN) OnStopClicked(this, new EventArgs());
else OnStartClicked(this, new EventArgs());
}
void UpdateTrayMenu()
{
if (trayMenu != null) trayMenu.Update(ConnectedToVPN, !IsHidden);
void UpdateTrayMenu()
{
if (trayMenu != null) trayMenu.Update(ConnectedToVPN, !IsHidden);
}
void UpdateIcon(string file)
@ -250,7 +250,7 @@ public partial class MainWindow : Window
{
if (old != current)
{
string msg = (current ? "Connected to" : "Disconnected from")+" the VPN";
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();
@ -258,22 +258,22 @@ public partial class MainWindow : Window
}
}
void CloseNotificationAfterWait(Notification pop, int timeout)
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);
pop.Close();
})
{
IsBackground = true
};
wait.Start();
// so it doesn't hang around
Thread wait = new Thread(() =>
{
Thread.Sleep(timeout);
pop.Close();
})
{
IsBackground = true
};
wait.Start();
}
void SendToTray()
void SendToTray()
{
IsHidden = true;
@ -286,41 +286,29 @@ public partial class MainWindow : Window
// delayed for the window to start minimizing
Thread thread = new Thread(() =>
{
Thread.Sleep(100);
Visible = false;
Thread.Sleep(100);
Visible = false;
})
{
IsBackground = true
};
thread.Start();
UpdateTrayMenu();
UpdateTrayMenu();
}
void JumpFromTray()
void JumpFromTray()
{
IsHidden = false;
Visible = true;
// Present triggers `Visible = true;`
// it is then called again once the window is visible
// so it triggers `Deiconify();`
Present();
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();
UpdateTrayMenu();
}
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
@ -382,8 +370,19 @@ public partial class MainWindow : Window
}
}
void OnRefreshClicked(object sender, EventArgs e)
void OnRefreshClicked(object sender, EventArgs e) => Refresh();
protected void OnVisibilityNotifyEvent(object o, VisibilityNotifyEventArgs args)
{
Refresh();
}
// Calling present again forces the window to `Deiconify();`
Thread thread = new Thread(() =>
{
Thread.Sleep(100);
Present();
})
{
IsBackground = true
};
thread.Start();
}
}

View File

@ -25,5 +25,6 @@ public partial class MainWindow
this.DefaultHeight = 86;
this.Show();
this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent);
this.VisibilityNotifyEvent += new global::Gtk.VisibilityNotifyEventHandler(this.OnVisibilityNotifyEvent);
}
}

View File

@ -13,6 +13,7 @@
<property name="Title" translatable="yes">MainWindow</property>
<property name="WindowPosition">CenterOnParent</property>
<signal name="DeleteEvent" handler="OnDeleteEvent" />
<signal name="VisibilityNotifyEvent" handler="OnVisibilityNotifyEvent" />
<child>
<widget class="Gtk.Fixed" id="fixed1">
<property name="MemberName" />