Skip to content

Commit

Permalink
Websockets (#27)
Browse files Browse the repository at this point in the history
* Added websocket sharp to server proj

* Added beginnings of websocket server/client

* Fixed refreshing views when changing projects

* Removed views from home menu item template

* Changed home page process items to be build via C#

* Updated readme

* Fixed controls in home screen

* Added a single ping/pong from client to server

* Added build server for server

* Added ServerClientShared proj for network package sending

* Got payload from /build service

* Change test projects file structure

* Update AvaloniaAppMVVM.csproj

* Added Unity IL2CPP test proj

* Fixed json package properly

* Improved build target form page

* Fixed enum selections in targets page

* Improved app project data persistence

* Added cloning git repo

* Updated git build process

- Removed test project into own repo

* Update README.md

* Fixed getting branches now from local repo ref

* Added back starting client

* Fixed checking if settings paths exists

* Removed BuildPath

* Updated build processes

* Removed not needed files for unity package

* Update package.json

* Fixed switching branch in git

* Added switching branch before update

* Improved gui app locking up when trying to connect to server when server is not running

* Update Git.cs

* Moved UnityBuilder into Build folder

* Create UnityHub.cs

* Update UnityHub.cs

* Added build runner for unity builds

* Update Program.cs

* Fixed cancellation issues

* Attempt at uploading zip files

* Changed uploads to raw files rather than zip

* Prepared proj for deployment runners

* Added copying steam sdk to output dir

* Removed stuff from steam sdk not needed

* Added xcode deploy scaffold

* Added google deploy proj

* Added aws deployment proj

* Added unity services proj

* Added clanforge and itchio projs

* Moved build runner to offload server proj

* moved stuff to main server proj

* Added server retries when disconnected

* Preparing new main server proj

* Prepare for testing new server layout

* Added branch to build service message request

* Fixed connecting to offload servers

* Beginnings of making custom websocket server

* Added TPC connection

* Improved file up/downloads

* Removed WebsocketSharp in favour for custom TPC connections

* Established connection from gui app to server

* Added loop to keep trying client connection if server isnt up

* Updated unity package to serialise enums as strings

* Moved projects into proper folders

* Added a way to extract as much data from EditorUserBuildSettings as i can for build options

* Updated Unity builds

* Removed code not needed

* Added test for uploading multiple directories in a queue

* Fixed not all builds getting to runner server

* code tidy

* Update launchSettings.json

* Move deployment runner to new MainServer proj

* Finished deployments to main server proj
  • Loading branch information
brogan89 authored Apr 7, 2024
1 parent 3a8d300 commit cb93cb4
Show file tree
Hide file tree
Showing 311 changed files with 9,873 additions and 8,947 deletions.
11 changes: 1 addition & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,4 @@
obj/
bin/
*.DS_Store
*.csproj.user

#unity
/Unity/BuildTest/Library
/Unity/BuildTest/Temp
/Unity/BuildTest/Logs
/Unity/BuildTest/Builds
/Unity/BuildTest/UserSettings
/Unity/BuildTest/**.csproj
/Unity/BuildTest/**.sln
*.csproj.user
10 changes: 10 additions & 0 deletions AvaloniaAppMVVM/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using AvaloniaAppMVVM.Data;
using AvaloniaAppMVVM.Services;
using AvaloniaAppMVVM.ViewModels;
using AvaloniaAppMVVM.Views;
using CommunityToolkit.Extensions.DependencyInjection;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using SocketServer;

namespace AvaloniaAppMVVM;

public partial class App : Application
{
private static readonly Client _client =
new(AppSettings.Singleton.ServerIp!, AppSettings.Singleton.ServerPort);

public static readonly BuildClientService BuildClient = new(_client);

public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
AppSettings.Load();
_client.AddService(BuildClient);
}

public override void OnFrameworkInitializationCompleted()
Expand Down
6 changes: 6 additions & 0 deletions AvaloniaAppMVVM/AvaloniaAppMVVM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
<PackageReference Include="FluentAvaloniaUI" />
<PackageReference Include="LoadingIndicators.Avalonia" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Tomlyn" />
</ItemGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\github.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ServerClientShared\ServerClientShared.csproj" />
<ProjectReference Include="..\Servers\SocketServer\SocketServer.csproj" />
</ItemGroup>

</Project>
31 changes: 30 additions & 1 deletion AvaloniaAppMVVM/Data/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace AvaloniaAppMVVM.Data;
using System.Runtime.Serialization;
using Tomlyn;

namespace AvaloniaAppMVVM.Data;

public class AppSettings
{
[IgnoreDataMember]
public static AppSettings Singleton { get; private set; } = new();

/// <summary>
/// Last project loaded location.
/// </summary>
Expand All @@ -11,4 +17,27 @@ public class AppSettings
/// All projects loaded.
/// </summary>
public List<string?> LoadedProjectPaths { get; set; } = [];

public string? ServerIp { get; set; } = "localhost";
public ushort ServerPort { get; set; } = 8080;
// public string? GitUsername { get; set; }
// public string? GitPassword { get; set; }

public void Save()
{
var toml = Toml.FromModel(this);
File.WriteAllText("settings.toml", toml);
Console.WriteLine("Saved settings: settings.toml");
Console.WriteLine(toml);
}

public static AppSettings Load()
{
if (!File.Exists("settings.toml"))
return Singleton;

var toml = File.ReadAllText("settings.toml");
Singleton = Toml.ToModel<AppSettings>(toml);
return Singleton;
}
}
6 changes: 4 additions & 2 deletions AvaloniaAppMVVM/Data/BuildProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public interface IProcess
public bool Succeeded { get; set; }
public bool Failed { get; set; }
public string? Id { get; set; }
public string? Logs{get; set;}
public string? Logs { get; set; }
public string? TotalTime { get; set; }
}

public class CiProcess : IProcess
Expand All @@ -18,6 +19,7 @@ public class CiProcess : IProcess
public bool Failed { get; set; }
public string? Id { get; set; }
public string? Logs { get; set; }

public string? TotalTime { get; set; }

public List<IProcess>? SubProcesses { get; set; }
}
6 changes: 0 additions & 6 deletions AvaloniaAppMVVM/Data/IBuildTarget.cs

This file was deleted.

11 changes: 11 additions & 0 deletions AvaloniaAppMVVM/Data/UnityBuildTargetTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using ServerClientShared;

namespace AvaloniaAppMVVM.Data.Shared;

/// <summary>
/// Unity Build Target, synced with <see cref="ServerClientShared.UnityBuildTarget"/>
/// </summary>
public class UnityBuildTargetTemplate(UnityBuildTarget data) : CiProcess
{
public UnityBuildTarget Data { get; set; } = data;
}
7 changes: 0 additions & 7 deletions AvaloniaAppMVVM/Forms/NewProjectForm.cs

This file was deleted.

File renamed without changes.
24 changes: 24 additions & 0 deletions AvaloniaAppMVVM/Services/BuildClientService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Newtonsoft.Json.Linq;
using SocketServer;

namespace AvaloniaAppMVVM.Services;

public class BuildClientService(Client client) : ClientService(client)
{
public override string Name => "build";

public override void OnStringMessage(string message)
{
throw new NotImplementedException();
}

public override void OnDataMessage(byte[] data)
{
throw new NotImplementedException();
}

public override void OnJsonMessage(JObject payload)
{
Console.WriteLine($"BuildClientService: Received json message: {payload}");
}
}
48 changes: 48 additions & 0 deletions AvaloniaAppMVVM/Utils/Json.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;

namespace AvaloniaAppMVVM.Utils;

/// <summary>
/// Wrapper class for JsonConvert
/// </summary>
public static class Json
{
private static readonly JsonSerializerSettings _settings = new()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
Converters =
{
new StringEnumConverter(),
}
};

public static string Serialise(object? obj)
{
try
{
return JsonConvert.SerializeObject(obj, _settings);
}
catch (Exception e)
{
Console.WriteLine($"Failed to serialise object: {obj}");
return string.Empty;
}
}

public static T? Deserialise<T>(string jsonStr)
{
try
{
return JsonConvert.DeserializeObject<T>(jsonStr, _settings);
}
catch (Exception e)
{
Console.WriteLine($"Failed to deserialise to type: {typeof(T).Name}, json: {jsonStr}");
throw;
}
}
}
1 change: 1 addition & 0 deletions AvaloniaAppMVVM/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AvaloniaAppMVVM.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using FluentAvalonia.UI.Windowing;

namespace AvaloniaAppMVVM;

Expand Down
137 changes: 135 additions & 2 deletions AvaloniaAppMVVM/ViewModels/BuildTargetsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,146 @@
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using AvaloniaAppMVVM.Data;
using AvaloniaAppMVVM.Data.Shared;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ServerClientShared;

namespace AvaloniaAppMVVM.ViewModels;

public partial class BuildTargetsViewModel : ViewModelBase
{
public ObservableCollection<UnityBuildTarget> BuildTargets { get; } = [];
public Project Project { get; set; }

[IgnoreDataMember]
public static ObservableCollection<string> ExtensionOptions { get; } =
[".exe", ".app", ".x86_64", ".aab", "/"];

[IgnoreDataMember]
public static ObservableCollection<Unity.BuildTarget> BuildTargetOptions { get; } =
new(Enum.GetValues<Unity.BuildTarget>());

[IgnoreDataMember]
public static ObservableCollection<Unity.BuildTargetGroup> BuildTargetGroupOptions { get; } =
new(Enum.GetValues<Unity.BuildTargetGroup>());

[IgnoreDataMember]
public static ObservableCollection<Unity.SubTarget> SubTargetOptions { get; } =
new(Enum.GetValues<Unity.SubTarget>());

[IgnoreDataMember]
public static ObservableCollection<Unity.BuildOptions> BuildOptionOptions { get; } =
new(Enum.GetValues<Unity.BuildOptions>());

public ObservableCollection<UnityBuildTargetTemplate> BuildTargets { get; } = [];
public ObservableCollection<NewBuildTargetTemplate> NewTargetTemplates { get; } =
[
new NewBuildTargetTemplate(
"Windows",
Unity.BuildTarget.StandaloneWindows64,
Unity.BuildTargetGroup.Standalone,
".exe"
),
new NewBuildTargetTemplate(
"Mac",
Unity.BuildTarget.StandaloneOSX,
Unity.BuildTargetGroup.Standalone,
".app"
),
new NewBuildTargetTemplate(
"Linux",
Unity.BuildTarget.StandaloneLinux64,
Unity.BuildTargetGroup.Standalone,
".x86_64"
),
new NewBuildTargetTemplate(
"Android",
Unity.BuildTarget.Android,
Unity.BuildTargetGroup.Android,
".apk"
),
new NewBuildTargetTemplate(
"iOS",
Unity.BuildTarget.iOS,
Unity.BuildTargetGroup.iOS,
"/"
),
];

[ObservableProperty]
private UnityBuildTargetTemplate? _selectedBuildTarget;

[ObservableProperty]
private NewBuildTargetTemplate? _selectedNewTargetTemplate;

[ObservableProperty]
private bool _showContent;

[ObservableProperty]
private UnityBuildTarget? _selectedBuildTarget;
private bool _showError = true;

partial void OnSelectedBuildTargetChanged(UnityBuildTargetTemplate? value)
{
ShowContent = true;
ShowError = false;
}

[RelayCommand]
public void NewTargetCommand(string name)
{
var template = NewTargetTemplates.FirstOrDefault(template => template.Name == name);

if (template is null)
return;

var data = new UnityBuildTarget
{
Name = template.Name,
ProductName = Project.Settings.ProjectName,
Target = template.Target,
SubTarget = Unity.SubTarget.Player,
TargetGroup = template.TargetGroup,
Extension = template.Extension
};

var newTarget = new UnityBuildTargetTemplate(data);
BuildTargets.Add(newTarget);
SelectedBuildTarget = newTarget;
}

[RelayCommand]
public void DeleteTargetCommand(string name)
{
foreach (var target in BuildTargets)
{
if (target.Data.Name != name)
continue;

BuildTargets.Remove(target);
break;
}

if (BuildTargets.Count > 0)
{
SelectedBuildTarget = BuildTargets[0];
}
else
{
ShowContent = false;
ShowError = true;
}
}
}

public class NewBuildTargetTemplate(
string? name,
Unity.BuildTarget target,
Unity.BuildTargetGroup targetGroup,
string? extension
)
{
public string? Name { get; set; } = name;
public Unity.BuildTarget Target { get; set; } = target;
public Unity.BuildTargetGroup TargetGroup { get; set; } = targetGroup;
public string? Extension { get; set; } = extension;
}
Loading

0 comments on commit cb93cb4

Please sign in to comment.