use pep8 style private naming and remove this.

This commit is contained in:
mshafer1
2024-12-21 07:51:57 -06:00
parent 8203e6c112
commit 934edb79eb
2 changed files with 86 additions and 86 deletions

View File

@@ -16,7 +16,7 @@ namespace ntfysh_client
private readonly NotificationListener _notificationListener; private readonly NotificationListener _notificationListener;
private bool _startInTray; private bool _startInTray;
private bool _trueExit; private bool _trueExit;
private NotificationDialog notificationDialog; private NotificationDialog _notificationDialog;
public MainForm(NotificationListener notificationListener, bool startInTray = false) public MainForm(NotificationListener notificationListener, bool startInTray = false)
{ {
@@ -34,7 +34,7 @@ namespace ntfysh_client
LoadSettings(); LoadSettings();
LoadTopics(); LoadTopics();
this.notificationDialog = new NotificationDialog(); _notificationDialog = new NotificationDialog();
} }
protected override void SetVisibleCore(bool value) protected override void SetVisibleCore(bool value)
@@ -79,12 +79,12 @@ namespace ntfysh_client
} }
else else
{ {
this.notificationDialog.ShowNotification( _notificationDialog.ShowNotification(
title: finalTitle, title: finalTitle,
message: e.Message, message: e.Message,
timeout_ms: (int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, timeout_ms: (int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds,
icon: priorityIcon, icon: priorityIcon,
showTimeOutBar: Program.Settings.CustomTrayNotificationsShowTimeoutBar showTimeOutBar: Program.Settings.CustomTrayNotificationsShowTimeoutBar,
showInDarkMode: Program.Settings.CustomTrayNotificationsShowInDarkMode showInDarkMode: Program.Settings.CustomTrayNotificationsShowInDarkMode
); );
} }

View File

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