leftwm / leftwm-theme

A tool to help manage themes for LeftWM
BSD 3-Clause "New" or "Revised" License
117 stars 12 forks source link

update: Add support for repos from local file #26

Closed darkowlzz closed 3 years ago

darkowlzz commented 3 years ago

This adds support for repos with URL as a local file (file://). This enables creating custom theme repos locally without the need to download a repo file.

The implementation adds Update::update_repos() which iterates through the repos and fetches the themes. If the repo URL is a web URL, it downloads it. If the URL is a local file address, it reads the files as a repo.

Introduces url crate for URL parsing and construction.

With this change, a local theme repo file can be created, say my-theme-repo.toml:

[[theme]]
name = "test-theme1"
repository = "https://github.com/leftwm/testtheme1/"
commit = "*"
version = "0.0.5"
leftwm_versions = "*"

[[theme]]
name = "test-theme2"
repository = "https://github.com/leftwm/testtheme2/"
commit = "*"
version = "0.0.3"
leftwm_versions = "*"

This repo can be added to ~/.config/leftwm/themes.toml as:

[[repos]]
url = "file:///tmp/my-theme-repo.toml"
name = "personal"

# ....

On running update:

$  ~ leftwm-theme update
Fetching themes . . .

Available themes:
   personal/test-theme1: A LeftWM theme
   personal/test-theme2: A LeftWM theme
   community/Orange Forest: A LeftWM theme-Installed
   community/Coffee: A LeftWM theme
   community/Soothe: A LeftWM theme-Installed
   community/TNG: A LeftWM theme
   community/Windows XP: A LeftWM theme
   community/Dracula Rounded: A LeftWM theme
   ...

The themes from the new repo gets added.

~~NOTE: I've learned about avoiding usage of unwrap() in production code. I introduced a lot of unwraps in config.rs with my recent changes, I'll fix them in a follow-up PR.~~

Update: Added a separate commit to remove all unwrap() from non-test code in config.rs.

lex148 commented 3 years ago

@darkowlzz this is great. Being able to pull from a local repo is a great Idea. Everything looks good and ready to go, but I can't merge until the conflicts are resolved. Would you mind resolving the conflicts? If you need help just let me know I would be happy to help.

darkowlzz commented 3 years ago

Hi @lex148 , I've resolved the conflicts. You should be able to merge it now :) Thanks for reviewing.