Add support for the "Open" action
This commit is contained in:
parent
4a7f7eef5f
commit
c0f9bdd37b
@ -13,6 +13,7 @@ import (
|
||||
|
||||
const (
|
||||
urlPath = "/url/open"
|
||||
openPath = "/cmd/open"
|
||||
)
|
||||
|
||||
type RemoteClient struct {
|
||||
@ -32,6 +33,22 @@ func New(host, token string) *RemoteClient {
|
||||
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 {
|
||||
formData := url.Values{
|
||||
"url": {urlStr},
|
||||
|
BIN
plugin/images/actions/open-icon.png
Normal file
BIN
plugin/images/actions/open-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
BIN
plugin/images/actions/open.png
Normal file
BIN
plugin/images/actions/open.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
BIN
plugin/images/actions/website-icon.png
Normal file
BIN
plugin/images/actions/website-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
@ -5,29 +5,42 @@
|
||||
"Name": "SSH",
|
||||
"States": [
|
||||
{
|
||||
"Image": "ssh",
|
||||
"Image": "images/actions/ssh",
|
||||
"TitleAlignment": "bottom",
|
||||
"FontSize": "16"
|
||||
}
|
||||
],
|
||||
"SupportedInMultiActions": false,
|
||||
"Tooltip": "Execute a command over SSH",
|
||||
"UUID": "tf.meow.remote.ssh",
|
||||
"PropertyInspectorPath": "pi/index_pi.html"
|
||||
},
|
||||
{
|
||||
"Icon": "images/actions/website",
|
||||
"Icon": "images/actions/website-icon",
|
||||
"Name": "Website",
|
||||
"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",
|
||||
"FontSize": "16"
|
||||
}
|
||||
],
|
||||
"SupportedInMultiActions": false,
|
||||
"Tooltip": "Open a website on a remote computer",
|
||||
"UUID": "tf.meow.remote.website",
|
||||
"Tooltip": "Open a file on a remote computer",
|
||||
"UUID": "tf.meow.remote.open",
|
||||
"PropertyInspectorPath": "pi/index_pi_server.html"
|
||||
}
|
||||
],
|
||||
|
BIN
plugin/pi/css/check.png
Normal file
BIN
plugin/pi/css/check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 234 B |
3
plugin/pi/css/check.svg
Normal file
3
plugin/pi/css/check.svg
Normal file
@ -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) {
|
||||
if (actionInfo['action'] == 'tf.meow.remote.website') {
|
||||
$('#url_container').show();
|
||||
$('#url_background_container').show();
|
||||
}
|
||||
const action = actionInfo['action'];
|
||||
|
||||
$('[data-action=' + action + ']').removeClass('hidden');
|
||||
|
||||
Object.keys(settings).forEach(function (item) {
|
||||
let $item = $('#' + item),
|
||||
value = settings[item];
|
||||
|
||||
console.log('Load setting', item, 'value', value);
|
||||
|
||||
switch ($item.attr('type')) {
|
||||
case 'checkbox':
|
||||
let itemVal = $item.attr('value');
|
||||
|
@ -23,17 +23,22 @@
|
||||
<input type="text" id="remote_token" class="sdpi-item-value" value="" required>
|
||||
</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>
|
||||
<input type="text" id="url" class="sdpi-item-value" value="" required>
|
||||
</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>
|
||||
<input class="sdpi-item-value" id="background" type="checkbox" value="true">
|
||||
<label for="background"><span></span>Access in background</label>
|
||||
</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>
|
||||
<!-- <script src="echomd.js"></script> -->
|
||||
<script
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
const (
|
||||
sshAction = "tf.meow.remote.ssh"
|
||||
websiteAction = "tf.meow.remote.website"
|
||||
openAction = "tf.meow.remote.open"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -20,6 +21,7 @@ func main() {
|
||||
|
||||
sdk.RegisterAction(sshAction, sshActionHandler)
|
||||
sdk.RegisterAction(websiteAction, serverActionHandler(websiteActionHandler))
|
||||
sdk.RegisterAction(openAction, serverActionHandler(openActionHandler))
|
||||
|
||||
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")
|
||||
|
||||
if url == "" {
|
||||
sdk.ShowAlert(context)
|
||||
return
|
||||
}
|
||||
|
||||
@ -79,3 +80,25 @@ func websiteActionHandler(context, host, token string, settings *fastjson.Value)
|
||||
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
Block a user