Skip to content

Commit

Permalink
Add option to start on boot in menu of system tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Jun 17, 2018
1 parent 5981e36 commit a92e523
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ When the Dynamic Desktop feature was announced for macOS Mojave which shifts thr

## How do I use this?

The first time you run WinDynamicDesktop, it will automatically download the macOS Mojave wallpapers from [here](https://files.rb.gd/mojave_dynamic.zip) and extract them to your disk. I have not included the files directly in this repository for copyright reasons.
The first time you run WinDynamicDesktop, it will automatically download the macOS Mojave wallpapers from [here](https://files.rb.gd/mojave_dynamic.zip) and extract them to your disk. I have not included the files directly in this repository for copyright reasons. If you want to select a different set of images, see the next section for how to do so.

You will also need to input your location when running the program for the first time. This location is not used for any purpose other than to determine the times of sunrise and sunset where you live.

After you enter your location, you can minimize the program to your system tray and it will run in the background. If you ever want to change the location, right-click on the system tray icon and click *Update Location*. The program can also be exited via the right-click menu of the system tray icon.

The program does not yet have an option built-in to automatically start when Windows boots. To make it do this, create a shortcut to the EXE in the following folder: `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup`.
After you enter your location, you can minimize the program to your system tray and it will run in the background. Right-clicking on the system tray icon opens a menu with options to update the location, start WinDynamicDesktop when Windows boots, or exit the program.

## Can I customize the images?

Expand Down
73 changes: 55 additions & 18 deletions src/FormWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace WinDynamicDesktop
{
class FormWrapper : ApplicationContext
{
private string registryStartupLocation = @"Software\Microsoft\Windows\CurrentVersion\Run";
private bool startOnBoot;

private ProgressDialog downloadDialog;
private InputDialog locationDialog;
private NotifyIcon notifyIcon;
Expand All @@ -23,10 +26,14 @@ public FormWrapper()
Application.ApplicationExit += new EventHandler(OnApplicationExit);
SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnPowerModeChanged);

InitializeComponent();

JsonConfig.LoadConfig();

RegistryKey startupKey = Registry.CurrentUser.OpenSubKey(registryStartupLocation);
startOnBoot = startupKey.GetValue("WinDynamicDesktop") != null;
startupKey.Close();

InitializeComponent();

if (!Directory.Exists("images"))
{
DownloadImages();
Expand All @@ -43,28 +50,38 @@ public FormWrapper()

private void InitializeComponent()
{
notifyIcon = new NotifyIcon();
notifyIcon.Visible = true;
notifyIcon.Icon = Properties.Resources.AppIcon;
notifyIcon.Text = "WinDynamicDesktop";
notifyIcon.BalloonTipTitle = "WinDynamicDesktop";
notifyIcon = new NotifyIcon
{
Visible = true,
Icon = Properties.Resources.AppIcon,
Text = "WinDynamicDesktop",
BalloonTipTitle = "WinDynamicDesktop"
};

notifyIcon.ContextMenu = new ContextMenu(new MenuItem[]
{
new MenuItem("WinDynamicDesktop"),
new MenuItem("-"),
new MenuItem("&Update Location", locationItem_Click),
new MenuItem("E&xit", exitItem_Click)
new MenuItem("&Update Location", OnLocationItemClick),
new MenuItem("&Start on Boot", OnStartupItemClick),
new MenuItem("E&xit", OnExitItemClick)
});

notifyIcon.ContextMenu.MenuItems[0].Enabled = false;
notifyIcon.ContextMenu.MenuItems[3].Checked = startOnBoot;
}

private void locationItem_Click(object sender, EventArgs e)
private void OnLocationItemClick(object sender, EventArgs e)
{
UpdateLocation();
}

private void OnStartupItemClick(object sender, EventArgs e)
{
ToggleStartOnBoot();
}

private void exitItem_Click(object sender, EventArgs e)
private void OnExitItemClick(object sender, EventArgs e)
{
notifyIcon.Visible = false;
Application.Exit();
Expand All @@ -83,7 +100,7 @@ public void DownloadImages()
}

downloadDialog = new ProgressDialog();
downloadDialog.FormClosed += downloadDialog_Closed;
downloadDialog.FormClosed += OnDownloadDialogClosed;
downloadDialog.Show();

using (WebClient client = new WebClient())
Expand All @@ -94,7 +111,7 @@ public void DownloadImages()
}
}

private void downloadDialog_Closed(object sender, EventArgs e)
private void OnDownloadDialogClosed(object sender, EventArgs e)
{
downloadDialog = null;

Expand All @@ -118,13 +135,12 @@ private void downloadDialog_Closed(object sender, EventArgs e)
}
}

public void UpdateLocation()
public void UpdateLocation()
{
if (locationDialog == null)
{
locationDialog = new InputDialog();
locationDialog.wcsService = wcsService;
locationDialog.FormClosed += locationDialog_Closed;
locationDialog = new InputDialog { wcsService = wcsService };
locationDialog.FormClosed += OnLocationDialogClosed;
locationDialog.Show();
}
else
Expand All @@ -133,7 +149,7 @@ public void UpdateLocation()
}
}

private void locationDialog_Closed(object sender, EventArgs e)
private void OnLocationDialogClosed(object sender, EventArgs e)
{
locationDialog = null;

Expand All @@ -149,9 +165,30 @@ private void locationDialog_Closed(object sender, EventArgs e)
notifyIcon.BalloonTipText = "The app is still running in the background. " +
"You can access it at any time by right-clicking on this icon.";
notifyIcon.ShowBalloonTip(10000);

JsonConfig.firstRun = false; // Don't show this message again
}
}

private void ToggleStartOnBoot()
{
RegistryKey startupKey = Registry.CurrentUser.OpenSubKey(registryStartupLocation, true);

if (!startOnBoot)
{
string exePath = Path.Combine(Directory.GetCurrentDirectory(),
Environment.GetCommandLineArgs()[0]);
startupKey.SetValue("WinDynamicDesktop", exePath);
}
else
{
startupKey.DeleteValue("WinDynamicDesktop");
}

startOnBoot = !startOnBoot;
notifyIcon.ContextMenu.MenuItems[3].Checked = startOnBoot;
}

private void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
if (e.Mode == PowerModes.Suspend)
Expand Down
1 change: 1 addition & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static void Main()
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(
OnUnhandledException);
Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath);

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1")]
//[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit a92e523

Please sign in to comment.