-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <[email protected]>
- Loading branch information
1 parent
8236cd4
commit 73c41cc
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} |