plugin work, page navigation, reticks
This commit is contained in:
49
stream_deck_plugin/ClipTrimDotNet/Keys/ClipSave.cs
Normal file
49
stream_deck_plugin/ClipTrimDotNet/Keys/ClipSave.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using BarRaider.SdTools;
|
||||
using ClipTrimDotNet.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClipTrimDotNet.Keys
|
||||
{
|
||||
[PluginActionId("com.michal-courson.cliptrim.clip-save")]
|
||||
public class ClipSave : KeypadBase
|
||||
{
|
||||
public ClipSave(SDConnection connection, InitialPayload payload) : base(connection, payload)
|
||||
{
|
||||
GlobalSettingsManager.Instance.RequestGlobalSettings();
|
||||
}
|
||||
public void Instance_OnReceivedGlobalSettings(object sender, ReceivedGlobalSettingsPayload e)
|
||||
{
|
||||
Tools.AutoPopulateSettings(GlobalSettings.Instance, e.Settings);
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
public override void KeyPressed(KeyPayload payload)
|
||||
{
|
||||
ClipTrimClient.Instance.SaveClip();
|
||||
}
|
||||
|
||||
|
||||
public override void OnTick()
|
||||
{
|
||||
}
|
||||
|
||||
public override void KeyReleased(KeyPayload payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ReceivedSettings(ReceivedSettingsPayload payload)
|
||||
{
|
||||
|
||||
}
|
||||
public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
|
||||
{
|
||||
Tools.AutoPopulateSettings(GlobalSettings.Instance, payload.Settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
107
stream_deck_plugin/ClipTrimDotNet/Keys/PageNavigator.cs
Normal file
107
stream_deck_plugin/ClipTrimDotNet/Keys/PageNavigator.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using BarRaider.SdTools;
|
||||
using ClipTrimDotNet.Client;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClipTrimDotNet.Keys
|
||||
{
|
||||
[PluginActionId("com.michal-courson.cliptrim.page-navigator")]
|
||||
public class PageNavigator : KeypadBase
|
||||
{
|
||||
static List<PageNavigator> instances = new();
|
||||
private KeyCoordinates coordinates;
|
||||
public PageNavigator(SDConnection connection, InitialPayload payload) : base(connection, payload)
|
||||
{
|
||||
coordinates = payload.Coordinates;
|
||||
GlobalSettingsManager.Instance.RequestGlobalSettings();
|
||||
instances.Add(this);
|
||||
OnTick();
|
||||
}
|
||||
public void Instance_OnReceivedGlobalSettings(object sender, ReceivedGlobalSettingsPayload e)
|
||||
{
|
||||
Tools.AutoPopulateSettings(GlobalSettings.Instance, e.Settings);
|
||||
}
|
||||
public int GetIndex()
|
||||
{
|
||||
int index = Math.Min(Math.Max(coordinates.Column - 1, 0), 2);
|
||||
return index;
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
public override void KeyPressed(KeyPayload payload)
|
||||
{
|
||||
switch (GetIndex())
|
||||
{
|
||||
case 0:
|
||||
ClipTrimClient.Instance.PageDown();
|
||||
break;
|
||||
case 1:
|
||||
ClipTrimClient.Instance.PageMode = !ClipTrimClient.Instance.PageMode;
|
||||
break;
|
||||
case 2:
|
||||
ClipTrimClient.Instance.PageUp();
|
||||
break;
|
||||
}
|
||||
Player.TickAll();
|
||||
TickAll();
|
||||
}
|
||||
|
||||
public static void TickAll()
|
||||
{
|
||||
foreach (var instance in instances)
|
||||
{
|
||||
instance.OnTick();
|
||||
}
|
||||
instances.RemoveAll(i => i == null);
|
||||
}
|
||||
|
||||
private async void SetTitle()
|
||||
{
|
||||
switch (GetIndex())
|
||||
{
|
||||
case 0:
|
||||
await Connection.SetTitleAsync(ClipTrimClient.Instance.CanPageDown ? "<" : "");
|
||||
break;
|
||||
case 1:
|
||||
await Connection.SetTitleAsync((ClipTrimClient.Instance.PageIndex + 1).ToString());
|
||||
break;
|
||||
case 2:
|
||||
await Connection.SetTitleAsync(ClipTrimClient.Instance.CanPageUp ? ">" : "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnTick()
|
||||
{
|
||||
SetTitle();
|
||||
}
|
||||
|
||||
public override void KeyReleased(KeyPayload payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ReceivedSettings(ReceivedSettingsPayload payload)
|
||||
{
|
||||
|
||||
}
|
||||
public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
|
||||
{
|
||||
Tools.AutoPopulateSettings(GlobalSettings.Instance, payload.Settings);
|
||||
//if (payload.Settings == null || payload.Settings.Count == 0)
|
||||
//{
|
||||
// var inst = GlobalSettings.Instance;
|
||||
// //GlobalSettingsManager.Instance.SetGlobalSettings(JObject.FromObject(inst));
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// GlobalSettings.Instance = payload.Settings.ToObject<GlobalSettings>();
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
stream_deck_plugin/ClipTrimDotNet/Keys/Player.cs
Normal file
87
stream_deck_plugin/ClipTrimDotNet/Keys/Player.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using BarRaider.SdTools;
|
||||
using BarRaider.SdTools.Wrappers;
|
||||
using ClipTrimDotNet.Client;
|
||||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Dynamic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClipTrimDotNet.Keys
|
||||
{
|
||||
[PluginActionId("com.michal-courson.cliptrim.player")]
|
||||
public class Player : KeypadBase
|
||||
{
|
||||
|
||||
private int coordIndex;
|
||||
private string? current_text = null;
|
||||
private KeyCoordinates coordinates;
|
||||
|
||||
static List<Player> instances = new();
|
||||
|
||||
public Player(SDConnection connection, InitialPayload payload) : base(connection, payload)
|
||||
{
|
||||
coordinates = payload.Coordinates;
|
||||
GlobalSettingsManager.Instance.RequestGlobalSettings();
|
||||
instances.Add(this);
|
||||
coordIndex = Math.Max((coordinates.Row - 1) * 5 + coordinates.Column, 0);
|
||||
OnTick();
|
||||
}
|
||||
|
||||
public static void TickAll()
|
||||
{
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, "Ticking all Player instances" + instances.Count);
|
||||
foreach (var instance in instances)
|
||||
{
|
||||
instance.OnTick();
|
||||
}
|
||||
instances.RemoveAll(i => i == null);
|
||||
}
|
||||
|
||||
private async void CheckFile()
|
||||
{
|
||||
var next_text = ClipTrimClient.Instance.GetPlayerStringByCoordinateIndex(coordIndex);
|
||||
if(next_text != current_text)
|
||||
{
|
||||
current_text = next_text;
|
||||
await Connection.SetTitleAsync($"{current_text ?? ""}");
|
||||
}
|
||||
current_text = next_text;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public override void KeyPressed(KeyPayload payload)
|
||||
{
|
||||
ClipTrimClient.Instance.PlayClip(coordIndex);
|
||||
}
|
||||
|
||||
|
||||
public override void OnTick() {
|
||||
CheckFile();
|
||||
}
|
||||
|
||||
|
||||
public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) {
|
||||
Tools.AutoPopulateSettings(GlobalSettings.Instance, payload.Settings);
|
||||
}
|
||||
|
||||
public override void KeyReleased(KeyPayload payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ReceivedSettings(ReceivedSettingsPayload payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
136
stream_deck_plugin/ClipTrimDotNet/Keys/ProfileSwitcher.cs
Normal file
136
stream_deck_plugin/ClipTrimDotNet/Keys/ProfileSwitcher.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using BarRaider.SdTools;
|
||||
using BarRaider.SdTools.Wrappers;
|
||||
using ClipTrimDotNet.Client;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Dynamic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ClipTrimDotNet.Keys
|
||||
{
|
||||
public class DataSourceItem
|
||||
{
|
||||
public string label { get; set; } = "";
|
||||
public string value { get; set; } = "";
|
||||
}
|
||||
[PluginActionId("com.michal-courson.cliptrim.profile-switcher")]
|
||||
public class ProfileSwitcher : KeypadBase
|
||||
{
|
||||
private class PluginSettings
|
||||
{
|
||||
public static PluginSettings CreateDefaultSettings()
|
||||
{
|
||||
PluginSettings instance = new PluginSettings();
|
||||
instance.ProfileName = null;
|
||||
return instance;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "profileName")]
|
||||
public string? ProfileName { get; set; }
|
||||
}
|
||||
|
||||
#region Private Members
|
||||
|
||||
private PluginSettings settings;
|
||||
|
||||
#endregion
|
||||
public ProfileSwitcher(SDConnection connection, InitialPayload payload) : base(connection, payload)
|
||||
{
|
||||
if (payload.Settings == null || payload.Settings.Count == 0)
|
||||
{
|
||||
settings = PluginSettings.CreateDefaultSettings();
|
||||
SaveSettings();
|
||||
}
|
||||
else
|
||||
{
|
||||
settings = payload.Settings.ToObject<PluginSettings>()!;
|
||||
}
|
||||
Logger.Instance.LogMessage(TracingLevel.INFO, $"ProfileSwitcher initialized with payload {JsonConvert.SerializeObject(payload)}");
|
||||
GlobalSettingsManager.Instance.RequestGlobalSettings();
|
||||
Connection.OnSendToPlugin += Connection_OnSendToPlugin;
|
||||
SetTitle();
|
||||
}
|
||||
|
||||
private async void SetTitle()
|
||||
{
|
||||
|
||||
await Connection.SetTitleAsync(settings.ProfileName + " B");
|
||||
}
|
||||
|
||||
private async void Connection_OnSendToPlugin(object? sender, SDEventReceivedEventArgs<BarRaider.SdTools.Events.SendToPlugin> e)
|
||||
{
|
||||
//Logger.Instance.LogMessage(TracingLevel.INFO, "get profiles");
|
||||
if (e.Event.Payload["event"] is null) return;
|
||||
|
||||
if (e.Event.Payload["event"]!.ToString() == "getProfiles")
|
||||
{
|
||||
var files = ClipTrimClient.Instance.GetCollectionNames();
|
||||
var items = files.Select(x => new DataSourceItem { label = x, value = x});
|
||||
var obj = new JObject
|
||||
{
|
||||
["event"] = "getProfiles",
|
||||
["items"] = JArray.FromObject(items)
|
||||
};
|
||||
await Connection.SendToPropertyInspectorAsync(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public override async void KeyPressed(KeyPayload payload)
|
||||
{
|
||||
GlobalSettings.Instance.SetCurrentProfile(settings.ProfileName??"");
|
||||
|
||||
await Connection.SetGlobalSettingsAsync(JObject.FromObject(GlobalSettings.Instance));
|
||||
await Connection.SwitchProfileAsync("ClipTrim");
|
||||
}
|
||||
|
||||
public override void KeyReleased(KeyPayload payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnTick()
|
||||
{
|
||||
SetTitle();
|
||||
}
|
||||
|
||||
public override void ReceivedSettings(ReceivedSettingsPayload payload)
|
||||
{
|
||||
Tools.AutoPopulateSettings(settings, payload.Settings);
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload)
|
||||
{
|
||||
Tools.AutoPopulateSettings(GlobalSettings.Instance, payload.Settings);
|
||||
//if (payload.Settings == null || payload.Settings.Count == 0)
|
||||
//{
|
||||
// var inst = GlobalSettings.Instance;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// GlobalSettings.Instance = payload.Settings.ToObject<GlobalSettings>();
|
||||
//}
|
||||
}
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private Task SaveSettings()
|
||||
{
|
||||
return Connection.SetSettingsAsync(JObject.FromObject(settings));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user