Add Linux SVG icon generation script
This commit is contained in:
parent
02593e56d0
commit
22f293b4d6
3 changed files with 103 additions and 4 deletions
|
|
@ -13,6 +13,8 @@ This file provides guidelines for codex agents contributing to the Sortana proje
|
||||||
- `prompt_templates/`: Custom/legacy templated message material kept in-repo for non-native prompt flows.
|
- `prompt_templates/`: Custom/legacy templated message material kept in-repo for non-native prompt flows.
|
||||||
- `build-xpi.ps1`: PowerShell script to package the extension.
|
- `build-xpi.ps1`: PowerShell script to package the extension.
|
||||||
- `build-xpi.sh`: Bash script to package the extension.
|
- `build-xpi.sh`: Bash script to package the extension.
|
||||||
|
- `resources/svg2img.ps1`: PowerShell script to regenerate themed PNG icons from SVGs.
|
||||||
|
- `resources/svg2img.sh`: Bash script to regenerate themed PNG icons from SVGs.
|
||||||
|
|
||||||
## Coding Style
|
## Coding Style
|
||||||
|
|
||||||
|
|
@ -80,4 +82,5 @@ time the add-on loads after an update.
|
||||||
Toolbar and menu icons reside under `resources/img` and are provided in 16, 32
|
Toolbar and menu icons reside under `resources/img` and are provided in 16, 32
|
||||||
and 64 pixel variants. When changing these icons, pass a dictionary mapping the
|
and 64 pixel variants. When changing these icons, pass a dictionary mapping the
|
||||||
sizes to the paths in `browserAction.setIcon` or `messageDisplayAction.setIcon`.
|
sizes to the paths in `browserAction.setIcon` or `messageDisplayAction.setIcon`.
|
||||||
Use `resources/svg2img.ps1` to regenerate PNGs from the SVG sources.
|
Use `resources/svg2img.ps1` on Windows or `resources/svg2img.sh` on Linux to
|
||||||
|
regenerate PNGs from the SVG sources.
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ Classification requests ask the model for structured JSON output with a required
|
||||||
- **Cache management** – clear cached results from the context menu or options page.
|
- **Cache management** – clear cached results from the context menu or options page.
|
||||||
- **Queue & timing stats** – monitor processing time on the Maintenance tab.
|
- **Queue & timing stats** – monitor processing time on the Maintenance tab.
|
||||||
- **Packaging scripts** – `build-xpi.ps1` (PowerShell) or `build-xpi.sh` (bash) build an XPI ready for installation.
|
- **Packaging scripts** – `build-xpi.ps1` (PowerShell) or `build-xpi.sh` (bash) build an XPI ready for installation.
|
||||||
|
- **Icon generation scripts** – `resources/svg2img.ps1` (PowerShell) or `resources/svg2img.sh` (bash) regenerate themed PNG icons from the SVG sources.
|
||||||
- **Maintenance tab** – view rule counts, cache entries and clear cached results from the options page.
|
- **Maintenance tab** – view rule counts, cache entries and clear cached results from the options page.
|
||||||
|
|
||||||
### Cache Storage
|
### Cache Storage
|
||||||
|
|
@ -67,15 +68,16 @@ Sortana is implemented entirely with documented MailExtension/WebExtension APIs.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
1. Ensure PowerShell is available (for Windows) or adapt the script for other
|
1. Ensure PowerShell is available on Windows or bash, `python3`, and Inkscape are
|
||||||
environments.
|
available on Linux.
|
||||||
2. The Bulma stylesheet (v1.0.3) is already included as `options/bulma.css`.
|
2. The Bulma stylesheet (v1.0.3) is already included as `options/bulma.css`.
|
||||||
3. Run `powershell ./build-xpi.ps1` or `./build-xpi.sh` from the repository root.
|
3. Run `powershell ./build-xpi.ps1` or `./build-xpi.sh` from the repository root.
|
||||||
The script reads the version from `manifest.json` and creates an XPI in the
|
The script reads the version from `manifest.json` and creates an XPI in the
|
||||||
`release` folder.
|
`release` folder.
|
||||||
4. Install the generated XPI in Thunderbird via the Add-ons Manager. During
|
4. Install the generated XPI in Thunderbird via the Add-ons Manager. During
|
||||||
development you can also load the directory as a temporary add-on.
|
development you can also load the directory as a temporary add-on.
|
||||||
5. To regenerate PNG icons from the SVG sources, run `resources/svg2img.ps1`.
|
5. To regenerate PNG icons from the SVG sources, run `resources/svg2img.ps1` on
|
||||||
|
Windows or `./resources/svg2img.sh` on Linux.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
|
||||||
94
resources/svg2img.sh
Executable file
94
resources/svg2img.sh
Executable file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
svg_dir="$script_dir/svg"
|
||||||
|
out_dir="$script_dir/img"
|
||||||
|
sizes=(16 32 64)
|
||||||
|
themes=(light dark)
|
||||||
|
|
||||||
|
get_theme_color() {
|
||||||
|
case "$1" in
|
||||||
|
light) printf '%s\n' '#000000' ;;
|
||||||
|
dark) printf '%s\n' '#ffffff' ;;
|
||||||
|
*)
|
||||||
|
printf 'Unknown theme: %s\n' "$1" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_temp_svg() {
|
||||||
|
local input_svg="$1"
|
||||||
|
local color="$2"
|
||||||
|
local temp_svg="$3"
|
||||||
|
|
||||||
|
python3 - "$input_svg" "$color" "$temp_svg" <<'PY'
|
||||||
|
import pathlib
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
input_path = pathlib.Path(sys.argv[1])
|
||||||
|
color = sys.argv[2]
|
||||||
|
output_path = pathlib.Path(sys.argv[3])
|
||||||
|
content = input_path.read_text(encoding="utf-8")
|
||||||
|
patched, count = re.subn(r"<svg([^>]*?)>", f'<svg\\1 style="color: {color}">', content, count=1)
|
||||||
|
if count != 1:
|
||||||
|
raise SystemExit("Couldn't find <svg> tag to patch.")
|
||||||
|
output_path.write_text(patched, encoding="utf-8")
|
||||||
|
PY
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ ! -d "$svg_dir" ]]; then
|
||||||
|
echo "SVG source directory not found: $svg_dir" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$out_dir"
|
||||||
|
|
||||||
|
if ! command -v inkscape >/dev/null 2>&1; then
|
||||||
|
echo "Inkscape CLI is not installed or not in PATH. Please install it from https://inkscape.org/" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v python3 >/dev/null 2>&1; then
|
||||||
|
echo "python3 is required to patch the SVG color attribute." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
shopt -s nullglob
|
||||||
|
svg_files=("$svg_dir"/*.svg)
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
|
if [[ ${#svg_files[@]} -eq 0 ]]; then
|
||||||
|
echo "No SVG files found in $svg_dir" >&2
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
temp_svg="$(mktemp "${TMPDIR:-/tmp}/sortana-svg2img.XXXXXX.svg")"
|
||||||
|
cleanup() {
|
||||||
|
rm -f "$temp_svg"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
for svg_path in "${svg_files[@]}"; do
|
||||||
|
base_name="$(basename "${svg_path%.svg}")"
|
||||||
|
|
||||||
|
for theme in "${themes[@]}"; do
|
||||||
|
color="$(get_theme_color "$theme")"
|
||||||
|
ensure_temp_svg "$svg_path" "$color" "$temp_svg"
|
||||||
|
|
||||||
|
for size in "${sizes[@]}"; do
|
||||||
|
out_file="$out_dir/$base_name-$theme-$size.png"
|
||||||
|
echo "Exporting $out_file (color $color)..."
|
||||||
|
inkscape "$temp_svg" \
|
||||||
|
--export-type=png \
|
||||||
|
--export-filename="$out_file" \
|
||||||
|
--export-width="$size" \
|
||||||
|
--export-height="$size" \
|
||||||
|
--actions=export-do
|
||||||
|
done
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Done generating light/dark themed PNGs."
|
||||||
Loading…
Add table
Add a link
Reference in a new issue