Resolve a few property inspector issues
This commit is contained in:
parent
e5aec34450
commit
4a7f7eef5f
@ -38,7 +38,7 @@
|
||||
"Name": "Remote",
|
||||
"Icon": "images/pluginIcon",
|
||||
"URL": "https://www.elgato.com/gaming/stream-deck",
|
||||
"Version": "1.2",
|
||||
"Version": "1.2.1",
|
||||
"SDKVersion": 2,
|
||||
"OS": [
|
||||
{
|
||||
|
@ -4,8 +4,11 @@ var websocket = null,
|
||||
uuid = null,
|
||||
actionInfo = {},
|
||||
settings = {},
|
||||
globalSettings = {},
|
||||
isQT = navigator.appVersion.includes('QtWebEngine'); // 'oninput'; // change this, if you want interactive elements act on any change, or while they're modified
|
||||
|
||||
const websiteAction = 'tf.meow.remote.website';
|
||||
|
||||
function connectSocket (
|
||||
inPort,
|
||||
inUUID,
|
||||
@ -50,12 +53,25 @@ function connectElgatoStreamDeckSocket (inPort, inUUID, inRegisterEvent, inInfo,
|
||||
};
|
||||
|
||||
websocket.send(JSON.stringify(json));
|
||||
|
||||
if (isAction(websiteAction)) {
|
||||
getGlobalSettings();
|
||||
}
|
||||
};
|
||||
|
||||
websocket.onmessage = function (evt) {
|
||||
// Received message from Stream Deck
|
||||
var jsonObj = JSON.parse(evt.data);
|
||||
var event = jsonObj['event'];
|
||||
let jsonObj = JSON.parse(evt.data);
|
||||
|
||||
let event = jsonObj['event'];
|
||||
|
||||
console.log('Got event', event);
|
||||
|
||||
switch (event) {
|
||||
case 'didReceiveGlobalSettings':
|
||||
didReceiveGlobalSettings(jsonObj);
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -66,43 +82,71 @@ function initPropertyInspector(initDelay) {
|
||||
}
|
||||
|
||||
Object.keys(settings).forEach(function (item) {
|
||||
$('#' + item).val(settings[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');
|
||||
|
||||
if (itemVal == 'false' || itemVal == 'true') {
|
||||
itemVal = (/^true$/i).test(itemVal);
|
||||
}
|
||||
|
||||
if (itemVal === value) {
|
||||
$item.prop('checked', true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$item.val(value);
|
||||
}
|
||||
});
|
||||
|
||||
$('input').each(function() {
|
||||
var $this = $(this),
|
||||
let $this = $(this),
|
||||
id = $this.attr('id');
|
||||
|
||||
let $item = $this.closest('.sdpi-item');
|
||||
|
||||
$this.on('change', function(e) {
|
||||
$this.on('change', function() {
|
||||
const type = $this.attr('type');
|
||||
|
||||
if (type) {
|
||||
const info = $item.find('.sdpi-file-info');
|
||||
|
||||
if (info) {
|
||||
const s = decodeURIComponent($this.val().replace(/^C:\\fakepath\\/, '')).split('/').pop();
|
||||
|
||||
info.text(s.length > 28
|
||||
? s.substr(0, 10)
|
||||
+ '...'
|
||||
+ s.substr(s.length - 10, s.length)
|
||||
: s);
|
||||
}
|
||||
}
|
||||
|
||||
let val = $this.val();
|
||||
|
||||
switch (type) {
|
||||
case 'checkbox':
|
||||
// If unchecked, unset the setting
|
||||
if (!this.checked) {
|
||||
removeSetting(id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (val == 'false' || val == 'true') {
|
||||
val = (/^true$/i).test(val);
|
||||
}
|
||||
break;
|
||||
case 'file':
|
||||
const info = $item.find('.sdpi-file-info');
|
||||
|
||||
if (info) {
|
||||
const s = decodeURIComponent($this.val().replace(/^C:\\fakepath\\/, '')).split('/').pop();
|
||||
|
||||
info.text(s.length > 28
|
||||
? s.substr(0, 10)
|
||||
+ '...'
|
||||
+ s.substr(s.length - 10, s.length)
|
||||
: s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
updateSetting(id, val);
|
||||
|
||||
if (isAction(websiteAction) && (id == 'remote_host' || id == 'remote_token')) {
|
||||
updateGlobalSetting(id, val);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -111,19 +155,20 @@ function initPropertyInspector(initDelay) {
|
||||
// Hide passphrase field
|
||||
$('#ssh_key_passphrase_container').hide();
|
||||
$('#ssh_password_container').show();
|
||||
return;
|
||||
} else {
|
||||
$('#ssh_password_container').hide();
|
||||
}
|
||||
|
||||
var f = e.target.files[0];
|
||||
let f = e.target.files[0];
|
||||
|
||||
var reader = new FileReader();
|
||||
let reader = new FileReader();
|
||||
|
||||
// Closure to capture the file information.
|
||||
reader.onload = function(e) {
|
||||
var result = e.target.result;
|
||||
let result = e.target.result;
|
||||
|
||||
var pki = forge.pki;
|
||||
let pki = forge.pki;
|
||||
|
||||
try {
|
||||
pki.privateKeyFromPem(result);
|
||||
@ -259,8 +304,18 @@ function updateSetting(setting, value) {
|
||||
setSettings(settings);
|
||||
}
|
||||
|
||||
function removeSetting(setting) {
|
||||
if (!settings) {
|
||||
settings = {};
|
||||
}
|
||||
|
||||
delete settings[setting];
|
||||
|
||||
setSettings(settings);
|
||||
}
|
||||
|
||||
function setSettings(settings) {
|
||||
var json = {
|
||||
let json = {
|
||||
"event": "setSettings",
|
||||
"context": uuid,
|
||||
"payload": settings
|
||||
@ -268,7 +323,49 @@ function setSettings(settings) {
|
||||
|
||||
if (websocket) {
|
||||
websocket.send(JSON.stringify(json));
|
||||
} else {
|
||||
console.log('Update:', json);
|
||||
}
|
||||
}
|
||||
|
||||
function updateGlobalSetting(id, val) {
|
||||
globalSettings[id] = val;
|
||||
|
||||
setGlobalSettings(globalSettings);
|
||||
}
|
||||
|
||||
function getGlobalSettings() {
|
||||
let json = {
|
||||
"event": "getGlobalSettings",
|
||||
"context": uuid
|
||||
};
|
||||
|
||||
if (websocket) {
|
||||
websocket.send(JSON.stringify(json));
|
||||
}
|
||||
}
|
||||
|
||||
function setGlobalSettings(settings) {
|
||||
let json = {
|
||||
"event": "setGlobalSettings",
|
||||
"context": uuid,
|
||||
"payload": settings
|
||||
};
|
||||
|
||||
if (websocket) {
|
||||
websocket.send(JSON.stringify(json));
|
||||
}
|
||||
}
|
||||
|
||||
function didReceiveGlobalSettings(obj) {
|
||||
globalSettings = getPropFromString(obj, 'payload.settings');
|
||||
|
||||
// Load defaults for fields not set
|
||||
Object.keys(globalSettings).forEach(function(item) {
|
||||
if (!(item in settings)) {
|
||||
$('#' + item).val(globalSettings[item]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isAction(action) {
|
||||
return actionInfo['action'] === action;
|
||||
}
|
Loading…
Reference in New Issue
Block a user