Skip to content

Commit

Permalink
Make logic in WallpaperChangeScheduler more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Jun 13, 2018
1 parent 80a91ef commit d20326b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/FormWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private void InitializeComponent()
notifyIcon = new NotifyIcon();
notifyIcon.Visible = true;
notifyIcon.Icon = Properties.Resources.AppIcon;
notifyIcon.Text = "WinDynamicDesktop";
notifyIcon.BalloonTipTitle = "WinDynamicDesktop";

notifyIcon.ContextMenu = new ContextMenu(new MenuItem[]
Expand Down
8 changes: 6 additions & 2 deletions src/WallpaperChangeScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class WallpaperChangeScheduler
private int[] nightImages = new[] { 13, 14, 15, 16, 1 };

private string lastDate = "yyyy-MM-dd";
private int lastImageId = -1;
private int lastImageNumber = -1;
private bool isSunUp;

Expand Down Expand Up @@ -72,6 +73,8 @@ private void SetWallpaper(int imageId)
String.Format(imageFilename, imageId)));

Wallpaper.Set(wallpaperUri, Wallpaper.Style.Stretched);

lastImageId = imageId;
}

public void StartScheduler()
Expand Down Expand Up @@ -133,7 +136,7 @@ private void StartDaySchedule()
wallpaperTimer.Elapsed += new ElapsedEventHandler(wallpaperTimer_Elapsed);
wallpaperTimer.Start();

if (imageNumber != lastImageNumber)
if (dayImages[imageNumber] != lastImageId)
{
SetWallpaper(dayImages[imageNumber]);
lastImageNumber = imageNumber;
Expand Down Expand Up @@ -182,7 +185,7 @@ private void StartNightSchedule()
wallpaperTimer.Elapsed += new ElapsedEventHandler(wallpaperTimer_Elapsed);
wallpaperTimer.Start();

if (imageNumber != lastImageNumber)
if (nightImages[imageNumber] != lastImageId)
{
SetWallpaper(nightImages[imageNumber]);
lastImageNumber = imageNumber;
Expand Down Expand Up @@ -214,6 +217,7 @@ private void NextNightImage()
yesterdaysData = todaysData;
todaysData = tomorrowsData;
tomorrowsData = null;
lastDate = GetDateString();
}
}

Expand Down

0 comments on commit d20326b

Please sign in to comment.