Skip to content
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

Rewrite the Linux part #43

Merged
merged 6 commits into from Jan 9, 2019
Merged

Rewrite the Linux part #43

merged 6 commits into from Jan 9, 2019

Conversation

deather
Copy link

@deather deather commented Oct 2, 2018

This PR is in response of issue #42

I purpose you a new file organization for manage the multiple background manager on Linux.
I'm using nitrogen so for me it is working. It would be cool if some people could test before merge.

What is it changed ?

setAvailableApps iterate over all manager and test if they are available, if it is they are stored
set method just call the set method of each available background managers
get method is more difficult to write, due to multiple managers. I use a strategy consisting of count the apparition of a file, and the most used will be return.

The final point is personnal, I think it is the more discutable. I'm ok to debate on this point.
I hope this work can help.

Thanks for reading.

Create a template of background-manager based on previous template, but with 3 mehods : get, set, available
Adapt the function set get and setAvailables
@sindresorhus sindresorhus changed the title Readaptation of linux part Rewrite the Linux part Dec 22, 2018
lib/linux/background-managers/cinnamon.js Outdated Show resolved Hide resolved
lib/linux/background-managers/cinnamon.js Outdated Show resolved Hide resolved
lib/linux/background-managers/cinnamon.js Outdated Show resolved Hide resolved
lib/linux/background-managers/cinnamon.js Outdated Show resolved Hide resolved
lib/linux/background-managers/dconf.js Outdated Show resolved Hide resolved
lib/linux/index.js Outdated Show resolved Hide resolved
lib/linux/index.js Outdated Show resolved Hide resolved
lib/linux/index.js Outdated Show resolved Hide resolved
lib/linux/util.js Outdated Show resolved Hide resolved
lib/linux/util.js Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

@deather Sorry about the long delay. I've had too many PRs to review. This is looking great! It's a much better and more maintainable way to structure it.

@sindresorhus
Copy link
Owner

get method is more difficult to write, due to multiple managers. I use a strategy consisting of count the apparition of a file, and the most used will be return.

Good idea! I like it.

Moving promisify function in util.js file.
Renaming function existsCommand into commandExists
Removing the usage of exec
Using Map instead of Object for storing the wallpaper vote
Using String template instead of String concatenation
Renaming function available into isAvailable
const {stdout} = await execFile('dconf', ['read', '/org/mate/desktop/background/picture-filename']);

return stdout.trim().slice(1, -1);
} catch (_) {}
Copy link
Owner

Choose a reason for hiding this comment

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

Yes, the responsibility to ignore the errors should be in the consumer, not the get function.

You can do something like this to ignore errors:

await Promise.all(promises.map(promise => promie.catch(() => {})));

lib/linux/background-managers/cinnamon.js Outdated Show resolved Hide resolved
lib/linux/background-managers/cinnamon.js Show resolved Hide resolved
lib/linux/background-managers/cinnamon.js Outdated Show resolved Hide resolved
const {stdout} = await execFile('dconf', ['read', '/org/mate/desktop/background/picture-filename']);

return stdout.trim().slice(1, -1);
} catch (_) {}
Copy link
Owner

Choose a reason for hiding this comment

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

Actually, would be better to just change line 31 to const imagePath = await app.get().catch(() => {});

lib/linux/background-managers/xfconf-query.js Outdated Show resolved Hide resolved
lib/linux/index.js Outdated Show resolved Hide resolved
lib/linux/index.js Outdated Show resolved Hide resolved
lib/linux/util.js Outdated Show resolved Hide resolved
lib/linux/util.js Outdated Show resolved Hide resolved
Find and replace to use arrow functions.
Use of Object.values() instead of Object.entries()
Removing all useless try catch to catch errors in the global get.
Refactoring grep function into hasLine
Fixing bug between dconf.js and mate.js. When we set picture-filename with dconf it is equivalent to the usage of gsettings. So now we just set the property with the filename not the URI.
lib/linux/background-managers/mate.js Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
@sindresorhus sindresorhus merged commit 38ea0f4 into sindresorhus:master Jan 9, 2019
@sindresorhus
Copy link
Owner

This is looking great now. Thank you so much for improving this, @deather 🙌

@sindresorhus
Copy link
Owner

@deather Would you be interested in joining the project as a maintainer?

@deather
Copy link
Author

deather commented Jan 9, 2019

@sindresorhus It will be cool, you can rely on me for this project 😄

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.

None yet

2 participants