Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
strayge committed Jan 7, 2018
1 parent 612f36b commit f4c4769
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 50 deletions.
6 changes: 0 additions & 6 deletions percentage/percentage/BatteryIcon.cs
Expand Up @@ -112,11 +112,5 @@ private static SizeF GetImageSize(string text, Font font)
using (Graphics graphics = Graphics.FromImage(image))
return graphics.MeasureString(text, font);
}

protected override void menuSettings_Click(object sender, EventArgs e)
{
base.menuSettings_Click(sender, e);
SetUpdateInterval(settings.updateInterval);
}
}
}
7 changes: 0 additions & 7 deletions percentage/percentage/CpuIcon.cs
Expand Up @@ -13,7 +13,6 @@ namespace percentage
class CpuIcon: TrayIcon
{
private SettingsCpu settings;

PerformanceCounter cpuCounter;
List<float> measurents = new List<float>();

Expand Down Expand Up @@ -76,11 +75,5 @@ public override void UpdateIcon(object sender, EventArgs e)
}
}
}

protected override void menuSettings_Click(object sender, EventArgs e)
{
base.menuSettings_Click(sender, e);
SetUpdateInterval(settings.updateInterval);
}
}
}
9 changes: 1 addition & 8 deletions percentage/percentage/NetworkIcon.cs
Expand Up @@ -13,9 +13,7 @@ namespace percentage
class NetworkIcon: TrayIcon
{
private SettingsNetwork settings;

List<float> measurents = new List<float>();

List<PerformanceCounter> counters = new List<PerformanceCounter>();

public NetworkIcon()
Expand All @@ -29,6 +27,7 @@ public NetworkIcon()

UpdateNICList();

// periodical check for new network interfaces
Timer checkNICTimer = new Timer();
checkNICTimer.Interval = 60 * 1000;
checkNICTimer.Tick += CheckNICList;
Expand Down Expand Up @@ -109,11 +108,5 @@ public override void UpdateIcon(object sender, EventArgs e)
}
}
}

protected override void menuSettings_Click(object sender, EventArgs e)
{
base.menuSettings_Click(sender, e);
SetUpdateInterval(settings.updateInterval);
}
}
}
6 changes: 3 additions & 3 deletions percentage/percentage/Program.cs
Expand Up @@ -14,10 +14,10 @@ static void Main()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

TrayIcon trayIcon = new BatteryIcon();
TrayIcon trayIcon4 = new NetworkIcon();
TrayIcon trayIcon1 = new BatteryIcon();
TrayIcon trayIcon2 = new NetworkIcon();
TrayIcon trayIcon3 = new RamIcon();
TrayIcon trayIcon2 = new CpuIcon();
TrayIcon trayIcon4 = new CpuIcon();

Application.Run();
}
Expand Down
6 changes: 0 additions & 6 deletions percentage/percentage/RamIcon.cs
Expand Up @@ -95,11 +95,5 @@ public override void UpdateIcon(object sender, EventArgs e)
}
}
}

protected override void menuSettings_Click(object sender, EventArgs e)
{
base.menuSettings_Click(sender, e);
SetUpdateInterval(settings.updateInterval);
}
}
}
13 changes: 0 additions & 13 deletions percentage/percentage/Settings.cs
Expand Up @@ -260,19 +260,6 @@ public static SettingsNetwork Instance
class Settings
{
protected CachedStorage storage;
//protected static Settings instance;

//public static Settings Instance
//{
// get
// {
// if (instance == null)
// {
// instance = new Settings();
// }
// return instance;
// }
//}

protected Settings()
{
Expand Down
13 changes: 6 additions & 7 deletions percentage/percentage/TrayIcon.cs
Expand Up @@ -10,25 +10,23 @@ class TrayIcon
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern bool DestroyIcon(IntPtr handle);



private NotifyIcon notifyIcon;
private Timer updateTimer;

public TrayIcon()
{
notifyIcon = new NotifyIcon();

// initialize contextMenu
// common menu for all icons
notifyIcon.ContextMenu = new ContextMenu(new[]
{
new MenuItem("&Settings", menuSettings_Click),
new MenuItem("E&xit", menuExit_Click),

});

notifyIcon.Visible = true;

// prepare update timer
updateTimer = new Timer();
updateTimer.Tick += new EventHandler(UpdateIcon);
}
Expand All @@ -39,6 +37,7 @@ public TrayIcon()

public int GetSmallIconSize()
{
// get size for tray icons on current system (depends of dpi)
return GetSystemMetrics(SM_CXSMICON);
}

Expand All @@ -56,9 +55,7 @@ public void EnableIcon()

public void SetUpdateInterval(int interval)
{
updateTimer.Stop();
updateTimer.Interval = interval;
//updateTimer.Start();
}

public void ChangeIcon(Bitmap bitmap, string tooltip)
Expand Down Expand Up @@ -105,8 +102,9 @@ protected void DelayedIcon(int position)
private void DelayedIconStart(object sender, EventArgs e)
{
((Timer)sender).Stop();
updateTimer.Start();
UpdateIcon(sender, e);
// and start updating
updateTimer.Start();
}

public virtual void UpdateIcon(object sender, EventArgs e)
Expand Down Expand Up @@ -134,6 +132,7 @@ private void menuExit_Click(object sender, EventArgs e)
protected virtual void menuSettings_Click(object sender, EventArgs e)
{
new SettingsForm().ShowDialog();
// immediatly see changes (works only on current icon)
UpdateIcon(null, null);
}
}
Expand Down

0 comments on commit f4c4769

Please sign in to comment.