-
-
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.
Fix setting wallpaper for dark style on Gnome (#96)
Co-authored-by: Sindre Sorhus <[email protected]>
- Loading branch information
1 parent
7acda73
commit d3b90d9
Showing
1 changed file
with
17 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import {commandExists, execFile} from '../util.js'; | ||
import {commandExists, execFile, hasLine} from '../util.js'; | ||
|
||
export async function isAvailable() { | ||
return commandExists('gsettings'); | ||
} | ||
|
||
async function isDarkStyle() { | ||
const {stdout} = await execFile('gsettings', [ | ||
'get', | ||
'org.gnome.desktop.interface', | ||
'color-scheme', | ||
]); | ||
|
||
return Boolean(hasLine(stdout, '\'prefer-dark\'')); | ||
} | ||
|
||
export async function get() { | ||
const keyForStyle = (await isDarkStyle()) ? 'picture-uri-dark' : 'picture-uri'; | ||
|
||
const {stdout} = await execFile('gsettings', [ | ||
'get', | ||
'org.gnome.desktop.background', | ||
'picture-uri', | ||
keyForStyle, | ||
]); | ||
|
||
return stdout.trim().slice(8, -1); | ||
} | ||
|
||
export async function set(imagePath) { | ||
const keyForStyle = (await isDarkStyle()) ? 'picture-uri-dark' : 'picture-uri'; | ||
|
||
await execFile('gsettings', [ | ||
'set', | ||
'org.gnome.desktop.background', | ||
'picture-uri', | ||
keyForStyle, | ||
`file://${imagePath}`, | ||
]); | ||
} |