Skip to content

Commit

Permalink
Add swww support (#94)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
doannc2212 and sindresorhus authored Oct 29, 2023
1 parent 8236cd4 commit 73c41cc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/linux/background-managers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * as qdbus from './qdbus.js';
export * as setroot from './setroot.js';
export * as xfconfquery from './xfconf-query.js';
export * as swaybg from './swaybg.js';
export * as swww from './swww.js';
28 changes: 28 additions & 0 deletions source/linux/background-managers/swww.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {commandExists, execFile} from '../util.js';

export async function isAvailable() {
return commandExists('swww');
}

async function initialize() {
try {
await execFile('swww', ['init']);
} catch (error) {
if (error.stderr.includes('There seems to already be another instance running')) {
return;
}

throw new Error(`Failed to set image for swww: ${error.stderr}`);
}
}

export async function get() {
await initialize();
const {stdout: query} = await execFile('swww', ['query']);
return query.slice(query.indexOf('/'), query.indexOf('\n'));
}

export async function set(imagePath) {
await initialize();
await execFile('swww', ['img', imagePath]);
}

0 comments on commit 73c41cc

Please sign in to comment.