Add support for the "Open" action
This commit is contained in:
parent
4a7f7eef5f
commit
c0f9bdd37b
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
urlPath = "/url/open"
|
urlPath = "/url/open"
|
||||||
|
openPath = "/cmd/open"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RemoteClient struct {
|
type RemoteClient struct {
|
||||||
|
@ -32,6 +33,22 @@ func New(host, token string) *RemoteClient {
|
||||||
return &RemoteClient{client: client, baseUrl: "https://" + host, token: token}
|
return &RemoteClient{client: client, baseUrl: "https://" + host, token: token}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RemoteClient) Open(path string) error {
|
||||||
|
formData := url.Values{
|
||||||
|
"path": {path},
|
||||||
|
}
|
||||||
|
|
||||||
|
status, _, err := r.doRequest(openPath, formData)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if status != http.StatusOK {
|
||||||
|
return errors.New("invalid status: " + strconv.Itoa(status))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *RemoteClient) OpenURL(urlStr string) error {
|
func (r *RemoteClient) OpenURL(urlStr string) error {
|
||||||
formData := url.Values{
|
formData := url.Values{
|
||||||
"url": {urlStr},
|
"url": {urlStr},
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
|
@ -5,29 +5,42 @@
|
||||||
"Name": "SSH",
|
"Name": "SSH",
|
||||||
"States": [
|
"States": [
|
||||||
{
|
{
|
||||||
"Image": "ssh",
|
"Image": "images/actions/ssh",
|
||||||
"TitleAlignment": "bottom",
|
"TitleAlignment": "bottom",
|
||||||
"FontSize": "16"
|
"FontSize": "16"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"SupportedInMultiActions": false,
|
|
||||||
"Tooltip": "Execute a command over SSH",
|
"Tooltip": "Execute a command over SSH",
|
||||||
"UUID": "tf.meow.remote.ssh",
|
"UUID": "tf.meow.remote.ssh",
|
||||||
"PropertyInspectorPath": "pi/index_pi.html"
|
"PropertyInspectorPath": "pi/index_pi.html"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Icon": "images/actions/website",
|
"Icon": "images/actions/website-icon",
|
||||||
"Name": "Website",
|
"Name": "Website",
|
||||||
"States": [
|
"States": [
|
||||||
{
|
{
|
||||||
"Image": "website",
|
"Image": "images/actions/website",
|
||||||
|
"TitleAlignment": "bottom",
|
||||||
|
"FontSize": "16"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Tooltip": "Open a website on a remote computer",
|
||||||
|
"UUID": "tf.meow.remote.website",
|
||||||
|
"PropertyInspectorPath": "pi/index_pi_server.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Icon": "images/actions/website-icon",
|
||||||
|
"Name": "Website",
|
||||||
|
"States": [
|
||||||
|
{
|
||||||
|
"Image": "images/actions/website",
|
||||||
"TitleAlignment": "bottom",
|
"TitleAlignment": "bottom",
|
||||||
"FontSize": "16"
|
"FontSize": "16"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"SupportedInMultiActions": false,
|
"SupportedInMultiActions": false,
|
||||||
"Tooltip": "Open a website on a remote computer",
|
"Tooltip": "Open a file on a remote computer",
|
||||||
"UUID": "tf.meow.remote.website",
|
"UUID": "tf.meow.remote.open",
|
||||||
"PropertyInspectorPath": "pi/index_pi_server.html"
|
"PropertyInspectorPath": "pi/index_pi_server.html"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 234 B |
|
@ -0,0 +1,3 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="10" viewBox="0 0 12 10">
|
||||||
|
<polygon fill="#FFF" points="7.2 7.5 7.2 -1.3 8.7 -1.3 8.6 9.1 2.7 8.7 2.7 7.2" transform="rotate(37 5.718 3.896)"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 210 B |
|
@ -76,17 +76,14 @@ function connectElgatoStreamDeckSocket (inPort, inUUID, inRegisterEvent, inInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
function initPropertyInspector(initDelay) {
|
function initPropertyInspector(initDelay) {
|
||||||
if (actionInfo['action'] == 'tf.meow.remote.website') {
|
const action = actionInfo['action'];
|
||||||
$('#url_container').show();
|
|
||||||
$('#url_background_container').show();
|
$('[data-action=' + action + ']').removeClass('hidden');
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(settings).forEach(function (item) {
|
Object.keys(settings).forEach(function (item) {
|
||||||
let $item = $('#' + item),
|
let $item = $('#' + item),
|
||||||
value = settings[item];
|
value = settings[item];
|
||||||
|
|
||||||
console.log('Load setting', item, 'value', value);
|
|
||||||
|
|
||||||
switch ($item.attr('type')) {
|
switch ($item.attr('type')) {
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
let itemVal = $item.attr('value');
|
let itemVal = $item.attr('value');
|
||||||
|
|
|
@ -23,17 +23,22 @@
|
||||||
<input type="text" id="remote_token" class="sdpi-item-value" value="" required>
|
<input type="text" id="remote_token" class="sdpi-item-value" value="" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="sdpi-item" id="url_container" style="display: none;">
|
<div class="sdpi-item hidden" id="url_container" data-action="tf.meow.remote.website">
|
||||||
<div class="sdpi-item-label">URL</div>
|
<div class="sdpi-item-label">URL</div>
|
||||||
<input type="text" id="url" class="sdpi-item-value" value="" required>
|
<input type="text" id="url" class="sdpi-item-value" value="" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="url_background_container" type="checkbox" class="sdpi-item" style="display: none;">
|
<div id="url_background_container" data-action="tf.meow.remote.website" type="checkbox" class="sdpi-item hidden">
|
||||||
<div class="sdpi-item-label">Options</div>
|
<div class="sdpi-item-label">Options</div>
|
||||||
<input class="sdpi-item-value" id="background" type="checkbox" value="true">
|
<input class="sdpi-item-value" id="background" type="checkbox" value="true">
|
||||||
<label for="background"><span></span>Access in background</label>
|
<label for="background"><span></span>Access in background</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="sdpi-item hidden" id="path_container" data-action="tf.meow.remote.open">
|
||||||
|
<div class="sdpi-item-label">App / File</div>
|
||||||
|
<input type="text" id="path" class="sdpi-item-value" value="" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- <script src="echomd.js"></script> -->
|
<!-- <script src="echomd.js"></script> -->
|
||||||
<script
|
<script
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
const (
|
const (
|
||||||
sshAction = "tf.meow.remote.ssh"
|
sshAction = "tf.meow.remote.ssh"
|
||||||
websiteAction = "tf.meow.remote.website"
|
websiteAction = "tf.meow.remote.website"
|
||||||
|
openAction = "tf.meow.remote.open"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -20,6 +21,7 @@ func main() {
|
||||||
|
|
||||||
sdk.RegisterAction(sshAction, sshActionHandler)
|
sdk.RegisterAction(sshAction, sshActionHandler)
|
||||||
sdk.RegisterAction(websiteAction, serverActionHandler(websiteActionHandler))
|
sdk.RegisterAction(websiteAction, serverActionHandler(websiteActionHandler))
|
||||||
|
sdk.RegisterAction(openAction, serverActionHandler(openActionHandler))
|
||||||
|
|
||||||
err = sdk.Open()
|
err = sdk.Open()
|
||||||
|
|
||||||
|
|
23
server.go
23
server.go
|
@ -51,6 +51,7 @@ func websiteActionHandler(context, host, token string, settings *fastjson.Value)
|
||||||
url := sdk.JsonStringValue(settings, "url")
|
url := sdk.JsonStringValue(settings, "url")
|
||||||
|
|
||||||
if url == "" {
|
if url == "" {
|
||||||
|
sdk.ShowAlert(context)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,3 +80,25 @@ func websiteActionHandler(context, host, token string, settings *fastjson.Value)
|
||||||
sdk.ShowOk(context)
|
sdk.ShowOk(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func openActionHandler(context, host, token string, settings *fastjson.Value) {
|
||||||
|
c := client.New(host, token)
|
||||||
|
|
||||||
|
path := sdk.JsonStringValue(settings, "path")
|
||||||
|
|
||||||
|
if path == "" {
|
||||||
|
sdk.ShowAlert(context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := c.Open(path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("error opening path:", err)
|
||||||
|
|
||||||
|
sdk.ShowAlert(context)
|
||||||
|
} else {
|
||||||
|
sdk.ShowOk(context)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue