Skip to content

Commit 1236c24

Browse files
doannc2212sindresorhus
authored andcommitted
Add swww support (sindresorhus#94)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent de0c717 commit 1236c24

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

source/linux/background-managers/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ module.exports = {
1313
qdbus: require('./qdbus.js'),
1414
setroot: require('./setroot.js'),
1515
xfconfquery: require('./xfconf-query.js'),
16-
swaybg: require('./swaybg.js')
16+
swaybg: require('./swaybg.js'),
17+
swww: require('./swww.js')
1718
};
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
const {commandExists, execFile} = require('../util.js');
3+
4+
exports.isAvailable = () => commandExists('swww');
5+
6+
async function initialize() {
7+
try {
8+
await execFile('swww', ['init']);
9+
} catch (error) {
10+
if (error.stderr.includes('There seems to already be another instance running')) {
11+
return;
12+
}
13+
14+
throw new Error(`Failed to set image for swww: ${error.stderr}`);
15+
}
16+
};
17+
18+
exports.get = async () => {
19+
await initialize();
20+
const {stdout: query} = await execFile('swww', ['query']);
21+
return query.slice(query.indexOf('/'), query.indexOf('\n'));
22+
};
23+
24+
exports.set = async imagePath => {
25+
await initialize();
26+
await execFile('swww', ['img', imagePath]);
27+
};

0 commit comments

Comments
 (0)