Skip to content

Commit

Permalink
feat: give names to surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jun 29, 2021
1 parent 2c988ec commit 3e3aa1c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/elgato_dm.js
Expand Up @@ -36,6 +36,14 @@ function elgatoDM(_system) {
var self = this
system = _system

self.surface_names = {}

system.emit('db_get', 'surfaces_names', function (names) {
if (names) {
self.surface_names = names
}
})

system.on('elgatodm_remove_device', self.removeDevice.bind(self))

system.on('devices_reenumerate', function () {
Expand Down Expand Up @@ -69,6 +77,15 @@ function elgatoDM(_system) {
})
})

socket.on('device_set_name', function (serialnumber, name) {
if (Object.values(instances).find((inst) => inst.serialnumber === serialnumber)) {
self.surface_names[serialnumber] = name
self.updateDevicesList()

system.emit('db_set', 'surfaces_names', self.surface_names)
}
})

socket.on('device_config_get', function (_id, answer) {
for (var id in instances) {
if (instances[id].id == _id) {
Expand Down Expand Up @@ -108,6 +125,7 @@ elgatoDM.prototype.getDevicesList = function () {
id: instance.id || '',
serialnumber: instance.serialnumber || '',
type: instance.type || '',
name: self.surface_names[instance.serialnumber] || '',
config: instance.config || {},
}))

Expand Down
16 changes: 16 additions & 0 deletions webui/src/Surfaces.jsx
Expand Up @@ -26,6 +26,7 @@ import { StaticContext, LoadingRetryOrError, socketEmit } from './util'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCog, faSync } from '@fortawesome/free-solid-svg-icons'
import shortid from 'shortid'
import { TextInputField } from './Components/TextInputField'

export const SurfacesPage = memo(function SurfacesPage() {
const context = useContext(StaticContext)
Expand Down Expand Up @@ -72,6 +73,13 @@ export const SurfacesPage = memo(function SurfacesPage() {
editModalRef.current.show(device)
}, [])

const updateName = useCallback(
(serialnumber, name) => {
context.socket.emit('device_set_name', serialnumber, name)
},
[context.socket]
)

return (
<div>
<h4>Surfaces</h4>
Expand All @@ -95,6 +103,7 @@ export const SurfacesPage = memo(function SurfacesPage() {
<tr>
<th>NO</th>
<th>ID</th>
<th>Name</th>
<th>Type</th>
<th>&nbsp;</th>
</tr>
Expand All @@ -105,6 +114,13 @@ export const SurfacesPage = memo(function SurfacesPage() {
<tr key={dev.id}>
<td>#{i}</td>
<td>{dev.serialnumber}</td>
<td>
<TextInputField
definition={{}}
value={dev.name}
setValue={(val) => updateName(dev.serialnumber, val)}
/>
</td>
<td>{dev.type}</td>
<td>
{dev?.config && dev.config.length > 0 ? (
Expand Down

0 comments on commit 3e3aa1c

Please sign in to comment.