Instead of providing delegates to a ScriptClient singleton, script execution now relies on dependency injection for debugging. This can be handled by registering an implementation of IScriptDebugger. Multiple script debuggers are supported. These changes required the creation of a PowerShellScriptFactory to handle DI of the service provider to the script.
In the case of LANCommander, "debugging" scripts really just gives an opportunity for the application to break after a script's execution and provide a poor-man's pty. This could be expanded upon in the future to hook directly into PowerShell's debugging functionality, but would require a substantial refactor to script execution.
- API requests are now made through the ApiRequestBuilder with DI supplied via the ApiRequestFactory singleton
- Reliance on RestSharp and WebClient has been removed in favor of HttpClient
- Auth token is now being tracked by the ITokenProvider
- Network information (MAC address, broadcast addresses, IP address) is now supplied with the INetworkInformationProvider singleton
- Connection state is now being maintained by the ConnectionService, with a reliance on RPC (SignalR websocket) reporting actual connection state without relying on pings
- All download streams are now provided as a TrackableStream
- Singleton Client class has been removed. All usage of the SDK should happen via Dependency Injection
This is just a base, non-functional refactor of the SDK to use DI. The following changes to the rest of the codebase need to be made:
- Usage of the SDK client in the launcher needs to be replaced in favor of injecting SDK services
- PowerShell cmdlets need to be able to have services injected. Most likely a separate scope will have to be opened up per PS runtime?
- Usage of the SDK client in the server needs to be replaced in favor of injecting SDK services. This should be minimal and should actually provide benefit when it comes to executing client-like features (scripts mostly) without needing a fully configured client that maintains connection state.
- Configuration of the client needs to be implemented using ILANCommanderConfiguration
This does a very basic job of bundling a PowerShell runtime into the SDK. Previously, scripts had been run by spawning a separate PowerShell process and feeding the script into it. This was nothing better than a hack and meant that PowerShell had to be separately installed on the machine it's executing on. This should open up the opportunity for scripts to run on other platforms.
There's still some things that need to be figured out. Some sort of console output as well as a debugging mode would be highly beneficial for those that wish to actively develop scripts for their games.
PowerShell scripts now execute correctly with the client. The built in PowerShell API's serializer will always return null on .NET 8 for some reason. The serializer/deserializer was switched to YAML, mostly due to convenience of already having a package for it.
Added a new settings for enabling script debugging mode. This ensures that when a script is executed, the PowerShell terminal window is not closed. This allows power users to get the same environment that the script executes in. It also allows for some scroll back to see what potentially went wrong in their script.
Probably pretty hacky. Environment.CurrentDirectory doesn't seem to be reliable in dev vs prod. In dev it correctly matches the LANCommander.PlaynitePlugin.dll's location. In prod it is the main directory of Playnite.