-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
316 additions
and
264 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,3 +364,4 @@ FodyWeavers.xsd | |
|
||
#Raw image resources | ||
*.afphoto | ||
*.afdesign |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using SharpDeck; | ||
using SharpDeck.Enums; | ||
using SharpDeck.Events.Received; | ||
|
||
namespace Revelator.io24.StreamDeck.Actions | ||
{ | ||
public abstract class ActionBase<TSettings> : StreamDeckAction | ||
where TSettings : class, new() | ||
{ | ||
//We need some how to know the settings when Events are received. | ||
//In other situations, use GetSettings. | ||
protected TSettings _settings { get; private set; } = new (); | ||
|
||
protected async Task RefreshState() | ||
{ | ||
var state = GetButtonState() ? 0 : 1; | ||
await SetStateAsync(state); | ||
} | ||
|
||
protected override async Task OnDidReceiveSettings(ActionEventArgs<ActionPayload> args) | ||
{ | ||
await base.OnDidReceiveSettings(args); | ||
|
||
_settings = args.Payload | ||
.GetSettings<TSettings>() ?? new (); | ||
|
||
await SettingsChanged(); | ||
|
||
await RefreshState(); | ||
} | ||
|
||
protected override async Task OnWillAppear(ActionEventArgs<AppearancePayload> args) | ||
{ | ||
await base.OnWillAppear(args); | ||
|
||
_settings = args.Payload | ||
.GetSettings<TSettings>() ?? new(); | ||
|
||
RegisterCallbacks(); | ||
|
||
await SettingsChanged(); | ||
|
||
await RefreshState(); | ||
} | ||
|
||
protected override async Task OnWillDisappear(ActionEventArgs<AppearancePayload> args) | ||
{ | ||
await base.OnWillDisappear(args); | ||
|
||
UnregisterCallbacks(); | ||
} | ||
|
||
protected override async Task OnKeyUp(ActionEventArgs<KeyPayload> args) | ||
{ | ||
await base.OnKeyUp(args); | ||
|
||
_settings = args.Payload | ||
.GetSettings<TSettings>() ?? new(); | ||
|
||
OnButtonPress(); | ||
|
||
var state = GetButtonState() ? 0 : 1; | ||
await SetStateAsync(state); | ||
} | ||
|
||
protected abstract void RegisterCallbacks(); | ||
protected abstract void UnregisterCallbacks(); | ||
protected abstract void OnButtonPress(); | ||
protected abstract bool GetButtonState(); | ||
protected abstract Task SettingsChanged(); | ||
|
||
protected async Task SetImageStates(string on, string off) | ||
{ | ||
try | ||
{ | ||
var onImageBytes = File.ReadAllBytes($"./Images/Plugin/{on}.png"); | ||
var onBase64 = Convert.ToBase64String(onImageBytes); | ||
await SetImageAsync("data:image/png;base64," + onBase64, TargetType.Both, 0); | ||
|
||
var offImageBytes = File.ReadAllBytes($"./Images/Plugin/{off}.png"); | ||
var offBase64 = Convert.ToBase64String(offImageBytes); | ||
await SetImageAsync("data:image/png;base64," + offBase64, TargetType.Both, 1); | ||
} | ||
catch | ||
{ | ||
await SetImageAsync(null); | ||
} | ||
} | ||
} | ||
} |
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.