mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-03 06:27:23 +01:00
add prettier
This commit is contained in:
14
cli.js
14
cli.js
@@ -25,7 +25,9 @@ if (argv.help || argv.h) {
|
|||||||
console.log('Detected devices:\n');
|
console.log('Detected devices:\n');
|
||||||
Object.keys(devices)
|
Object.keys(devices)
|
||||||
.sort(key => !devices[key].connected)
|
.sort(key => !devices[key].connected)
|
||||||
.forEach(key => console.log(key + ':', connectionStatus(devices[key])));
|
.forEach(key =>
|
||||||
|
console.log(key + ':', connectionStatus(devices[key]))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let selectedMonitors = argv._;
|
let selectedMonitors = argv._;
|
||||||
@@ -39,13 +41,19 @@ if (argv.help || argv.h) {
|
|||||||
console.log('Using profile', profile);
|
console.log('Using profile', profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Switching on', selectedMonitors.length ? selectedMonitors : 'all connected monitors');
|
console.log(
|
||||||
|
'Switching on',
|
||||||
|
selectedMonitors.length ? selectedMonitors : 'all connected monitors'
|
||||||
|
);
|
||||||
|
|
||||||
swm.getDevices((err, devices) => {
|
swm.getDevices((err, devices) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
const xrandrOptions = swm.generateXrandrOptions(selectedMonitors, devices);
|
const xrandrOptions = swm.generateXrandrOptions(
|
||||||
|
selectedMonitors,
|
||||||
|
devices
|
||||||
|
);
|
||||||
swm.switchDevices(xrandrOptions);
|
swm.switchDevices(xrandrOptions);
|
||||||
swm.executePostCmd(postCmd);
|
swm.executePostCmd(postCmd);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const configPath = require('xdg').basedir.configPath('switchmon/config.json');
|
|||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
postCmd: undefined,
|
postCmd: undefined,
|
||||||
profiles: {},
|
profiles: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let config = Object.assign({}, defaults);
|
let config = Object.assign({}, defaults);
|
||||||
|
|||||||
@@ -14,10 +14,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/tomru/switchmon.git"
|
"url": "git+https://github.com/tomru/switchmon.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": ["xrandr", "monitor"],
|
||||||
"xrandr",
|
|
||||||
"monitor"
|
|
||||||
],
|
|
||||||
"author": "Thomas Ruoff",
|
"author": "Thomas Ruoff",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
@@ -36,5 +33,9 @@
|
|||||||
"mocha-lcov-reporter": "^1.2.0",
|
"mocha-lcov-reporter": "^1.2.0",
|
||||||
"proxyquire": "^1.7.4",
|
"proxyquire": "^1.7.4",
|
||||||
"sinon": "^1.17.3"
|
"sinon": "^1.17.3"
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"tabWidth": 4,
|
||||||
|
"singleQuote": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
swm.js
6
swm.js
@@ -8,7 +8,9 @@ function executeCmd(cmd, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDevices(callback) {
|
function getDevices(callback) {
|
||||||
executeCmd('xrandr', (err, stdout) => callback(err, err ? null : xrandrParse(stdout)));
|
executeCmd('xrandr', (err, stdout) =>
|
||||||
|
callback(err, err ? null : xrandrParse(stdout))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchDevices(xrandrOptions, callback) {
|
function switchDevices(xrandrOptions, callback) {
|
||||||
@@ -23,7 +25,7 @@ function orderDeviceKeys(selectedDevices, devices) {
|
|||||||
let orderedDeviceKeys = Object.keys(devices).sort();
|
let orderedDeviceKeys = Object.keys(devices).sort();
|
||||||
|
|
||||||
// fix the sort order if monitors were explicitly selected
|
// fix the sort order if monitors were explicitly selected
|
||||||
selectedDevices.reverse().forEach((monitor) => {
|
selectedDevices.reverse().forEach(monitor => {
|
||||||
const index = orderedDeviceKeys.indexOf(monitor);
|
const index = orderedDeviceKeys.indexOf(monitor);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
console.error('Unkown monitor', monitor, '(ignored)');
|
console.error('Unkown monitor', monitor, '(ignored)');
|
||||||
|
|||||||
Reference in New Issue
Block a user