Skip to content

Commit

Permalink
Merge pull request #10 from BarRaider/dev
Browse files Browse the repository at this point in the history
v1.8 - "Run in Background" + optimizations
  • Loading branch information
BarRaider authored May 21, 2023
2 parents f3f77e9 + 1b68c56 commit 634400e
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 55 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

**Author's website and contact information:** [https://barraider.com](https://barraider.com)

### New in v1.8
- New `Run in Background` option allows to launch apps without a window (still experimental)
- Optimized internal logic and reduced CPU usage

### New in v1.7
- Updated Steam Game Launcher to work with new Steam file formats

Expand Down
71 changes: 57 additions & 14 deletions streamdeck-advancedlauncher/Actions/LauncherAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BarRaider.SdTools;
using AdvancedLauncher.Backend;
using BarRaider.SdTools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
Expand All @@ -11,6 +12,8 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;

namespace AdvancedLauncher.Actions
{
Expand All @@ -22,13 +25,13 @@ namespace AdvancedLauncher.Actions
//---------------------------------------------------

[PluginActionId("com.barraider.advancedlauncher")]
public class LauncherAction : PluginBase
public class LauncherAction : KeypadBase
{
private const int MAX_INSTANCES = 1;
private const int POST_KILL_LAUNCH_DELAY = 0;
private class PluginSettings
{

public static PluginSettings CreateDefaultSettings()
{
PluginSettings instance = new PluginSettings
Expand All @@ -42,7 +45,8 @@ public static PluginSettings CreateDefaultSettings()
PostKillLaunchDelay = POST_KILL_LAUNCH_DELAY.ToString(),
RunAsAdmin = false,
ShowRunningIndicator = false,
BringToFront = false
BringToFront = false,
BackgroundRun = false
};
return instance;
}
Expand Down Expand Up @@ -77,6 +81,10 @@ public static PluginSettings CreateDefaultSettings()

[JsonProperty(PropertyName = "bringToFront")]
public bool BringToFront { get; set; }

[JsonProperty(PropertyName = "backgroundRun")]
public bool BackgroundRun { get; set; }

}

#region Private Members
Expand All @@ -85,6 +93,7 @@ public static PluginSettings CreateDefaultSettings()
private readonly PluginSettings settings;
private int maxInstances = 1;
private Bitmap fileImage;
private bool fileImageHasLaunchedIndicator = false;
private int postKillLaunchDelay = 0;
private Image prefetchedAdminImage = null;

Expand Down Expand Up @@ -121,8 +130,8 @@ public async override void OnTick()
{
if (fileImage != null)
{
HandleRunningIndicator();
await Connection.SetImageAsync(fileImage);
await HandleRunningIndicator();
}
}

Expand Down Expand Up @@ -197,7 +206,7 @@ private async Task HandleApplicationRun()
}

FileInfo fileInfo = new FileInfo(settings.Application);
string fileName = fileInfo.Name.Substring(0,fileInfo.Name.LastIndexOf('.'));
string fileName = fileInfo.Name.Substring(0, fileInfo.Name.LastIndexOf('.'));
// Kill existing instances
if (settings.KillInstances)
{
Expand Down Expand Up @@ -254,9 +263,12 @@ private void RunApplication()
}
// Enter the executable to run, including the complete path
start.FileName = settings.Application;
// Do you want to show a console window?
//start.WindowStyle = ProcessWindowStyle.Hidden;
//start.CreateNoWindow = true;

if (settings.BackgroundRun)
{
start.WindowStyle = ProcessWindowStyle.Hidden;
//start.CreateNoWindow = true;
}

if (settings.RunAsAdmin)
{
Expand All @@ -267,7 +279,7 @@ private void RunApplication()
Process.Start(start);
}

private async Task HandleRunningIndicator()
private void HandleRunningIndicator()
{
if (!settings.ShowRunningIndicator)
{
Expand All @@ -278,13 +290,43 @@ private async Task HandleRunningIndicator()
string fileName = fileInfo.Name.Substring(0, fileInfo.Name.LastIndexOf('.'));

// Check if there are any running instances
if (Process.GetProcessesByName(fileName).Length > 0)
if (ProcessesCache.Instance.GetProcessCountByProcessName(fileName) > 0)
{
await Connection.SetTitleAsync($"🟢{new String(' ',10)}");
if (fileImageHasLaunchedIndicator) // No need to do anything as the indicator already exists
{
return;
}
AddLaunchedIndicator();
}
else
else if (fileImageHasLaunchedIndicator)
{
FetchFileImage();
}
}

private void AddLaunchedIndicator()
{
if (fileImage == null)
{
return;
}

try
{
Bitmap newImage = (Bitmap)fileImage.Clone();

// Add Circle
Graphics graphics = Graphics.FromImage(newImage);
graphics.FillCircle(new SolidBrush(Color.FromArgb(0, 210, 106)), 30, 120, 12);

// Replace image
fileImage.Dispose();
fileImage = newImage;
fileImageHasLaunchedIndicator = true;
}
catch (Exception ex)
{
await Connection.SetTitleAsync((String)null);
Logger.Instance.LogMessage(TracingLevel.ERROR, $"{this.GetType()} AddLaunchedIndicator Exception: {ex}");
}
}

Expand All @@ -296,6 +338,7 @@ private void FetchFileImage()
fileImage = null;
}

fileImageHasLaunchedIndicator = false;
// Try to extract Icon
if (!String.IsNullOrEmpty(settings.Application) && File.Exists(settings.Application))
{
Expand Down
2 changes: 1 addition & 1 deletion streamdeck-advancedlauncher/Actions/ProcessKillerAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace AdvancedLauncher.Actions
{
[PluginActionId("com.barraider.advancedlauncher.processkiller")]
public class ProcessKillerAction : PluginBase
public class ProcessKillerAction : KeypadBase
{
private class PluginSettings
{
Expand Down
7 changes: 3 additions & 4 deletions streamdeck-advancedlauncher/Actions/SteamLauncherAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace AdvancedLauncher.Actions
{
[PluginActionId("com.barraider.steamlauncher")]
public class SteamLauncherAction : PluginBase
public class SteamLauncherAction : KeypadBase
{

public enum ImageFit
Expand Down Expand Up @@ -123,7 +123,7 @@ public async override void OnTick()

if (appInfo != null && titleParameters != null && settings.ShowAppName)
{
await Connection.SetTitleAsync(Tools.SplitStringToFit(appInfo.Name, titleParameters));
await Connection.SetTitleAsync(appInfo.Name?.SplitToFitKey(titleParameters));
}
}

Expand Down Expand Up @@ -167,7 +167,6 @@ private void Connection_OnTitleParametersDidChange(object sender, SDEventReceive

private async void FetchAppInfo()
{

try
{
// Cleanup
Expand Down Expand Up @@ -348,7 +347,7 @@ private void LoadInstalledApps()
}
}
}
var apps = settings.Applications.OrderBy(a => a.Name).ToList();
var apps = settings.Applications.GroupBy(a => a.Id).Select(g => g.FirstOrDefault())?.OrderBy(a => a.Name).ToList();
Logger.Instance.LogMessage(TracingLevel.INFO, $"{this.GetType()} Found {apps.Count} apps in {directories.Count} dirs");
settings.Applications = apps;
}
Expand Down
4 changes: 2 additions & 2 deletions streamdeck-advancedlauncher/Actions/UWPLauncherAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace AdvancedLauncher.Actions
{
[PluginActionId("com.barraider.msstorelauncher")]
public class UWPLauncherAction : PluginBase
public class UWPLauncherAction : KeypadBase
{
private class PluginSettings
{
Expand Down Expand Up @@ -108,7 +108,7 @@ public async override void OnTick()

if (appInfo != null && titleParameters != null && settings.ShowAppName)
{
await Connection.SetTitleAsync(Tools.SplitStringToFit(appInfo.Name, titleParameters));
await Connection.SetTitleAsync(appInfo.Name?.SplitToFitKey(titleParameters));
}
}

Expand Down
52 changes: 37 additions & 15 deletions streamdeck-advancedlauncher/AdvancedLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
<OutputType>Exe</OutputType>
<RootNamespace>AdvancedLauncher</RootNamespace>
<AssemblyName>com.barraider.advancedlauncher</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -37,31 +38,50 @@
<PropertyGroup>
<ApplicationIcon>brlogo.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\com.barraider.advancedlauncher.sdPlugin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>8.0</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\Release\com.barraider.advancedlauncher.sdPlugin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>8.0</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=2.8.0.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll</HintPath>
<Reference Include="CommandLine, Version=2.9.1.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\CommandLineParser.2.9.1\lib\net461\CommandLine.dll</HintPath>
</Reference>
<Reference Include="Gameloop.Vdf, Version=0.6.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\Gameloop.Vdf.0.6.1\lib\net45\Gameloop.Vdf.dll</HintPath>
<Reference Include="Gameloop.Vdf, Version=0.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\Gameloop.Vdf.0.6.2\lib\net45\Gameloop.Vdf.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\NLog.4.7.11\lib\net45\NLog.dll</HintPath>
<HintPath>..\..\..\DotNet\StreamDeck\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="streamdeck-client-csharp, Version=4.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\streamdeck-client-csharp.4.3.0\lib\netstandard2.0\streamdeck-client-csharp.dll</HintPath>
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\NLog.5.1.4\lib\net46\NLog.dll</HintPath>
</Reference>
<Reference Include="StreamDeckTools, Version=3.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\StreamDeck-Tools.3.2.0\lib\net472\StreamDeckTools.dll</HintPath>
<Reference Include="StreamDeckTools, Version=6.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\StreamDeck-Tools.6.1.1\lib\netstandard2.0\StreamDeckTools.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common, Version=4.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\System.Drawing.Common.5.0.2\lib\net461\System.Drawing.Common.dll</HintPath>
<Reference Include="System.Drawing.Common, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\DotNet\StreamDeck\packages\System.Drawing.Common.7.0.0\lib\net462\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.Serialization" />
Expand All @@ -84,6 +104,8 @@
<ItemGroup>
<Compile Include="Actions\UWPLauncherAction.cs" />
<Compile Include="Actions\SteamLauncherAction.cs" />
<Compile Include="Backend\GraphicsExtensionMethods.cs" />
<Compile Include="Backend\ProcessesCache.cs" />
<Compile Include="Backend\SteamAppInfo.cs" />
<Compile Include="Backend\SteamInstalledApplication.cs" />
<Compile Include="Backend\UWPManager.cs" />
Expand Down
18 changes: 9 additions & 9 deletions streamdeck-advancedlauncher/App.config
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CommandLine" publicKeyToken="5a870481e358d379" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
<assemblyIdentity name="CommandLine" publicKeyToken="5a870481e358d379" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.2" newVersion="4.0.0.2" />
<assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</configuration>
26 changes: 26 additions & 0 deletions streamdeck-advancedlauncher/Backend/GraphicsExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdvancedLauncher.Backend
{
internal static class GraphicsExtensionMethods
{
public static void DrawCircle(this Graphics g, Pen pen,
float centerX, float centerY, float radius)
{
g.DrawEllipse(pen, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}

public static void FillCircle(this Graphics g, Brush brush,
float centerX, float centerY, float radius)
{
g.FillEllipse(brush, centerX - radius, centerY - radius,
radius + radius, radius + radius);
}
}
}
Loading

0 comments on commit 634400e

Please sign in to comment.