Added start on windows startup feature IO-404

This commit is contained in:
Patrick Fic
2021-01-18 11:49:55 -08:00
parent 34a5ae2292
commit 1b4e5fb3f0
9 changed files with 72 additions and 2 deletions

View File

@@ -63,6 +63,9 @@
<setting name="RefreshToken" serializeAs="String">
<value />
</setting>
<setting name="StartWithWindows" serializeAs="String">
<value>True</value>
</setting>
</BodyshopPartner.Properties.Settings>
</userSettings>
</configuration>

View File

@@ -21,6 +21,7 @@ namespace BodyshopPartner
private void Application_Exit(object sender, ExitEventArgs e)
{
BodyshopPartner.Properties.Settings.Default.Save();
Utils.QuickBooksInterop.DisconnectFromQuickBooks();
}
}

View File

@@ -240,6 +240,15 @@ namespace BodyshopPartner.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Start with Windows.
/// </summary>
public static string Label_StartWithWindows {
get {
return ResourceManager.GetString("Label_StartWithWindows", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Status.
/// </summary>

View File

@@ -177,6 +177,9 @@
<data name="Label_StartAllMonitors" xml:space="preserve">
<value>Start _All Monitors</value>
</data>
<data name="Label_StartWithWindows" xml:space="preserve">
<value>Start with Windows</value>
</data>
<data name="Label_Status" xml:space="preserve">
<value>Status</value>
</data>

View File

@@ -128,5 +128,17 @@ namespace BodyshopPartner.Properties {
this["RefreshToken"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool StartWithWindows {
get {
return ((bool)(this["StartWithWindows"]));
}
set {
this["StartWithWindows"] = value;
}
}
}
}

View File

@@ -29,5 +29,8 @@
<Setting Name="RefreshToken" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="StartWithWindows" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -192,7 +192,23 @@ namespace BodyshopPartner.ViewModels
}
}
private ICommand _startWithWindowsCommand;
public ICommand StartWithWindowsCommand
{
get
{
if (_startWithWindowsCommand == null)
{
_startWithWindowsCommand = new RelayCommand(
p => true,
p =>
{
ToggleStartWithWindows((bool)(p));
});
}
return _startWithWindowsCommand;
}
}
}
}

View File

@@ -198,7 +198,24 @@ namespace BodyshopPartner.ViewModels
App.Current.Shutdown();
}
public async Task LoadBodyshopData()
public void ToggleStartWithWindows(bool shouldStart)
{
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (shouldStart)
{
// Add the value in the registry so that the application runs at startup
rkApp.SetValue(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, System.Reflection.Assembly.GetEntryAssembly().Location);
}
else
{
// Remove the value from the registry so that the application doesn't start
rkApp.DeleteValue(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, false);
}
}
public async Task LoadBodyshopData()
{
var r = new GraphQLRequest
{

View File

@@ -128,6 +128,12 @@
<CheckBox IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=AutoStartMonitor}"
Margin="8"
Content="{x:Static p:Resources.Label_AutoStartMonitor}" />
<CheckBox IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=StartWithWindows}"
Margin="8"
Content="{x:Static p:Resources.Label_StartWithWindows}"
Command="{Binding StartWithWindowsCommand}"
CommandParameter="{Binding Source={x:Static p:Settings.Default}, Path=StartWithWindows}"/>
<Button Command="{Binding AddMonitoringPathCommand, UpdateSourceTrigger=PropertyChanged}"
Margin="8"
ToolTip="{x:Static p:Resources.Label_AddMonitoringPath}"