Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: ApplicationAction to suspend PC #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/LibCecTray/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/LibCecTray/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,7 @@ CEC will not work (properly) if the TV does not support CEC, or has CEC disabled
<data name="application_foreground" xml:space="preserve">
<value>Foreground application</value>
</data>
<data name="action_type_suspend_pc" xml:space="preserve">
<value>suspend PC</value>
</data>
</root>
73 changes: 72 additions & 1 deletion src/LibCecTray/controller/applications/ApplicationInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ enum ActionType
Generic = 0,
CloseControllerApplication = 1,
StartApplication = 2,
SendKey = 3
SendKey = 3,
SuspendPc = 4
}

/// <summary>
Expand Down Expand Up @@ -297,6 +298,8 @@ public static string FriendlyActionName(ActionType type)
return Resources.action_type_start_application;
case ActionType.SendKey:
return Resources.action_type_sendkey;
case ActionType.SuspendPc:
return Resources.action_type_suspend_pc;
default:
return type.ToString();
}
Expand Down Expand Up @@ -408,6 +411,9 @@ public static ApplicationInput FromString(ApplicationController controller, stri
if (addAction == null || addAction.Empty())
addAction = ApplicationActionStart.FromString(controller, item);

if (addAction == null || addAction.Empty())
addAction = ApplicationActionSuspendPc.FromString(controller, item);

if (addAction != null && !addAction.Empty())
retVal.Append(addAction);
}
Expand All @@ -432,10 +438,75 @@ public ApplicationInput AddAction(ActionType action)
case ActionType.StartApplication:
Append(new ApplicationActionStart(Controller));
break;
case ActionType.SuspendPc:
Append(new ApplicationActionSuspendPc(Controller));
break;
}
return this;
}

private readonly List<ApplicationAction> _input = new List<ApplicationAction>();
}

/// <summary>
/// Suspends the host PC
/// </summary>
internal class ApplicationActionSuspendPc : ApplicationAction
{
public ApplicationActionSuspendPc(ApplicationController controller) :
base(controller, ActionType.SuspendPc)
{
}

public override bool Transmit(IntPtr windowHandle)
{
return Application.SetSuspendState(PowerState.Suspend, true, false);
}

public override string AsString()
{
return TypePrefix;
}

public override string AsFriendlyString()
{
return string.Format("[{0}]", Resources.action_type_suspend_pc);
}

public override bool Empty()
{
return false;
}

public override bool CanAppend(ApplicationAction value)
{
return false;
}

public override ApplicationAction Append(ApplicationAction value)
{
return this;
}

public override ApplicationAction RemoveKey(int index)
{
return null;
}

public static ApplicationAction FromString(ApplicationController controller, string value)
{
ApplicationActionSuspendPc retVal = new ApplicationActionSuspendPc(controller);
return value.Trim().Equals(retVal.AsString()) ? retVal : null;
}

public static bool HasDefaultValue(CecKeypress key)
{
return DefaultValue(key) != null;
}

public static ApplicationAction DefaultValue(CecKeypress key)
{
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public CecButtonConfigUI(CecButtonConfigItem button)
//TODO
cbAddAction.Items.Add(ApplicationInput.FriendlyActionName(ActionType.CloseControllerApplication));
cbAddAction.Items.Add(ApplicationInput.FriendlyActionName(ActionType.StartApplication));
cbAddAction.Items.Add(ApplicationInput.FriendlyActionName(ActionType.SuspendPc));

// take the icon of the main window
ComponentResourceManager resources = new ComponentResourceManager(typeof(CECTray));
Expand Down