use pep8 style private naming and remove this.
This commit is contained in:
@@ -17,118 +17,118 @@ namespace ntfysh_client
|
||||
private const int ScreenMargin = 20;
|
||||
|
||||
private int _timeout = 0;
|
||||
private System.Timers.Timer? displayTimeoutTimer = null;
|
||||
private System.Windows.Forms.Timer? updateTimer = null;
|
||||
private Stopwatch? shownStopwatch = null;
|
||||
private System.Timers.Timer? _displayTimeoutTimer = null;
|
||||
private System.Windows.Forms.Timer? _updateTimer = null;
|
||||
private Stopwatch? _shownStopwatch = null;
|
||||
private ToolTipIcon? _icon;
|
||||
private int _progress_value = 0;
|
||||
private int progress
|
||||
{
|
||||
get { return this._progress_value; }
|
||||
get { return _progress_value; }
|
||||
set
|
||||
{
|
||||
this._progress_value = value;
|
||||
this.progressBar1.Value = value;
|
||||
_progress_value = value;
|
||||
progressBar1.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsVisible
|
||||
{
|
||||
get { return this.Visible; }
|
||||
set { this.Visible = value; }
|
||||
get { return Visible; }
|
||||
set { Visible = value; }
|
||||
}
|
||||
|
||||
public NotificationDialog()
|
||||
{
|
||||
this.ShowInTaskbar = false;
|
||||
this.IsVisible = false;
|
||||
this.TopMost = true;
|
||||
ShowInTaskbar = false;
|
||||
IsVisible = false;
|
||||
TopMost = true;
|
||||
InitializeComponent();
|
||||
InitializeWindowHidden();
|
||||
}
|
||||
|
||||
public void ShowNotification(string title, string message, int timeout_ms = -1, ToolTipIcon? icon = null, bool showTimeOutBar = true, bool showInDarkMode = true)
|
||||
{
|
||||
if (this.IsVisible)
|
||||
if (IsVisible)
|
||||
{
|
||||
// close the current notification
|
||||
this.handleTimeout(null, null);
|
||||
handleTimeout(null, null);
|
||||
}
|
||||
// setup data
|
||||
this._icon = icon;
|
||||
if (this._icon != null)
|
||||
_icon = icon;
|
||||
if (_icon != null)
|
||||
{
|
||||
this.iconBox.Image = ConvertToolTipIconToImage(_icon.Value);
|
||||
iconBox.Image = ConvertToolTipIconToImage(_icon.Value);
|
||||
}
|
||||
this.tbTitle.Text = title;
|
||||
this.tbMessage.Text = message;
|
||||
tbTitle.Text = title;
|
||||
tbMessage.Text = message;
|
||||
|
||||
// setup timers
|
||||
if (this.displayTimeoutTimer != null)
|
||||
if (_displayTimeoutTimer != null)
|
||||
{
|
||||
this.displayTimeoutTimer.Stop();
|
||||
this.displayTimeoutTimer.Dispose();
|
||||
_displayTimeoutTimer.Stop();
|
||||
_displayTimeoutTimer.Dispose();
|
||||
}
|
||||
if (this.updateTimer != null)
|
||||
if (_updateTimer != null)
|
||||
{
|
||||
this.updateTimer.Stop();
|
||||
this.updateTimer.Dispose();
|
||||
_updateTimer.Stop();
|
||||
_updateTimer.Dispose();
|
||||
}
|
||||
if (timeout_ms > 0)
|
||||
{
|
||||
this.displayTimeoutTimer = new System.Timers.Timer(timeout_ms);
|
||||
displayTimeoutTimer.Elapsed += handleTimeout;
|
||||
this.displayTimeoutTimer.Start();
|
||||
_displayTimeoutTimer = new System.Timers.Timer(timeout_ms);
|
||||
_displayTimeoutTimer.Elapsed += handleTimeout;
|
||||
_displayTimeoutTimer.Start();
|
||||
|
||||
if (showTimeOutBar)
|
||||
{
|
||||
this.progress = 100;
|
||||
this.updateTimer = new System.Windows.Forms.Timer();
|
||||
updateTimer.Interval = 100;
|
||||
this.updateTimer.Tick += this.UpdateProgress;
|
||||
this.updateTimer.Start();
|
||||
progress = 100;
|
||||
_updateTimer = new System.Windows.Forms.Timer();
|
||||
_updateTimer.Interval = 100;
|
||||
_updateTimer.Tick += UpdateProgress;
|
||||
_updateTimer.Start();
|
||||
|
||||
this.shownStopwatch = new Stopwatch();
|
||||
this.shownStopwatch.Start();
|
||||
_shownStopwatch = new Stopwatch();
|
||||
_shownStopwatch.Start();
|
||||
|
||||
this.progressBar1.Visible = true;
|
||||
this.lbTimeout.Visible = true;
|
||||
this._timeout = timeout_ms;
|
||||
progressBar1.Visible = true;
|
||||
lbTimeout.Visible = true;
|
||||
_timeout = timeout_ms;
|
||||
} else
|
||||
{
|
||||
this.progressBar1.Visible = false;
|
||||
this.lbTimeout.Visible = false;
|
||||
progressBar1.Visible = false;
|
||||
lbTimeout.Visible = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.progressBar1.Visible = false;
|
||||
this.lbTimeout.Visible = false;
|
||||
progressBar1.Visible = false;
|
||||
lbTimeout.Visible = false;
|
||||
}
|
||||
|
||||
// ok, show the window
|
||||
this.Show();
|
||||
this.SetWindowPosition();
|
||||
Show();
|
||||
SetWindowPosition();
|
||||
}
|
||||
|
||||
private void UpdateProgress(object? sender, EventArgs e)
|
||||
{
|
||||
if (this.shownStopwatch == null)
|
||||
if (_shownStopwatch == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.progress = (int)((this._timeout - this.shownStopwatch.ElapsedMilliseconds) * 100 / this._timeout);
|
||||
this.lbTimeout.Text = $"{(int)(this._timeout - this.shownStopwatch.ElapsedMilliseconds) / 1000}";
|
||||
progress = (int)((_timeout - _shownStopwatch.ElapsedMilliseconds) * 100 / _timeout);
|
||||
lbTimeout.Text = $"{(int)(_timeout - _shownStopwatch.ElapsedMilliseconds) / 1000}";
|
||||
}
|
||||
|
||||
protected override void SetVisibleCore(bool value)
|
||||
{
|
||||
this.SetWindowPosition();
|
||||
SetWindowPosition();
|
||||
if (value)
|
||||
{
|
||||
this.BringToFront();
|
||||
BringToFront();
|
||||
AnimateWindow(
|
||||
this.Handle,
|
||||
Handle,
|
||||
time: 250,
|
||||
flags: NFWinUserAnimateWindowConstnats.AW_SLIDE | NFWinUserAnimateWindowConstnats.AW_VER_NEGATIVE
|
||||
);
|
||||
@@ -143,35 +143,35 @@ namespace ntfysh_client
|
||||
|
||||
private void SetWindowPosition()
|
||||
{
|
||||
int workingtop = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
|
||||
this.Top = workingtop - NotificationDialog.ScreenMargin;
|
||||
int workingtop = Screen.PrimaryScreen.WorkingArea.Height - Height;
|
||||
Top = workingtop - NotificationDialog.ScreenMargin;
|
||||
|
||||
int workingleft = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
|
||||
this.Left = workingleft - NotificationDialog.ScreenMargin;
|
||||
int workingleft = Screen.PrimaryScreen.WorkingArea.Width - Width;
|
||||
Left = workingleft - NotificationDialog.ScreenMargin;
|
||||
}
|
||||
|
||||
private void ui_hide_window(object? sender, EventArgs? e)
|
||||
{
|
||||
AnimateWindow(
|
||||
this.Handle,
|
||||
Handle,
|
||||
time: 250,
|
||||
flags: NFWinUserAnimateWindowConstnats.AW_SLIDE | NFWinUserAnimateWindowConstnats.AW_VER_POSITIVE | NFWinUserAnimateWindowConstnats.AW_HIDE
|
||||
);
|
||||
this.IsVisible = false;
|
||||
IsVisible = false;
|
||||
}
|
||||
|
||||
private void handleTimeout(object? sender, EventArgs? e)
|
||||
{
|
||||
this.cancelTimer();
|
||||
if (this.InvokeRequired)
|
||||
cancelTimer();
|
||||
if (InvokeRequired)
|
||||
{
|
||||
// on a background thread, so invoke on the UI thread
|
||||
this.Invoke(new Action(() => this.ui_hide_window(sender, e)));
|
||||
Invoke(new Action(() => ui_hide_window(sender, e)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// in the UI thread, invoke directly
|
||||
this.ui_hide_window(sender, e);
|
||||
ui_hide_window(sender, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,16 +193,16 @@ namespace ntfysh_client
|
||||
|
||||
private void InitializeWindowHidden()
|
||||
{
|
||||
this.Opacity = 0;
|
||||
this.ShowNotification("Title", "Message");
|
||||
this.IsVisible = false;
|
||||
this.Opacity = 1;
|
||||
Opacity = 0;
|
||||
ShowNotification("Title", "Message");
|
||||
IsVisible = false;
|
||||
Opacity = 1;
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
// immediate
|
||||
this.IsVisible = false;
|
||||
IsVisible = false;
|
||||
}
|
||||
|
||||
private class NFWinUserAnimateWindowConstnats
|
||||
@@ -220,43 +220,43 @@ namespace ntfysh_client
|
||||
|
||||
private void window_MouseDown(object sender, EventArgs e)
|
||||
{
|
||||
this.cancelTimer();
|
||||
cancelTimer();
|
||||
}
|
||||
|
||||
private void cancelTimer()
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
if (InvokeRequired)
|
||||
{
|
||||
// on a background thread, so invoke on the UI thread
|
||||
this.Invoke(new Action(() =>
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.lbTimeout.Visible = false;
|
||||
this.progressBar1.Visible = false;
|
||||
lbTimeout.Visible = false;
|
||||
progressBar1.Visible = false;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
// in the UI thread, invoke directly
|
||||
this.lbTimeout.Visible = false;
|
||||
this.progressBar1.Visible = false;
|
||||
lbTimeout.Visible = false;
|
||||
progressBar1.Visible = false;
|
||||
}
|
||||
|
||||
if (this.displayTimeoutTimer != null) // check if the timer has already been disposed
|
||||
if (_displayTimeoutTimer != null) // check if the timer has already been disposed
|
||||
{
|
||||
this.displayTimeoutTimer.Stop();
|
||||
this.displayTimeoutTimer.Dispose();
|
||||
this.displayTimeoutTimer = null;
|
||||
_displayTimeoutTimer.Stop();
|
||||
_displayTimeoutTimer.Dispose();
|
||||
_displayTimeoutTimer = null;
|
||||
}
|
||||
if (this.updateTimer != null)
|
||||
if (_updateTimer != null)
|
||||
{
|
||||
this.updateTimer.Stop();
|
||||
this.updateTimer.Dispose();
|
||||
this.updateTimer = null;
|
||||
_updateTimer.Stop();
|
||||
_updateTimer.Dispose();
|
||||
_updateTimer = null;
|
||||
}
|
||||
if (this.shownStopwatch != null)
|
||||
if (_shownStopwatch != null)
|
||||
{
|
||||
this.shownStopwatch.Stop();
|
||||
this.shownStopwatch = null;
|
||||
_shownStopwatch.Stop();
|
||||
_shownStopwatch = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user