8000 Add hyprpaper support by VardanHeroic · Pull Request #99 · sindresorhus/wallpaper · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

VardanHeroic
Copy link
Contributor

Add hyprpaper support

@sindresorhus
Copy link
Owner

#99 (comment)

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());
Copy link
Owner

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, '');
Copy link
Owner

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 =.

Copy link
Contributor Author
@VardanHeroic VardanHeroic Jul 19, 2024

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'.

Copy link
Owner

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 }\'');
Copy link
Owner

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.

Copy link
Owner

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.

Comment on lines 42 to 44
for (const monitor of monitors.split('\n').slice(0, -1)) {
commandArray.push(execFile('hyprctl', ['hyprpaper', 'wallpaper', `${monitor},${imagePath}`]));
}
Copy link
Owner

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')) {
Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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.

@sindresorhus
Copy link
Owner

Commenting this for a second time: #99 (comment)

@sindresorhus
Copy link
Owner

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (fallBackImage) {
if (fallbackImage) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0