Skip to content

Commit 6bc7712

Browse files
committed
add option: run automatically on startup
1 parent 8da59cf commit 6bc7712

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

UnityLauncherPro/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<setting name="enablePlatformSelection" serializeAs="String">
7979
<value>False</value>
8080
</setting>
81+
<setting name="runAutomatically" serializeAs="String">
82+
<value>False</value>
83+
</setting>
8184
</UnityLauncherPro.Properties.Settings>
8285
</userSettings>
8386
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@
890890

891891
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="5,10,3,3" >
892892
<CheckBox x:Name="chkEnablePlatformSelection" Content="Enable Platform Selection (Experimental!)" Foreground="{DynamicResource ThemeButtonForeground}" Checked="ChkEnablePlatformSelection_Checked" Unchecked="ChkEnablePlatformSelection_Checked" Margin="0,0,0,4" ToolTip="" HorizontalAlignment="Left"/>
893+
<CheckBox x:Name="chkRunAutomatically" Content="Run this app automatically on startup" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,4" ToolTip="" HorizontalAlignment="Left" Checked="ChkRunAutomatically_Checked" Unchecked="ChkRunAutomatically_Checked"/>
893894
</StackPanel>
894895
</StackPanel>
895896

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace UnityLauncherPro
2424
public partial class MainWindow : Window
2525
{
2626
private System.Windows.Forms.NotifyIcon notifyIcon;
27-
const string appName = "UnityLauncherPro";
27+
public const string appName = "UnityLauncherPro";
2828

2929
[DllImport("user32", CharSet = CharSet.Unicode)]
3030
static extern IntPtr FindWindow(string cls, string win);
@@ -275,6 +275,7 @@ void LoadSettings()
275275
txtCustomThemeFile.Text = themefile;
276276

277277
chkEnablePlatformSelection.IsChecked = Properties.Settings.Default.enablePlatformSelection;
278+
chkRunAutomatically.IsChecked = Properties.Settings.Default.runAutomatically;
278279

279280
// update optional grid columns, hidden or visible
280281
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
@@ -1864,6 +1865,17 @@ private void CmbPlatformSelection_DropDownClosed(object sender, EventArgs e)
18641865
}
18651866
}
18661867

1868+
private void ChkRunAutomatically_Checked(object sender, RoutedEventArgs e)
1869+
{
1870+
if (this.IsActive == false) return; // dont run code on window init
1871+
var isChecked = (bool)((CheckBox)sender).IsChecked;
1872+
Properties.Settings.Default.runAutomatically = isChecked;
1873+
Properties.Settings.Default.Save();
1874+
chkRunAutomatically.IsChecked = isChecked;
1875+
// set or unset registry, NOTE should not do this on debug build.. (otherwise 2 builds try to run?)
1876+
Tools.SetStartupRegistry(isChecked);
1877+
}
1878+
18671879
//private void CmbPlatformSelection_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
18681880
//{
18691881
// var comb = (ComboBox)sender;

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityLauncherPro/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@
7171
<Setting Name="enablePlatformSelection" Type="System.Boolean" Scope="User">
7272
<Value Profile="(Default)">False</Value>
7373
</Setting>
74+
<Setting Name="runAutomatically" Type="System.Boolean" Scope="User">
75+
<Value Profile="(Default)">False</Value>
76+
</Setting>
7477
</Settings>
7578
</SettingsFile>

UnityLauncherPro/Tools.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,5 +983,19 @@ public static string[] GetPlatformsForUnityVersion(string version)
983983
return null;
984984
}
985985

986+
// https://stackoverflow.com/a/675347/5452781
987+
public static void SetStartupRegistry(bool state)
988+
{
989+
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
990+
if (state == true)
991+
{
992+
rk.SetValue(MainWindow.appName, "\"" + Process.GetCurrentProcess().MainModule.FileName + "\"");
993+
}
994+
else
995+
{
996+
rk.DeleteValue(MainWindow.appName, false);
997+
}
998+
}
999+
9861000
} // class
9871001
} // namespace

0 commit comments

Comments
 (0)