Skip to content

Commit

Permalink
feat: Autostart with system
Browse files Browse the repository at this point in the history
  • Loading branch information
Marconi Gomes committed Sep 10, 2023
1 parent 06e851d commit ea33c81
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
22 changes: 19 additions & 3 deletions AMRPC WatchDog Desktop/Window.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 31 additions & 8 deletions AMRPC WatchDog Desktop/Window.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
using System;
using System.Windows.Forms;
using Microsoft.Win32;

namespace AMRPC_WatchDog_Desktop
{
public partial class Window : Form
{
private System.Windows.Forms.NotifyIcon _notifyIcon;
private const string StartupKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
private const string StartupValue = "AMRPC WatchDog";
private readonly RegistryKey _regKey = Registry.CurrentUser.OpenSubKey(StartupKey, true);
private NotifyIcon _notifyIcon;
public Window(string appVersion)
{
InitializeComponent();

SetupNotifyIcon(appVersion);
SetupAutostartCheckbox();

var provider = new Provider();
}

private void SetupNotifyIcon(string appVersion)
{
_notifyIcon.Text = $"AMRPC WatchDog {appVersion}";
_notifyIcon.Visible = false;
_runningStatusLabel.Text = "Service is running\nYou might want to minimize this window to tray.";

var provider = new Provider();
}

private void SetupAutostartCheckbox()
{
var value = _regKey.GetValue(StartupValue);
_autoStartCheckbox.Checked = value != null;
}

private void Window_Resize(object sender, EventArgs e)
Expand All @@ -32,10 +46,19 @@ private void Window_Restore(object sender, EventArgs e)
WindowState = FormWindowState.Normal;
_notifyIcon.Visible = false;
}

private void Window_Load(object sender, EventArgs e)
{

private void _autoStartCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox) sender).Checked)
{
_regKey.SetValue(StartupValue, Application.ExecutablePath);
}
else
{
_regKey.DeleteValue(StartupValue);
}
}

private void Window_Load(object sender, EventArgs e) { }
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Go to the [releases page](https://github.com/zephraOSS/AMRPC-WatchDog/releases/t
- [x] Build the desktop version
- [x] Fix the fail to reconnect websocket when watchdog keeps running but connection is closed
- [ ] Fix triplicated websocket messages on song info changed
- [ ] Add "Autostart with system" option
- [x] Add "Autostart with system" option
- [ ] Add "Start minimized" option

0 comments on commit ea33c81

Please sign in to comment.