Skip to content

Commit

Permalink
Moved common files to external library
Browse files Browse the repository at this point in the history
  • Loading branch information
BarRaider committed Jan 17, 2019
1 parent 058f1f5 commit 8526903
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 67 deletions.
11 changes: 6 additions & 5 deletions Stopwatch/PluginContainer.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using BarRaider.SdTools;
using Newtonsoft.Json;
using streamdeck_client_csharp;
using streamdeck_client_csharp.Events;
using System;
Expand All @@ -18,7 +19,7 @@ class PluginContainer
private SemaphoreSlim instancesLock = new SemaphoreSlim(1);

// Holds all instances of plugin
private static Dictionary<string, StopwatchTimer> instances = new Dictionary<string, StopwatchTimer>();
private static Dictionary<string, IPluginable> instances = new Dictionary<string, IPluginable>();


public void Run(StreamDeckOptions options)
Expand Down Expand Up @@ -58,7 +59,7 @@ private async void Connection_OnKeyDown(object sender, StreamDeckEventReceivedEv
{
if (instances.ContainsKey(e.Event.Context))
{
instances[e.Event.Context].TriggerStopwatch();
instances[e.Event.Context].KeyPressed();
}
}
finally
Expand Down Expand Up @@ -91,9 +92,9 @@ private async void RunTick()
await instancesLock.WaitAsync();
try
{
foreach (KeyValuePair<string, StopwatchTimer> kvp in instances.ToArray())
foreach (KeyValuePair<string, IPluginable> kvp in instances.ToArray())
{
_ = connection.SetTitleAsync(kvp.Value.GetCurrentStopwatchValue(), kvp.Key, SDKTarget.HardwareAndSoftware);
kvp.Value.OnTick();
}
}
finally
Expand Down
3 changes: 2 additions & 1 deletion Stopwatch/Program.cs
@@ -1,4 +1,5 @@
using CommandLine;
using BarRaider.SdTools;
using CommandLine;
using System;

namespace Stopwatch
Expand Down
12 changes: 12 additions & 0 deletions Stopwatch/PropertyInspector/Index.js
Expand Up @@ -64,6 +64,18 @@ function sendPayloadToPlugin(payload) {
}
}

function openWebsite() {
if (websocket && (websocket.readyState === 1)) {
const json = {
'event': 'openUrl',
'payload': {
'url': 'https://BarRaider.github.io'
}
};
websocket.send(JSON.stringify(json));
}
}

// our method to pass values to the plugin
function sendValueToPlugin(value, param) {
if (websocket && (websocket.readyState === 1)) {
Expand Down
2 changes: 1 addition & 1 deletion Stopwatch/PropertyInspector/Stopwatch/Index.html
Expand Up @@ -11,7 +11,7 @@
<body>
<div class="sdpi-wrapper">
<details class="message info">
<summary>For feedback/suggestions contact me at <a href="https://BarRaider.github.io" target="_blank">https://BarRaider.github.io</a> </summary>
<summary>For feedback/suggestions contact me at <a href="https://BarRaider.github.io" target="_blank" onclick="openWebsite()">https://BarRaider.github.io</a> </summary>
</details>

<div type="checkbox" class="sdpi-item" id="MultilineStopwatch">
Expand Down
4 changes: 3 additions & 1 deletion Stopwatch/Stopwatch.csproj
Expand Up @@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="barraider-sdtools">
<HintPath>..\..\barraider-sdtools\barraider-sdtools\bin\Release\barraider-sdtools.dll</HintPath>
</Reference>
<Reference Include="CommandLine, Version=2.4.3.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.2.4.3\lib\netstandard2.0\CommandLine.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -60,7 +63,6 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StopwatchTimer.cs" />
<Compile Include="StreamDeckOptions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
39 changes: 7 additions & 32 deletions Stopwatch/StopwatchTimer.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using BarRaider.SdTools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand All @@ -9,9 +10,9 @@

namespace Stopwatch
{
public class StopwatchTimer
public class StopwatchTimer : IPluginable
{
private class InspectorSettings
private class InspectorSettings : SettingsBase
{
public static InspectorSettings CreateDefaultSettings()
{
Expand All @@ -22,36 +23,11 @@ public static InspectorSettings CreateDefaultSettings()
return instance;
}

public async void SendToPropertyInspectorAsync()
{
if (StreamDeckConnection != null && !String.IsNullOrEmpty(ContextId) && !String.IsNullOrEmpty(ActionId))
{
await StreamDeckConnection.SendToPropertyInspectorAsync(ActionId, JObject.FromObject(this), this.ContextId);
}
}

public async void SetSettingsAsync()
{
if (StreamDeckConnection != null && !String.IsNullOrEmpty(ContextId) && !String.IsNullOrEmpty(ActionId))
{
await StreamDeckConnection.SetSettingsAsync(JObject.FromObject(this), this.ContextId);
}
}

[JsonProperty(PropertyName = "resumeOnClick")]
public bool ResumeOnClick { get; set; }

[JsonProperty(PropertyName = "multiline")]
public bool Multiline { get; set; }

[JsonIgnore]
public string ActionId { private get; set; }

[JsonIgnore]
public string ContextId { private get; set; }

[JsonIgnore]
public streamdeck_client_csharp.StreamDeckConnection StreamDeckConnection { private get; set; }
}

#region Private members
Expand Down Expand Up @@ -85,7 +61,7 @@ public StopwatchTimer(streamdeck_client_csharp.StreamDeckConnection connection,
ResetCounter();
}

public void TriggerStopwatch()
public void KeyPressed()
{
// Used for long press
keyPressStart = DateTime.Now;
Expand All @@ -111,7 +87,7 @@ public void KeyReleased()
keyPressed = false;
}

public string GetCurrentStopwatchValue()
public void OnTick()
{
long total, minutes, seconds, hours;
string delimiter = settings.Multiline ? "\n" : ":";
Expand All @@ -126,7 +102,7 @@ public string GetCurrentStopwatchValue()
hours = minutes / 60;
minutes = minutes % 60;

return $"{hours.ToString("00")}{delimiter}{minutes.ToString("00")}\n{seconds.ToString("00")}";
settings.SetTitleAsync($"{hours.ToString("00")}{delimiter}{minutes.ToString("00")}\n{seconds.ToString("00")}");
}

public void UpdateSettings(JObject payload)
Expand Down Expand Up @@ -197,6 +173,5 @@ private void PauseStopwatch()
}

#endregion

}
}
24 changes: 0 additions & 24 deletions Stopwatch/StreamDeckOptions.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Stopwatch/manifest.json
Expand Up @@ -11,17 +11,17 @@
}
],
"SupportedInMultiActions": false,
"Tooltip": "Stopwatch implementation with various display and behaviour settings",
"Tooltip": "Stopwatch implementation with various display and behaviour settings.",
"UUID": "com.barraider.stopwatch",
"PropertyInspectorPath": "PropertyInspector/Stopwatch/Index.html"
}
],
"Author": "BarRaider",
"Description": "Stopwatch implementation with various display and behaviour settings",
"Description": "Stopwatch implementation with various display and behaviour settings.",
"Name": "Stopwatch",
"Icon": "Images/pluginIcon",
"URL": "https://barraider.github.io/",
"Version": "1.0",
"Version": "1.01",
"CodePath": "com.barraider.stopwatch",
"Category": "BarRaider",
"CategoryIcon": "Images/categoryIcon",
Expand Down

0 comments on commit 8526903

Please sign in to comment.