Skip to content

Commit

Permalink
Skip loading unneeded plugins via cli
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed May 17, 2024
1 parent e521fa9 commit e52eee1
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions BottlesPlugin/Bottles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Bottles : IGameSource
public string Version => "v1.0.8";
public string SlugServiceName => "bottles";
public string ShortServiceName => "bottles";
public PluginType Type => PluginType.BootProfile;

private string _message = "";
private List<BottlesWrapper> _wrappers = new();
private List<BottlesProgram> _games = new();
Expand Down
2 changes: 2 additions & 0 deletions GogIntegration/GogIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using LauncherGamePlugin.Enums;
using LauncherGamePlugin.Forms;
using LauncherGamePlugin.Interfaces;
using LauncherGamePlugin.Launcher;
using Newtonsoft.Json;

namespace GogIntegration;
Expand All @@ -16,6 +17,7 @@ public class GogIntegration : IGameSource
public string Version => "v1.1.4";
public string SlugServiceName => "gog-integration";
public string ShortServiceName => "GOG";
public PluginType Type => PluginType.GameSource;

public IApp App { get; private set; }
public Config Config => _storage.Data;
Expand Down
3 changes: 3 additions & 0 deletions HideGamesMiddleware/HideGames.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LauncherGamePlugin;
using LauncherGamePlugin.Commands;
using LauncherGamePlugin.Enums;
using LauncherGamePlugin.Interfaces;

namespace HideGamesMiddleware;
Expand All @@ -12,6 +13,8 @@ public class HideGames : IGameSource
public string ShortServiceName => SlugServiceName;
public Storage<Store> Storage { get; set; }
public IApp App { get; set; }
public PluginType Type => PluginType.Middleware;

public async Task<InitResult?> Initialize(IApp app)
{
Storage = new(app, "hidegames.json");
Expand Down
1 change: 1 addition & 0 deletions ItchIoIntegration/ItchGameSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ItchGameSource : IGameSource
public string Version => "v1.1.6";
public string SlugServiceName => "itch-io";
public string ShortServiceName => "Itch.io";
public PluginType Type => PluginType.GameSource;

private Config Config => _storage.Data;
private Storage<Config> _storage;
Expand Down
14 changes: 10 additions & 4 deletions Launcher/Loader/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public LogType LogLevel

public event Action<IGameSource, long> OnPluginInitialised;

private async Task<IGameSource> InitialiseService(IGameSource source)
private async Task<IGameSource> InitializeService(IGameSource source)
{
Stopwatch stopwatch = new();
stopwatch.Start();
Expand All @@ -113,7 +113,7 @@ private async Task<IGameSource> InitialiseService(IGameSource source)
return source;
}

public async Task InitializeGameSources()
public async Task InitializeGameSources(Func<IGameSource, bool>? loadPlugin = null)
{
if (_initialised)
return;
Expand All @@ -122,8 +122,14 @@ public async Task InitializeGameSources()
List<Task<IGameSource>> tasks = new();
sources.ForEach(x =>
{
Logger.Log($"Initialising {x.ServiceName}...");
tasks.Add(InitialiseService(x));
if (loadPlugin != null && !loadPlugin(x))
{
Logger.Log($"Skipping load for service {x.ServiceName}...");
return;
}

Logger.Log($"Initialising service {x.ServiceName}...");
tasks.Add(InitializeService(x));
});

while (true)
Expand Down
2 changes: 1 addition & 1 deletion Launcher/Loader/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static List<string> AvailablePlugins()
File.ReadAllLines(Path.GetFullPath(Path.Join(path, "..", "..", "..", "..", "..", "Plugins.txt")))
.Select(x => x.Trim())
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(x => Path.GetFullPath(Path.Join(path, "..", "..", "..", "..", "..", x, "bin", "Debug", "net7.0", $"{x}.dll"))));
.Select(x => Path.GetFullPath(Path.Join(path, "..", "..", "..", "..", "..", x, "bin", "Debug", "net8.0", $"{x}.dll"))));
#endif

if (!Directory.Exists(path))
Expand Down
2 changes: 2 additions & 0 deletions Launcher/Middleware/MiddlewareBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using LauncherGamePlugin;
using LauncherGamePlugin.Commands;
using LauncherGamePlugin.Enums;
using LauncherGamePlugin.Interfaces;
using LauncherGamePlugin.Launcher;

Expand All @@ -12,6 +13,7 @@ public class MiddlewareBridge : IGameSource
public IGameSource Service { get; set; }
public IServiceMiddleware? NextMiddleware { get; set; }
public MiddlewareBridge? NextBridge { get; set; }
public PluginType Type => PluginType.Middleware;

public MiddlewareBridge(IGameSource service, IServiceMiddleware? nextMiddleware, MiddlewareBridge? nextBridge)
{
Expand Down
4 changes: 3 additions & 1 deletion Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia;
using LauncherGamePlugin;
using LauncherGamePlugin.Commands;
using LauncherGamePlugin.Enums;
using LauncherGamePlugin.Extensions;
using LauncherGamePlugin.Forms;
using LauncherGamePlugin.Interfaces;
Expand All @@ -20,6 +21,7 @@ internal class Program
[STAThread]
public static void Main(string[] args)
{
args = new[] { "epic-games", "Salt", "Launch" };
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

if (args.Length <= 2)
Expand All @@ -32,7 +34,7 @@ public static void Start(string[] args)
{
Loader.App app = Loader.App.GetInstance();
app.HeadlessMode = true;
app.InitializeGameSources().GetAwaiter().GetResult();
app.InitializeGameSources(gameSource => gameSource.Type != PluginType.GameSource || gameSource.SlugServiceName == args[0]).GetAwaiter().GetResult();
List<IGame> allGames = app.GetGames().GetAwaiter().GetResult();
IGame? target = allGames.Find(x => x.Source.SlugServiceName == args[0] && x.InternalName == args[1]);
if (target == null)
Expand Down
2 changes: 1 addition & 1 deletion Launcher/Views/GameViewSmall.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public List<Command> GetCommands()
GameSession total = config.GetTotalTime();
if (total.TimeSpent.TotalSeconds > 0)
{
string time = total.TimeSpent.ToString(@"hh\:mm");
string time = total.TimeSpent.ToString(@"hh\hmm\m");
commands.Add(new($"Played for {time}"));
}
}
Expand Down
9 changes: 9 additions & 0 deletions LauncherGamePlugin/Enums/PluginType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace LauncherGamePlugin.Enums;

public enum PluginType
{
GameSource,
BootProfile,
Middleware,
Other
}
2 changes: 2 additions & 0 deletions LauncherGamePlugin/Interfaces/IGameSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LauncherGamePlugin.Commands;
using LauncherGamePlugin.Enums;
using LauncherGamePlugin.Launcher;

namespace LauncherGamePlugin.Interfaces;
Expand All @@ -9,6 +10,7 @@ public interface IGameSource
string Version { get; }
string SlugServiceName { get; }
string ShortServiceName { get; }
PluginType Type { get; }

public Task<InitResult?> Initialize(IApp app);
public async Task<List<IBootProfile>> GetBootProfiles() => new();

Check warning on line 16 in LauncherGamePlugin/Interfaces/IGameSource.cs

View workflow job for this annotation

GitHub Actions / build-linux

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 16 in LauncherGamePlugin/Interfaces/IGameSource.cs

View workflow job for this annotation

GitHub Actions / build-windows

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 16 in LauncherGamePlugin/Interfaces/IGameSource.cs

View workflow job for this annotation

GitHub Actions / build-windows

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
Expand Down
2 changes: 2 additions & 0 deletions LegendaryIntegration/LegendaryGameSource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LauncherGamePlugin;
using LauncherGamePlugin.Commands;
using LauncherGamePlugin.Enums;
using LauncherGamePlugin.Forms;
using LauncherGamePlugin.Interfaces;
using LauncherGamePlugin.Launcher;
Expand All @@ -18,6 +19,7 @@ public class LegendaryGameSource : IGameSource
public string Version => "v1.2.4";
public string SlugServiceName => "epic-games";
public string ShortServiceName => "EpicGames";
public PluginType Type => PluginType.GameSource;
public LegendaryAuth? auth;
public LegendaryGameManager? manager;
public static LegendaryGameSource Source { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions LocalGames/LocalGameSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class LocalGameSource : IGameSource
public string ShortServiceName => "Local";
public string Version => "v2.0.1";
public string SlugServiceName => "local-games";
public PluginType Type => PluginType.GameSource;

private IApp _app;
public List<LocalGame> Games => _storage.Data.LocalGames;
Expand Down
2 changes: 2 additions & 0 deletions SteamExporterPlugin/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Exporter : IGameSource
public string Version => "v1.2.7";
public string SlugServiceName => "steam-exporter";
public string ShortServiceName => "Steam";
public PluginType Type => PluginType.BootProfile;

public IApp? App { get; private set; }
private bool _initialised = false;
private ProtonManager? _protonManager;
Expand Down
2 changes: 2 additions & 0 deletions SteamGridDbMiddleware/SteamGridDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class SteamGridDb : IGameSource
public string Version => "v1.2.2";
public string SlugServiceName => "steam-grid-db";
public string ShortServiceName => "steamgriddb";
public PluginType Type => PluginType.Middleware;

public IApp App { get; set; }

Check warning on line 20 in SteamGridDbMiddleware/SteamGridDb.cs

View workflow job for this annotation

GitHub Actions / build-linux

Non-nullable property 'App' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public craftersmine.SteamGridDBNet.SteamGridDb? Api { get; set; }
public Storage<Store> Storage { get; set; }

Check warning on line 22 in SteamGridDbMiddleware/SteamGridDb.cs

View workflow job for this annotation

GitHub Actions / build-linux

Non-nullable property 'Storage' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Expand Down

0 comments on commit e52eee1

Please sign in to comment.