diff --git a/bin/omarchy-theme-set-browser b/bin/omarchy-theme-set-browser index ee189d17bb..19deb0bb42 100755 --- a/bin/omarchy-theme-set-browser +++ b/bin/omarchy-theme-set-browser @@ -1,6 +1,6 @@ #!/bin/bash -# omarchy:summary=Apply the current theme color to Chromium, Chrome, Edge, and Brave +# omarchy:summary=Apply the current theme color to Chromium, Chrome, Edge, Brave, and Zen # omarchy:hidden=true CHROMIUM_THEME=~/.config/omarchy/current/theme/chromium.theme @@ -42,3 +42,4 @@ refresh_running_browser msedge microsoft-edge-stable set_browser_policy /etc/brave/policies/managed refresh_running_browser brave brave refresh_running_browser brave-origin-beta brave-origin-beta -f +omarchy-theme-set-zen diff --git a/bin/omarchy-theme-set-zen b/bin/omarchy-theme-set-zen new file mode 100755 index 0000000000..1c5ea1bddb --- /dev/null +++ b/bin/omarchy-theme-set-zen @@ -0,0 +1,175 @@ +#!/bin/bash + +# omarchy:summary=Apply the current theme color to Zen browser +# omarchy:hidden=true +# omarchy:aliases=omarchy set-zen-theme + +THEME_COLORS=~/.config/omarchy/current/theme/colors.toml +ZEN_CONFIG_DIR=~/.config/zen + +read_theme_color() { + sed -n "s/^$1 = \"\([^\"]*\)\"$/\1/p" "$THEME_COLORS" +} + +set_zen_theme() { + [[ -d $ZEN_CONFIG_DIR && -f $THEME_COLORS ]] || return + + local background foreground accent cursor surface profile_dir chrome_dir omarchy_css user_chrome_css user_js + background=$(read_theme_color background) + foreground=$(read_theme_color foreground) + accent=$(read_theme_color accent) + cursor=$(read_theme_color cursor) + surface=$(read_theme_color color0) + + [[ -n $background && -n $foreground && -n $accent && -n $cursor && -n $surface ]] || return + + for profile_dir in "$ZEN_CONFIG_DIR"/*; do + [[ -f "$profile_dir/prefs.js" ]] || continue + + chrome_dir="$profile_dir/chrome" + omarchy_css="$chrome_dir/omarchy-theme.css" + user_chrome_css="$chrome_dir/userChrome.css" + user_js="$profile_dir/user.js" + + mkdir -p "$chrome_dir" + + cat >"$omarchy_css" <"$user_chrome_css" <<'EOF' +@import url("omarchy-theme.css"); +EOF + elif ! grep -Fq '@import url("omarchy-theme.css");' "$user_chrome_css"; then + printf '\n@import url("omarchy-theme.css");\n' >>"$user_chrome_css" + fi + + if [[ ! -f $user_js ]] || ! grep -Fq 'toolkit.legacyUserProfileCustomizations.stylesheets' "$user_js"; then + cat >>"$user_js" <<'EOF' +user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true); +EOF + fi + done + + if pgrep -x zen-browser >/dev/null; then + omarchy-restart-app zen-browser + fi +} + +set_zen_theme