forked from IsaacSchemm/casthelper.exe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RokuRemote.cs
67 lines (56 loc) · 1.76 KB
/
RokuRemote.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using RokuDotNet.Client.Input;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CastHelper {
public partial class RokuRemote : Form {
private readonly IRokuDeviceInput _roku;
public Task LastTask { get; private set; } = Task.CompletedTask;
public string LabelText {
get {
return label1.Text;
}
set {
label1.Text = value;
}
}
public RokuRemote(IRokuDeviceInput roku) {
_roku = roku;
InitializeComponent();
}
private async void RokuKeyPress(SpecialKeys key) {
if (_roku == null) return;
try {
await _roku.KeyPressAsync(key);
} catch (Exception) {
MessageBox.Show(this, "Could not connect to the Roku device.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnInstantReplay_Click(object sender, EventArgs e) {
RokuKeyPress(SpecialKeys.InstantReplay);
}
private void btnRewind_Click(object sender, EventArgs e) {
RokuKeyPress(SpecialKeys.Reverse);
}
private void btnPlayPause_Click(object sender, EventArgs e) {
RokuKeyPress(SpecialKeys.Play);
}
private void btnFastForward_Click(object sender, EventArgs e) {
RokuKeyPress(SpecialKeys.Forward);
}
private void btnClose_Click(object sender, EventArgs e) {
Close();
}
private void RokuRemote_FormClosing(object sender, FormClosingEventArgs e) {
var result = MessageBox.Show(this, "Would you like to stop video playback on the Roku?", Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (result == DialogResult.Cancel) e.Cancel = true;
if (result == DialogResult.Yes) LastTask = _roku?.KeyPressAsync(SpecialKeys.Home);
}
}
}