diff --git a/docs/config.md b/docs/config.md index 864e540d..c88edc7c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -62,16 +62,17 @@ module.exports = { */ afterDevices(devices) { // Override the defaults for plustek scanners - const device = devices.filter(d => d.id.startsWith('plustek'))[0]; - if (device) { - device.features['--mode'].default = 'Color'; - device.features['--resolution'].default = 150; - device.features['--resolution'].options = [75, 150, 300, 600]; - device.features['--brightness'].default = 0; - device.features['--contrast'].default = 5; - device.features['-x'].default = 215; - device.features['-y'].default = 297; - } + devices + .filter(d => d.id.includes('plustek')) + .forEach(device => { + device.features['--mode'].default = 'Color'; + device.features['--resolution'].default = 150; + device.features['--resolution'].options = [75, 150, 300, 600]; + device.features['--brightness'].default = 0; + device.features['--contrast'].default = 5; + device.features['-x'].default = 215; + device.features['-y'].default = 297; + }); } }; ``` @@ -90,13 +91,14 @@ options. */ afterDevices(devices) { // Override the defaults for plustek scanners - const device = devices.filter(d => d.id.startsWith('plustek'))[0]; - if (device) { - device.features['--resolution'].default = 150; - device.features['--resolution'].options = [75, 150, 300, 600]; - device.features['-x'].default = 215; - device.features['-y'].default = 297; - } + devices + .filter(d => d.id.includes('plustek')) + .forEach(device => { + device.features['--resolution'].default = 150; + device.features['--resolution'].options = [75, 150, 300, 600]; + device.features['-x'].default = 215; + device.features['-y'].default = 297; + }); } ``` @@ -108,15 +110,36 @@ the cropping logic because scanservjs incorrectly trusts the SANE output. ```javascript afterDevices(devices) { - const device = devices.filter(d => d.id.includes('brother'))[0]; - if (device) { - device.features['-l'].limits = [0, 215]; - device.features['-t'].limits = [0, 297]; - device.features['-x'].default = 215; - device.features['-x'].limits = [0, 215]; - device.features['-y'].default = 297; - device.features['-y'].limits = [0, 297]; - } + devices + .filter(d => d.id.includes('brother')) + .forEach(device => { + device.features['-l'].limits = [0, 215]; + device.features['-t'].limits = [0, 297]; + device.features['-x'].default = 215; + device.features['-x'].limits = [0, 215]; + device.features['-y'].default = 297; + device.features['-y'].limits = [0, 297]; + }); + } +``` + +### Friendly device name + +If you have many scanners available then you may wish to give devices friendly +names as per [#212](https://github.com/sbs20/scanservjs/issues/212). +`{ScanDevice}` objects have a `name` attribute which defaults to the `id` but +can be anything you want it to be. You just need to override it. + +```javascript + afterDevices(devices) { + const deviceNames = { + 'plustek:libusb:001:003': 'Downstairs Canon Flatbed', + 'test:device:unreal': 'Upstairs Canon MFD' + }; + + devices + .filter(d => d.id in deviceNames) + .forEach(d => d.name = deviceNames[d.id]); } ``` diff --git a/server/src/device.js b/server/src/device.js index b4b6dd14..b7b18718 100644 --- a/server/src/device.js +++ b/server/src/device.js @@ -74,6 +74,7 @@ class Adapter { * @returns {ScanDevice} */ static decorate(device) { + device.name = device.id; for (const key in device.features) { const feature = device.features[key]; feature.parameters = feature.parameters.replace(/^auto\|/, ''); diff --git a/server/src/types.js b/server/src/types.js index 68c2f07f..015c9d3f 100644 --- a/server/src/types.js +++ b/server/src/types.js @@ -23,6 +23,7 @@ /** * @typedef {Object} ScanDevice * @property {string} id + * @property {string} name * @property {string} version * @property {Object.} features */ diff --git a/webui/src/components/Scan.vue b/webui/src/components/Scan.vue index d86e3f87..b823a7e1 100644 --- a/webui/src/components/Scan.vue +++ b/webui/src/components/Scan.vue @@ -6,7 +6,7 @@ + :items="context.devices" return-object item-text="name" @change="clear">