refactor(script/user-chrome-setup): Install userChrome.css to multiple

profiles
This commit is contained in:
Ahmad Ansori Palembani 2024-07-19 19:55:43 +07:00
parent 783d2bbd4c
commit 29bc84fabc
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -63,17 +63,22 @@ if not bool_from_string(prompt, False):
# default = next(config[p] for p in profiles if str(config[p].get("Default", "0")) == "1") # default = next(config[p] for p in profiles if str(config[p].get("Default", "0")) == "1")
_install = [p for p in config.sections() if p.startswith("Install")] _install = [p for p in config.sections() if p.startswith("Install")]
default_path = next(config[p] for p in _install) default_paths = [config[p] for p in _install]
profile_path = f"{browser_path}/{default_path['Default']}" installed = 0
chrome_path = pathlib.Path(f"{profile_path}/chrome") for default_path in default_paths:
chrome_path.mkdir(parents=True, exist_ok=True) profile_path = f"{browser_path}/{default_path['Default']}"
user_chrome_path = chrome_path / "userChrome.css" chrome_path = pathlib.Path(f"{profile_path}/chrome")
try: chrome_path.mkdir(parents=True, exist_ok=True)
user_chrome_path.symlink_to(f"{dotfiles}/.include/ff-chrome/userChrome.css") user_chrome_path = chrome_path / "userChrome.css"
except FileExistsError: target_path = f"{dotfiles}/.include/ff-chrome/userChrome.css"
prompt = input("Overwrite existing userChrome.css? [y/N] ") try:
if not bool_from_string(prompt, False): user_chrome_path.symlink_to(target_path)
exit(0) installed += 1
user_chrome_path.unlink() except FileExistsError:
user_chrome_path.symlink_to(f"{dotfiles}/.include/ff-chrome/userChrome.css") prompt = input(f"[{default_path['Default']}] Overwrite existing userChrome.css? [y/N] ")
print("userChrome.css has successfully installed.") if not bool_from_string(prompt, False):
continue
user_chrome_path.unlink()
user_chrome_path.symlink_to(target_path)
installed += 1
print(f"userChrome.css has successfully installed in {installed} out of {len(default_paths)} profile(s).")