Skip to content

Commit

Permalink
Added option to start app minimized.
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz committed Apr 4, 2021
1 parent 3e53a79 commit 3184ac3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
3 changes: 3 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<setting name="FtpMode" serializeAs="String">
<value>1</value>
</setting>
<setting name="StartMinimized" serializeAs="String">
<value>False</value>
</setting>
</ValheimSaveShield.Properties.Settings>
</userSettings>
</configuration>
4 changes: 3 additions & 1 deletion MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<CheckBox x:Name="chkAutoBackup" Content="Automatically backup save files" ToolTip="Monitor save files and back them up when they're changed" HorizontalAlignment="Left" Margin="10,2,0,2" VerticalAlignment="Top" Click="ChkAutoBackup_Click" Grid.Row="0" Checked="ChkAutoBackup_Click" Unchecked="ChkAutoBackup_Click"/>
<Grid Grid.Row="1">
Expand Down Expand Up @@ -143,7 +144,8 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox x:Name="chkCreateLogFile" Content="Create log file" ToolTip="Whether a log.txt file should be created" HorizontalAlignment="Left" Margin="10,2,0,2" VerticalAlignment="Center" Grid.Row="0" Checked="chkCreateLogFile_Click" Unchecked="chkCreateLogFile_Click"/>
<CheckBox x:Name="chkCreateLogFile" Content="Create log file" ToolTip="Whether a log.txt file should be created" HorizontalAlignment="Left" Margin="10,2,0,2" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" Checked="chkCreateLogFile_Click" Unchecked="chkCreateLogFile_Click"/>
<CheckBox x:Name="chkStartMinimized" Content="Start minimized" ToolTip="Minimize app on startup" HorizontalAlignment="Left" Margin="10,2,0,2" VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" Checked="chkStartMinimized_Checked" Unchecked="chkStartMinimized_Checked"/>
<CheckBox x:Name="chkAutoCheckUpdate" Content="Automatically check for update" HorizontalAlignment="Left" Margin="10,5" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" Checked="chkAutoCheckUpdate_Click"/>
<Button x:Name="btnAppUpdate" Content="Check Now" ToolTip="Check to see if there's a new version of this program available" HorizontalAlignment="Left" Margin="10,5,0,5" VerticalAlignment="Center" Click="btnAppUpdate_Click" Grid.Row="1" Grid.Column="1" />
</Grid>
Expand Down
30 changes: 23 additions & 7 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ public MainWindow()
// start the directory syncing if user has the correct settings for it
syncDirectoriesAsync();

chkCreateLogFile.IsChecked = Properties.Settings.Default.CreateLogFile;

saveTimers = new Dictionary<string, SaveTimer>();

listBackups = new List<SaveBackup>();
Expand Down Expand Up @@ -311,6 +309,10 @@ private void NotifyIcon_Click(object sender, EventArgs e)

private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (Properties.Settings.Default.StartMinimized)
{
this.WindowState = WindowState.Minimized;
}
loadBackups();
txtBackupFolder.Text = Properties.Settings.Default.BackupFolder;

Expand All @@ -319,6 +321,8 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
txtBackupMins.Text = Properties.Settings.Default.BackupMinutes.ToString();
txtBackupLimit.Text = Properties.Settings.Default.BackupLimit.ToString();
chkAutoCheckUpdate.IsChecked = Properties.Settings.Default.AutoCheckUpdate;
chkCreateLogFile.IsChecked = Properties.Settings.Default.CreateLogFile;
chkStartMinimized.IsChecked = Properties.Settings.Default.StartMinimized;

if (Properties.Settings.Default.AutoCheckUpdate)
{
Expand Down Expand Up @@ -1125,13 +1129,19 @@ private void Window_Deactivated(object sender, EventArgs e)

private void chkCreateLogFile_Click(object sender, RoutedEventArgs e)
{
bool newValue = chkCreateLogFile.IsChecked.HasValue ? chkCreateLogFile.IsChecked.Value : false;
if (newValue & !Properties.Settings.Default.CreateLogFile)
try
{
System.IO.File.WriteAllText("log.txt", DateTime.Now.ToString() + ": Version " + typeof(MainWindow).Assembly.GetName().Version + "\r\n");
bool newValue = chkCreateLogFile.IsChecked.GetValueOrDefault();
if (newValue & !Properties.Settings.Default.CreateLogFile)
{
System.IO.File.WriteAllText("log.txt", DateTime.Now.ToString() + ": Version " + typeof(MainWindow).Assembly.GetName().Version + "\r\n");
}
Properties.Settings.Default.CreateLogFile = newValue;
Properties.Settings.Default.Save();
} catch (Exception ex)
{
logMessage($"Error changing log option: {ex.Message}");
}
Properties.Settings.Default.CreateLogFile = newValue;
Properties.Settings.Default.Save();
}

private void chkAutoCheckUpdate_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -1633,6 +1643,12 @@ private void dataBackups_ContextMenuOpening(object sender, ContextMenuEventArgs
menuBackups.Visibility = Visibility.Collapsed;
}
}

private void chkStartMinimized_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.StartMinimized = chkStartMinimized.IsChecked.GetValueOrDefault();
Properties.Settings.Default.Save();
}
}

public enum LogType
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,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("0.4.10.0")]
[assembly: AssemblyFileVersion("0.4.10.0")]
[assembly: AssemblyVersion("0.4.11.0")]
[assembly: AssemblyFileVersion("0.4.11.0")]
12 changes: 12 additions & 0 deletions Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@
<Setting Name="FtpMode" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
<Setting Name="StartMinimized" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 3184ac3

Please sign in to comment.