Skip to content

Commit 5a2facc

Browse files
committed
feature: finished Load Online Templates, add setting for auto fetch templates, add manual fetch button if auto-fetch disabled closes #147
1 parent 3bcffdb commit 5a2facc

File tree

6 files changed

+60
-13
lines changed

6 files changed

+60
-13
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@
902902
<CheckBox x:Name="useUnofficialReleaseList" Content="Use Unofficial Release Watch List (for latest downloads)" ToolTip="Checks latest releases from https://github.com/unitycoder/UnofficialUnityReleasesWatcher (if not yet available in The Unity Releases API)" Checked="useUnofficialReleaseList_Checked" Unchecked="useUnofficialReleaseList_Checked"/>
903903
<CheckBox x:Name="chkDisableUnityHubLaunch" Content="Disable UnityHub launch at Editor start" ToolTip="Overrides UnityHub IPC port. Note: You will be logged out in Editor!" Checked="chkDisableUnityHubLaunch_Checked" Unchecked="chkDisableUnityHubLaunch_Checked"/>
904904
<CheckBox x:Name="chkFetchAdditionalInfo" Content="Fetch additional info about Editor" ToolTip="Reads releases API for security related info" Checked="chkFetchAdditionalInfo_Checked" Unchecked="chkFetchAdditionalInfo_Checked"/>
905+
<CheckBox x:Name="chkFetchOnlineTemplates" Content="New Project window: Fetch online templates" ToolTip="Automatically fetch template listfrom Unity servers" Checked="chkFetchOnlineTemplates_Checked" Unchecked="chkFetchOnlineTemplates_Checked"/>
905906
<CheckBox x:Name="chkStreamerMode" Content="Streamer Mode (hide project names and folders)" ToolTip="Hide project names and folders in main view" Checked="ChkStreamerMode_Checked" Unchecked="ChkStreamerMode_Checked" HorizontalAlignment="Left"/>
906907
<!--<StackPanel Orientation="Horizontal" Margin="0,0,0,4">
907908
<TextBox x:Name="txtTemplatePackagesFolder" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" ToolTip="Folder for your custom unitypackage templates (for new project)" Padding="0,3,0,0" Width="110" TextChanged="TxtTemplatePackagesFolder_TextChanged" />

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ void LoadSettings()
580580
useUnofficialReleaseList.IsChecked = Settings.Default.useUnofficialReleaseList;
581581
chkDisableUnityHubLaunch.IsChecked = Settings.Default.disableUnityHubLaunch;
582582
chkFetchAdditionalInfo.IsChecked = Settings.Default.fetchAdditionalInfo;
583+
chkFetchOnlineTemplates.IsChecked = Settings.Default.fetchOnlineTemplates;
583584

584585
chkEnablePlatformSelection.IsChecked = Settings.Default.enablePlatformSelection;
585586
chkRunAutomatically.IsChecked = Settings.Default.runAutomatically;
@@ -2176,8 +2177,10 @@ void CreateNewEmptyProject(string targetFolder = null)
21762177

21772178
}
21782179

2179-
var suggestedName = targetFolder != null ? Path.GetFileName(targetFolder) : Tools.GetSuggestedProjectName(newVersion, rootFolder);
2180-
NewProject modalWindow = new NewProject(newVersion, suggestedName, rootFolder, targetFolder != null);
2180+
string suggestedName = targetFolder != null ? Path.GetFileName(targetFolder) : Tools.GetSuggestedProjectName(newVersion, rootFolder);
2181+
bool fetchOnlineTemplates = chkFetchOnlineTemplates.IsChecked == true;
2182+
2183+
NewProject modalWindow = new NewProject(newVersion, suggestedName, rootFolder, targetFolder != null, fetchOnlineTemplates);
21812184
modalWindow.ShowInTaskbar = this == null;
21822185
modalWindow.WindowStartupLocation = this == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
21832186
modalWindow.Topmost = this == null;
@@ -4219,6 +4222,14 @@ private void Image_MouseDown(object sender, MouseButtonEventArgs e)
42194222
Tools.LaunchExe(thumbnailPath);
42204223
}
42214224

4225+
private void chkFetchOnlineTemplates_Checked(object sender, RoutedEventArgs e)
4226+
{
4227+
if (this.IsActive == false) return;
4228+
4229+
Settings.Default.fetchOnlineTemplates = (bool)chkFetchOnlineTemplates.IsChecked;
4230+
Settings.Default.Save();
4231+
}
4232+
42224233
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
42234234
//{
42244235
// var proj = GetSelectedProject();

UnityLauncherPro/NewProject.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@
8585
</Grid>
8686
</StackPanel>
8787
<StackPanel Orientation="Vertical" Margin="0,3,10,3" Grid.Column="1">
88-
<Label Content="Unity Online Templates" Foreground="{DynamicResource ThemeButtonForeground}" Margin="0,0,0,3" Padding="5,5,5,3" />
88+
<StackPanel Orientation="Horizontal">
89+
<Label Name="lblUnityOnlineTemplates" Content="Online Templates" Foreground="{DynamicResource ThemeButtonForeground}" Margin="5,0,0,3" Padding="5,5,5,3" HorizontalAlignment="Left" />
90+
<Button Style="{StaticResource CustomButton}" ToolTip="Fetch list of templates" x:Name="btnFetchTemplates" Content="" Height="22" Width="26" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="16" Margin="20,0,0,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="btnFetchTemplates_Click"/>
91+
</StackPanel>
8992

9093

9194
<ListBox x:Name="listOnlineTemplates" Margin="6,5,0,0" Height="411"

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ public partial class NewProject : Window
2727
bool isInitializing = true; // to keep OnChangeEvent from firing too early
2828
int previousSelectedTemplateIndex = -1;
2929
int previousSelectedModuleIndex = -1;
30+
bool loadOnlineTemplates = true;
3031

3132
public static string targetFolder { get; private set; } = null;
3233
private CancellationTokenSource _templateLoadCancellation;
3334

34-
public NewProject(string unityVersion, string suggestedName, string targetFolder, bool nameIsLocked = false)
35+
public NewProject(string unityVersion, string suggestedName, string targetFolder, bool nameIsLocked = false, bool fetchOnlineTemplates = false)
3536
{
3637
isInitializing = true;
3738
InitializeComponent();
3839

40+
loadOnlineTemplates = fetchOnlineTemplates;
41+
btnFetchTemplates.Visibility = fetchOnlineTemplates ? Visibility.Collapsed : Visibility.Visible;
42+
3943
NewProject.targetFolder = targetFolder;
4044

4145
LoadSettings();
@@ -67,7 +71,7 @@ public NewProject(string unityVersion, string suggestedName, string targetFolder
6771
gridAvailableVersions.ScrollIntoView(gridAvailableVersions.SelectedItem);
6872

6973
string baseVersion = GetBaseVersion(newVersion);
70-
_ = LoadOnlineTemplatesAsync(baseVersion);
74+
if (fetchOnlineTemplates) _ = LoadOnlineTemplatesAsync(baseVersion);
7175
break;
7276
}
7377
}
@@ -104,7 +108,6 @@ void UpdateTemplatesDropDown(string unityPath)
104108
lblTemplateTitleAndCount.Content = "Templates: (" + (cmbNewProjectTemplate.Items.Count - 1) + ")";
105109
}
106110

107-
108111
void UpdateModulesDropdown(string version)
109112
{
110113
// get modules and stick into combobox, NOTE we already have this info from GetProjects.Scan, so could access it
@@ -350,11 +353,15 @@ private void GridAvailableVersions_SelectionChanged(object sender, SelectionChan
350353
//chkForceDX11.IsChecked = chkForceDX11.Visibility == Visibility.Visible ? forceDX11 : false;
351354
forceDX11 = Settings.Default.forceDX11 && is6000;
352355

353-
string baseVersion = GetBaseVersion(k.Version);
354-
// Cancel previous request
355-
_templateLoadCancellation?.Cancel();
356-
_templateLoadCancellation = new CancellationTokenSource();
357-
_ = LoadOnlineTemplatesAsync(baseVersion, _templateLoadCancellation.Token);
356+
listOnlineTemplates.ItemsSource = null; // clear previous items
357+
if (loadOnlineTemplates)
358+
{
359+
string baseVersion = GetBaseVersion(k.Version);
360+
// Cancel previous request
361+
_templateLoadCancellation?.Cancel();
362+
_templateLoadCancellation = new CancellationTokenSource();
363+
_ = LoadOnlineTemplatesAsync(baseVersion, _templateLoadCancellation.Token);
364+
}
358365
}
359366

360367
string GetBaseVersion(string version)
@@ -519,7 +526,7 @@ private async Task LoadOnlineTemplatesAsync(string baseVersion, CancellationToke
519526
Console.WriteLine($"GraphQL request failed: {response.StatusCode}");
520527
if (!cancellationToken.IsCancellationRequested)
521528
{
522-
LoadFallbackTemplates();
529+
//LoadFallbackTemplates();
523530
}
524531
}
525532
}
@@ -534,7 +541,7 @@ private async Task LoadOnlineTemplatesAsync(string baseVersion, CancellationToke
534541
if (!cancellationToken.IsCancellationRequested)
535542
{
536543
Console.WriteLine($"Error loading online templates: {ex.Message}");
537-
LoadFallbackTemplates();
544+
//LoadFallbackTemplates();
538545
}
539546
}
540547
}
@@ -851,5 +858,15 @@ private string SplitTextToRows(string description, int rows)
851858
return part1 + Environment.NewLine + part2 + Environment.NewLine + part3;
852859
}
853860

861+
private void btnFetchTemplates_Click(object sender, RoutedEventArgs e)
862+
{
863+
if (gridAvailableVersions.SelectedItem is UnityInstallation selectedInstallation)
864+
{
865+
string baseVersion = GetBaseVersion(selectedInstallation.Version);
866+
_templateLoadCancellation?.Cancel();
867+
_templateLoadCancellation = new CancellationTokenSource();
868+
_ = LoadOnlineTemplatesAsync(baseVersion, _templateLoadCancellation.Token);
869+
}
870+
}
854871
} // class NewProject
855872
} // namespace UnityLauncherPro

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
@@ -163,5 +163,8 @@
163163
<Setting Name="forceDX11" Type="System.Boolean" Scope="User">
164164
<Value Profile="(Default)">False</Value>
165165
</Setting>
166+
<Setting Name="fetchOnlineTemplates" Type="System.Boolean" Scope="User">
167+
<Value Profile="(Default)">True</Value>
168+
</Setting>
166169
</Settings>
167170
</SettingsFile>

0 commit comments

Comments
 (0)