-
-
Notifications
You must be signed in to change notification settings - Fork 91
Add hyprpaper support #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
const hyprpaper = childProcess.spawn('script', ['--quiet', '--command', 'hyprpaper', '/dev/null']); | ||
hyprpaper.stdout.on('data', data => { | ||
if (data.toString().includes('[ERR]') || data.toString().includes('error')) { | ||
throw new Error(data.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot throw from here. Use reject
.
// Query output looks like: | ||
// eDP-1 = /path/to/image | ||
// HDMI-A-1 = /path/to/image | ||
return query.split(' ').at(-1).replace(/(\r\n|\n|\r)/gm, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear what the replace
call is supposed to do. But I would split on newlines first and then on =
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used .replace() to remove newlines. If you split on newlines then on '=' in result there will be extra space like here: ' /path/to/image' instead of '/path/to/image'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can you 'trim()' then
export async function set(imagePath) { | ||
await initialize(); | ||
const commandArray = []; | ||
const {stdout: monitors} = await exec('hyprctl monitors | grep "Monitor" | awk \'{ print $2 }\''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use execFile
. Transformations should be done in JS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too, add a comment what the output of hyprctl monitors
looks like.
for (const monitor of monitors.split('\n').slice(0, -1)) { | ||
commandArray.push(execFile('hyprctl', ['hyprpaper', 'wallpaper', `${monitor},${imagePath}`])); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use .map
instead of a loop.
return new Promise((resolve, reject) => { | ||
const hyprpaper = childProcess.spawn('script', ['--quiet', '--command', 'hyprpaper', '/dev/null']); | ||
hyprpaper.stdout.on('data', data => { | ||
if (data.toString().includes('[ERR]') || data.toString().includes('error')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really fragile. Would be better to check exit code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then where it should resolve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the subprocess exit handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But hyprpaper must always work in background
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it exits if it encounters an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But I think at error we should reject promise not resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never said it should not reject.
Commenting this for a second time: #99 (comment) |
Also, please open an issue on https://github.com/hyprwm/hyprpaper to provide this info in a machine readable-format like JSON. It's ridiculous having to parse this manually. |
const formattedQuery = query.split('\n').slice(0, -1).map(row => [row.split('=')[0], row.split('=')[1].trim()]); | ||
const fallBackImage = formattedQuery.find(row => row[0] === ' ')[1]; | ||
|
||
if (fallBackImage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (fallBackImage) { | |
if (fallbackImage) { |
Add hyprpaper support