Skip to content

Commit

Permalink
avoid calling checkbox checked setting save code at startup (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
unitycoder committed Dec 25, 2023
1 parent 607b176 commit 15c1cad
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions UnityLauncherPro/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,12 +1526,16 @@ private void BtnOpenWebsite_Click(object sender, RoutedEventArgs e)

private void ChkMinimizeToTaskbar_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.minimizeToTaskbar = (bool)chkMinimizeToTaskbar.IsChecked;
Settings.Default.Save();
}

private void ChkRegisterExplorerMenu_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

if ((bool)chkRegisterExplorerMenu.IsChecked)
{
Tools.AddContextMenuRegistry(contextRegRoot);
Expand All @@ -1548,6 +1552,7 @@ private void ChkRegisterExplorerMenu_CheckedChanged(object sender, RoutedEventAr
private void ChkShowLauncherArgumentsColumn_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.showArgumentsColumn = (bool)chkShowLauncherArgumentsColumn.IsChecked;
Settings.Default.Save();
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
Expand All @@ -1557,6 +1562,7 @@ private void ChkShowLauncherArgumentsColumn_CheckedChanged(object sender, Routed
private void ChkShowGitBranchColumn_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.showGitBranchColumn = (bool)chkShowGitBranchColumn.IsChecked;
Settings.Default.Save();
gridRecent.Columns[5].Visibility = (bool)chkShowGitBranchColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
Expand All @@ -1565,12 +1571,16 @@ private void ChkShowGitBranchColumn_CheckedChanged(object sender, RoutedEventArg

private void ChkQuitAfterOpen_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.closeAfterProject = (bool)chkQuitAfterOpen.IsChecked;
Settings.Default.Save();
}

private void ChkQuitAfterCommandline_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.closeAfterExplorer = (bool)chkQuitAfterCommandline.IsChecked;
Settings.Default.Save();
}
Expand Down Expand Up @@ -1793,12 +1803,16 @@ private void DataGridUpdates_PreviewMouseDoubleClick(object sender, MouseButtonE

private void ChkShowMissingFolderProjects_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.showProjectsMissingFolder = (bool)chkShowMissingFolderProjects.IsChecked;
Settings.Default.Save();
}

private void ChkAllowSingleInstanceOnly_CheckedChanged(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.AllowSingleInstanceOnly = (bool)chkAllowSingleInstanceOnly.IsChecked;
Settings.Default.Save();
}
Expand Down Expand Up @@ -1966,17 +1980,21 @@ void CreateNewEmptyProject(string targetFolder = null)

private void ChkAskNameForQuickProject_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.askNameForQuickProject = (bool)chkAskNameForQuickProject.IsChecked;
Properties.Settings.Default.Save();
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.askNameForQuickProject = (bool)chkAskNameForQuickProject.IsChecked;
Settings.Default.Save();
}

bool isInitializing = true; // used to avoid doing things while still starting up
private void ChkStreamerMode_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

Properties.Settings.Default.streamerMode = isChecked;
Properties.Settings.Default.Save();
Settings.Default.streamerMode = isChecked;
Settings.Default.Save();

// Create cellstyle and assign if streamermode is enabled
Style cellStyle = new Style(typeof(DataGridCell));
Expand All @@ -1999,6 +2017,8 @@ private void ChkStreamerMode_Checked(object sender, RoutedEventArgs e)

private void ChkShowPlatform_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

Settings.Default.showTargetPlatform = isChecked;
Expand Down Expand Up @@ -2072,6 +2092,8 @@ public void MoveRecentGridItem(int to)

private void ChkEnableProjectRename_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Properties.Settings.Default.enableProjectRename = (bool)chkEnableProjectRename.IsChecked;
Properties.Settings.Default.Save();
}
Expand Down Expand Up @@ -2565,8 +2587,8 @@ private void ChkUseCustomTheme_Checked(object sender, RoutedEventArgs e)
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;
Properties.Settings.Default.useCustomTheme = isChecked;
Properties.Settings.Default.Save();
Settings.Default.useCustomTheme = isChecked;
Settings.Default.Save();

btnReloadTheme.IsEnabled = isChecked;

Expand Down Expand Up @@ -2616,9 +2638,11 @@ private void BtnExploreFolder_Click(object sender, RoutedEventArgs e)

private void ChkEnablePlatformSelection_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;
Properties.Settings.Default.enablePlatformSelection = isChecked;
Properties.Settings.Default.Save();
Settings.Default.enablePlatformSelection = isChecked;
Settings.Default.Save();
chkEnablePlatformSelection.IsChecked = isChecked;
}

Expand All @@ -2642,9 +2666,10 @@ private void CmbPlatformSelection_DropDownClosed(object sender, EventArgs e)
private void ChkRunAutomatically_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;
Properties.Settings.Default.runAutomatically = isChecked;
Properties.Settings.Default.Save();
Settings.Default.runAutomatically = isChecked;
Settings.Default.Save();
chkRunAutomatically.IsChecked = isChecked;
// set or unset registry, NOTE should not do this on debug build.. (otherwise 2 builds try to run?)
Tools.SetStartupRegistry(isChecked);
Expand Down Expand Up @@ -2741,6 +2766,7 @@ bool ValidateIntRange(TextBox textBox, int min, int max)
private void ChkHumanFriendlyDateTime_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

// cannot have both date formats
Expand Down Expand Up @@ -2796,6 +2822,7 @@ void OpenSelectedBuildReportFile()
private void ChkRunAutomaticallyMinimized_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

Settings.Default.runAutomaticallyMinimized = isChecked;
Expand Down Expand Up @@ -2974,6 +3001,7 @@ private void Window_SourceInitialized(object sender, EventArgs e)
private void ChkSearchProjectPath_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

var isChecked = (bool)((CheckBox)sender).IsChecked;

searchProjectPathAlso = isChecked;
Expand Down Expand Up @@ -3011,6 +3039,7 @@ private void MenuBatchBuildIOS_Click(object sender, RoutedEventArgs e)
private void ChkCheckPlasticBranch_Checked(object sender, RoutedEventArgs e)
{
if (this.IsActive == false) return; // dont run code on window init

Settings.Default.checkPlasticBranch = (bool)chkCheckPlasticBranch.IsChecked;
Settings.Default.Save();
RefreshRecentProjects();
Expand Down Expand Up @@ -3315,7 +3344,7 @@ private void btnPatchHubConfig_Click(object sender, RoutedEventArgs e)
// replace the manual:true with manual:false using regex
json = json.Replace("\"manual\":true", "\"manual\":false");

Console.WriteLine(json);
//Console.WriteLine(json);

// write the config file
File.WriteAllText(configFile, json);
Expand Down

0 comments on commit 15c1cad

Please sign in to comment.