Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to run on Windows startup #289

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions Steam Desktop Authenticator/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public MainForm()

private void MainForm_Shown(object sender, EventArgs e)
{
if (Program.winStartup)
{
this.Hide();
}

this.labelVersion.Text = String.Format("v{0}", Application.ProductVersion);
this.manifest = Manifest.GetManifest();

Expand Down Expand Up @@ -71,6 +76,12 @@ private void MainForm_Shown(object sender, EventArgs e)
private void MainForm_Load(object sender, EventArgs e)
{
trayIcon.Icon = this.Icon;

if (Program.winStartup)
{
//Minimize on load so it doesn't blink
this.WindowState = FormWindowState.Minimized;
}
}

private void MainForm_Resize(object sender, EventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions Steam Desktop Authenticator/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class Manifest
[JsonProperty("auto_confirm_trades")]
public bool AutoConfirmTrades { get; set; } = false;

[JsonProperty("startup_min")]
public bool StartupMinimized { get; set; } = true;

private static Manifest _manifest { get; set; }

public static string GetExecutableDir()
Expand Down
11 changes: 9 additions & 2 deletions Steam Desktop Authenticator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Steam_Desktop_Authenticator
{
static class Program
{
public static bool winStartup;

public static Process PriorProcess()
// Returns a System.Diagnostics.Process pointing to
// a pre-existing process with the same name as the
Expand Down Expand Up @@ -38,7 +40,7 @@ public static Process PriorProcess()
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
static void Main(string[] args)
{
// run the program only once
if (PriorProcess() != null)
Expand All @@ -47,11 +49,16 @@ static void Main()
return;
}

bool startup = args.Length > 0 && args[0] == "-startup";

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Manifest man = Manifest.GetManifest();
if(man.FirstRun)

winStartup = startup && man.StartupMinimized;

if (man.FirstRun)
{
// Install VC++ Redist and wait
new InstallRedistribForm().ShowDialog();
Expand Down
32 changes: 30 additions & 2 deletions Steam Desktop Authenticator/SettingsForm.Designer.cs

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

35 changes: 34 additions & 1 deletion Steam Desktop Authenticator/SettingsForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Win32;
using System;
using System.Windows.Forms;

namespace Steam_Desktop_Authenticator
Expand All @@ -8,6 +9,17 @@ public partial class SettingsForm : Form
Manifest manifest;
bool fullyLoaded = false;

bool startupEnabled;
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

private string StartupLine
{
get
{
return "\"" + Application.ExecutablePath + "\" -startup";
}
}

public SettingsForm()
{
InitializeComponent();
Expand All @@ -24,6 +36,11 @@ public SettingsForm()
SetControlsEnabledState(chkPeriodicChecking.Checked);

fullyLoaded = true;

startupEnabled = rkApp.GetValue("SDA")?.ToString() == StartupLine;
chkStartup.Checked = startupEnabled;
chkStartMin.Enabled = startupEnabled;
chkStartMin.Checked = manifest.StartupMinimized;
}

private void SetControlsEnabledState(bool enabled)
Expand All @@ -49,7 +66,18 @@ private void btnSave_Click(object sender, EventArgs e)
manifest.CheckAllAccounts = chkCheckAll.Checked;
manifest.AutoConfirmMarketTransactions = chkConfirmMarket.Checked;
manifest.AutoConfirmTrades = chkConfirmTrades.Checked;
manifest.StartupMinimized = chkStartMin.Checked;
manifest.Save();

if (chkStartup.Checked && !startupEnabled)
{
rkApp.SetValue("SDA", StartupLine);
}
else if (!chkStartup.Checked && startupEnabled)
{
rkApp.DeleteValue("SDA", false);
}

this.Close();
}

Expand All @@ -69,5 +97,10 @@ private void chkConfirmTrades_CheckedChanged(object sender, EventArgs e)
if(chkConfirmTrades.Checked)
ShowWarning(chkConfirmTrades);
}

private void chkStartup_CheckedChanged(object sender, EventArgs e)
{
chkStartMin.Enabled = chkStartup.Checked;
}
}
}