forked from LAB02-Research/HASS.Agent.Staging
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release fixing reported issues regarding CompatHelper and VirtualDesktop feature handling.
- Loading branch information
1 parent
0afb3f0
commit 7867123
Showing
21 changed files
with
304 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 42 additions & 63 deletions
105
...SS.Agent.Staging/HASS.Agent/HomeAssistant/Commands/CustomCommands/SwitchDesktopCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,71 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using HASS.Agent.Managers; | ||
using HASS.Agent.Shared.Enums; | ||
using HASS.Agent.Shared.Managers; | ||
using Serilog; | ||
using WindowsDesktop; | ||
|
||
namespace HASS.Agent.Shared.HomeAssistant.Commands.InternalCommands | ||
namespace HASS.Agent.Shared.HomeAssistant.Commands.InternalCommands; | ||
|
||
/// <summary> | ||
/// Activates provided Virtual Desktop | ||
/// </summary> | ||
public class SwitchDesktopCommand : InternalCommand | ||
{ | ||
/// <summary> | ||
/// Activates provided Virtual Desktop | ||
/// </summary> | ||
public class SwitchDesktopCommand : InternalCommand | ||
private const string DefaultName = "switchdesktop"; | ||
|
||
public SwitchDesktopCommand(string name = DefaultName, string friendlyName = DefaultName, string desktopId = "", CommandEntityType entityType = CommandEntityType.Switch, string id = default) : base(name ?? DefaultName, friendlyName ?? null, desktopId, entityType, id) | ||
{ | ||
CommandConfig = desktopId; | ||
State = "OFF"; | ||
} | ||
|
||
public override void TurnOn() | ||
{ | ||
private const string DefaultName = "switchdesktop"; | ||
State = "ON"; | ||
|
||
public SwitchDesktopCommand(string name = DefaultName, string friendlyName = DefaultName, string desktopId = "", CommandEntityType entityType = CommandEntityType.Switch, string id = default) : base(name ?? DefaultName, friendlyName ?? null, desktopId, entityType, id) | ||
if (string.IsNullOrWhiteSpace(CommandConfig)) | ||
{ | ||
CommandConfig = desktopId; | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Unable to launch command, it's configured as action-only", Name); | ||
|
||
State = "OFF"; | ||
return; | ||
} | ||
|
||
public override void TurnOn() | ||
{ | ||
State = "ON"; | ||
ActivateVirtualDesktop(CommandConfig); | ||
|
||
if (string.IsNullOrWhiteSpace(CommandConfig)) | ||
{ | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Unable to launch command, it's configured as action-only", Name); | ||
State = "OFF"; | ||
} | ||
|
||
State = "OFF"; | ||
return; | ||
} | ||
public override void TurnOnWithAction(string action) | ||
{ | ||
State = "ON"; | ||
|
||
ActivateVirtualDesktop(CommandConfig); | ||
if (string.IsNullOrWhiteSpace(action)) | ||
{ | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Unable to launch command, empty action provided", Name); | ||
|
||
State = "OFF"; | ||
return; | ||
} | ||
|
||
public override void TurnOnWithAction(string action) | ||
if (!string.IsNullOrWhiteSpace(CommandConfig)) | ||
{ | ||
State = "ON"; | ||
|
||
if (string.IsNullOrWhiteSpace(action)) | ||
{ | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Unable to launch command, empty action provided", Name); | ||
|
||
State = "OFF"; | ||
return; | ||
} | ||
|
||
if (!string.IsNullOrWhiteSpace(CommandConfig)) | ||
{ | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Command launched by action, command-provided process will be ignored", Name); | ||
|
||
State = "OFF"; | ||
return; | ||
} | ||
|
||
ActivateVirtualDesktop(action); | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Command launched by action, command-provided process will be ignored", Name); | ||
|
||
State = "OFF"; | ||
return; | ||
} | ||
|
||
private void ActivateVirtualDesktop(string virtualDesktopId) | ||
{ | ||
var targetDesktopGuid = Guid.Empty; | ||
var parsed = Guid.TryParse(virtualDesktopId, out targetDesktopGuid); | ||
if (!parsed) | ||
{ | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Unable to parse virtual desktop id: {virtualDesktopId}", Name, virtualDesktopId); | ||
return; | ||
} | ||
|
||
var targetDesktop = VirtualDesktop.GetDesktops().FirstOrDefault(d => d.Id == targetDesktopGuid); | ||
if (targetDesktop == null) | ||
{ | ||
Log.Warning("[SWITCHDESKTOP] [{name}] Unable to find virtual desktop with id: {virtualDesktopId}", Name, virtualDesktopId); | ||
return; | ||
} | ||
|
||
if (VirtualDesktop.Current == targetDesktop) | ||
{ | ||
Log.Information("[SWITCHDESKTOP] [{name}] Target virtual desktop '{virtualDesktopId}' is already active", Name, virtualDesktopId); | ||
return; | ||
} | ||
|
||
targetDesktop.Switch(); | ||
} | ||
ActivateVirtualDesktop(action); | ||
|
||
State = "OFF"; | ||
} | ||
|
||
private void ActivateVirtualDesktop(string virtualDesktopId) | ||
{ | ||
VirtualDesktopManager.ActivateDesktop(virtualDesktopId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.