From c81151c3b756046ba66d9f070713724e6c0a3f24 Mon Sep 17 00:00:00 2001 From: Panu Oksala Date: Sun, 2 Jun 2024 15:05:36 +0300 Subject: [PATCH] Changed app to use DI container, because non-DI version had problems to start Updated register and start plugin powershell from plugin author repository Updated version in manifest to 1.5.0 Updated readme to contain more information about starting the app in own computer --- Program.cs | 24 +++++++----- README.md | 1 + RegisterPluginAndStartStreamDeck.ps1 | 56 +++++++++++++--------------- StreamDeckAzureDevOps.csproj | 10 +++-- manifest.json | 4 +- 5 files changed, 49 insertions(+), 46 deletions(-) diff --git a/Program.cs b/Program.cs index 0de9906..4e75542 100644 --- a/Program.cs +++ b/Program.cs @@ -1,21 +1,25 @@ -using StreamDeckLib; +using Microsoft.Extensions.Hosting; +using StreamDeckLib; +using StreamDeckLib.DependencyInjection; +using StreamDeckLib.Hosting; +using System.Net.WebSockets; using System.Threading.Tasks; namespace StreamDeckAzureDevOps { class Program { - - static async Task Main(string[] args) + public static void Main(string[] args) { - using (var config = StreamDeckLib.Config.ConfigurationBuilder.BuildDefaultConfiguration(args)) - { - await ConnectionManager.Initialize(args, config.LoggerFactory) - .RegisterAllActions(typeof(Program).Assembly) - .StartAsync(); - } - + CreateHostBuilder(args).Build().Run(); } + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureStreamDeckToolkit(args) + .ConfigureServices((hostContext, services) => + { + services.AddStreamDeck(hostContext.Configuration, typeof(Program).Assembly); + }); } } diff --git a/README.md b/README.md index 0427a8a..f7ed6c8 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ If Stream Deck shows red question icon on top right corner of the button, check 4. Visual Studio should automatically add Azure DevOps button into your Stream Deck app / device. 5. To debug the app just run it and attach debugger into StreamDeck application (you might have two so try both). 6. If you experience problems try to run the Visual Studio in Administrator mode. +7. Build/Rebuild will stop StreamDeck app, so start it manually after every build. It will reload changes automatically. If you have problems to build plugin after debugging, quick fix is to restart Visual Studio. diff --git a/RegisterPluginAndStartStreamDeck.ps1 b/RegisterPluginAndStartStreamDeck.ps1 index bdf1775..6e2e9dd 100644 --- a/RegisterPluginAndStartStreamDeck.ps1 +++ b/RegisterPluginAndStartStreamDeck.ps1 @@ -1,16 +1,11 @@ Write-Host "Gathering deployment items..." -Write-Host "Script root: $PSScriptRoot`n" +Write-Host "Current Working Directory: $(get-location)" -$basePath = $PSScriptRoot +$basePath = $(get-location) -if ($PSSCriptRoot.Length -eq 0) { - $basePath = $PWD.Path; -} - - -# Load and parse the plugin project file -$pluginProjectFile = "$basePath\StreamDeckAzureDevOps.csproj" +# Load and parse the plugin project file - Fully expects there to be only one csproj file in there +$pluginProjectFile = Get-ChildItem -Filter *.csproj | Select-Object -First 1 $projectContent = Get-Content $pluginProjectFile | Out-String; $projectXML = [xml]$projectContent; @@ -20,45 +15,46 @@ $buildConfiguration = "Debug" $targetFrameworkName = $projectXML.Project.PropertyGroup.TargetFramework; # Set local path references -$streamDeckExePath = "$($ENV:ProgramFiles)\Elgato\StreamDeck\StreamDeck.exe" - -# For now, this PS script will only be run on Windows. -$bindir = "$basePath\bin\Debug\$targetFrameworkName\win-x64" +if ($IsMacOS) { + $streamDeckExePath = "/Applications/Stream Deck.app" + $bindir = "$basePath/bin/Debug/$targetFrameworkName/osx-x64" +} else { + $streamDeckExePath = "$($ENV:ProgramFiles)\Elgato\StreamDeck\StreamDeck.exe" + $bindir = "$basePath\bin\Debug\$targetFrameworkName\win-x64" +} # Make sure we actually have a directory/build to deploy If (-not (Test-Path $bindir)) { - Write-Error "The output directory `"$bindir`" was not found.`n You must first build the `"StreamDeckAzureDevOps`" project before calling this script."; + Write-Error "The output directory `"$bindir`" was not found.`n You must first build the project before calling this script."; exit 1; } # Load and parse the plugin's manifest file -$manifestFile = $bindir +"\manifest.json" -$manifestContent = Get-Content $manifestFile | Out-String -$json = ConvertFrom-JSON $manifestcontent +$manifestPath = Join-Path $bindir "manifest.json" +$json = Get-Content -Path $manifestPath -Raw | ConvertFrom-Json $uuidAction = $json.Actions[0].UUID $pluginID = $uuidAction.substring(0, $uuidAction.Length - ".action".Length) -$destDir = "$($env:APPDATA)\Elgato\StreamDeck\Plugins\$pluginID.sdPlugin" -$pluginName = Split-Path $basePath -leaf +if($IsMacOS) { + $destDir = "$HOME/Library/Application Support/com.elgato.StreamDeck/Plugins/$pluginID.sdPlugin" +} else { + $destDir = "$($env:APPDATA)\Elgato\StreamDeck\Plugins\$pluginID.sdPlugin" +} -Get-Process -Name ("StreamDeck", $pluginName) -ErrorAction SilentlyContinue | Stop-Process –force -ErrorAction SilentlyContinue | Wait-Process -Timeout 30 +$pluginName = Split-Path $basePath -leaf -# Short wait as the files below might still be locked for few seconds after StreamDeck is closed. -Start-Sleep 4 +Get-Process -Name ("StreamDeck", $pluginName) -ErrorAction SilentlyContinue | Stop-Process –force -ErrorAction SilentlyContinue # Delete the target directory, make sure the deployment/copy is clean -If (Test-Path $destDir) { - Remove-Item -Recurse -Force -Path $destDir -} +Remove-Item -Recurse -Force -Path $destDir -ErrorAction SilentlyContinue +$bindir = Join-Path $bindir "*" # Then copy all deployment items to the plugin directory New-Item -Type Directory -Path $destDir -ErrorAction SilentlyContinue # | Out-Null -$bindir = $bindir +"\*" Copy-Item -Path $bindir -Destination $destDir -Recurse - -Write-Host "Deployment complete. Restarting the Stream Deck desktop application..." -Start-Process $streamDeckExePath -exit 0 +Write-Host "Deployment complete. We will NOT restart the Stream Deck desktop application here, but will from the template..." +# Start-Process $streamDeckExePath +exit 0 \ No newline at end of file diff --git a/StreamDeckAzureDevOps.csproj b/StreamDeckAzureDevOps.csproj index 9aa97dc..149fd4f 100644 --- a/StreamDeckAzureDevOps.csproj +++ b/StreamDeckAzureDevOps.csproj @@ -4,11 +4,12 @@ Exe net6.0 latest + win-x64 - win-x64 + osx-x64 - win-x64;osx-x64 + OnBuildSuccess @@ -25,10 +26,11 @@ + - + @@ -37,7 +39,7 @@ - + diff --git a/manifest.json b/manifest.json index 9ea3169..5157885 100644 --- a/manifest.json +++ b/manifest.json @@ -25,10 +25,10 @@ "Name": "AzureDevOpsRunner", "Icon": "images/Azure-DevOps72", "URL": "https://github.com/panuoksala/streamdeck-azuredevops-plugin", - "Version": "1.4.0", + "Version": "1.5.0", "SDKVersion": 2, "Software": { - "MinimumVersion": "4.1" + "MinimumVersion": "5.0" }, "OS": [ {