Skip to content

Commit

Permalink
Fix setting wallpaper for dark style on Gnome (#96)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
xero08 and sindresorhus authored Mar 18, 2024
1 parent 7acda73 commit d3b90d9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions source/linux/background-managers/gnome.js
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}`,
]);
}

0 comments on commit d3b90d9

Please sign in to comment.