mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-16 17:51:59 +01:00
Preferences gains two pages for the config.json settings that had no place in the app: - Sync: the patterns every synced folder leaves out (own patterns, and each built-in one on or off), and what the conflict sweep may do. - Apps: which program opens which kind of file (open_with), and how the search launcher opens (prompt). Each synced folder kept on this computer gets "Excluded Files…" in its menu for its own .pdfsignore: checked as typed, "Check a path" says which rule decides, and a version changed elsewhere is never written over without asking. `pdfs sync ignore list|add|remove|reset|check` does the same from a terminal, and `--page preferences-sync` (and -apps, -storage) opens Preferences at a page. Every writer of config.json now goes through AppDirs::update_config, which reads, changes and writes under an flock on config.json.lock, so the app, the tray and the daemon no longer undo each other's change (B292). The opener reads its rules on each open, so a new rule applies without a restart. The built-in ignore list also leaves out what Nextcloud, Dropbox and Syncthing leave out: desktop.ini, .directory, trash folders, NFS/FUSE leftovers, partial downloads, Kate swap and office lock files.
231 lines
8.6 KiB
Bash
Executable File
231 lines
8.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Retakes the README and website screenshots from made-up data.
|
|
set -Eeuo pipefail
|
|
|
|
usage() {
|
|
cat >&2 <<'EOF'
|
|
usage: scripts/screenshots.sh [OPTION ...]
|
|
|
|
Builds the app, starts it against a stand-in daemon that serves an invented
|
|
account (crates/pdfs-core/examples/demo_daemon.rs), and captures every page in
|
|
a headless Wayland compositor. No Proton account, no FUSE mount, nothing from
|
|
your own files: HOME, every XDG directory, the session bus and the keyring
|
|
are throwaway ones under a temporary directory.
|
|
|
|
Options:
|
|
--out DIR where the PNGs go (default: images/)
|
|
--only LIST capture only these, comma-separated (default: all of
|
|
login,files,photos,photos_map,computers,sync,conflicts,
|
|
prompt_gtk,prompt_fzf). preferences_sync and
|
|
preferences_apps exist too, for pull requests only
|
|
--website DIR afterwards, copy them into the website checkout at DIR
|
|
with its scripts/sync-screenshots.sh
|
|
--settle SECS how long a page gets to load before its capture (default 3)
|
|
--debug use a debug build instead of a release build
|
|
--keep keep the temporary directory, for a look at the logs
|
|
|
|
Needs cage, grim, wlr-randr, ImageMagick, dbus-run-session and
|
|
gnome-keyring-daemon; prompt_gtk types its query with wtype when there is one,
|
|
and prompt_fzf needs fzf and alacritty. Demo photos come from picsum.photos
|
|
(Unsplash licence) on the first run and are cached in
|
|
~/.cache/pdfs-screenshots.
|
|
EOF
|
|
exit 2
|
|
}
|
|
|
|
repo="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
all=login,files,photos,photos_map,computers,sync,conflicts,prompt_gtk,prompt_fzf
|
|
# Not in the README, so not taken by default.
|
|
extra=preferences_sync,preferences_apps
|
|
|
|
# The capture itself, run by cage inside the throwaway session (see below).
|
|
if [[ "${1:-}" == --capture ]]; then
|
|
shots=",$SHOTS,"
|
|
wants() { [[ "$shots" == *",$1,"* ]]; }
|
|
output() { wlr-randr --output "$(wlr-randr | awk 'NR==1 {print $1}')" --custom-mode "$1"; }
|
|
shoot() {
|
|
sleep "$SETTLE"
|
|
grim "$OUT/$1.png"
|
|
echo "captured $1"
|
|
}
|
|
# Cut the compositor's black background off a window smaller than it.
|
|
trim() {
|
|
magick "$OUT/$1.png" -bordercolor black -border 1 -trim +repage "$OUT/$1.png"
|
|
}
|
|
quit() {
|
|
kill "$@" 2>/dev/null || true
|
|
wait "$@" 2>/dev/null || true
|
|
}
|
|
|
|
output 1836x1006
|
|
if wants login; then
|
|
"$BIN/pdfs-app" &
|
|
app=$!
|
|
shoot login
|
|
quit "$app"
|
|
fi
|
|
"$BIN/demo_daemon" seed-keyring
|
|
"$BIN/pdfs-app" &
|
|
app=$!
|
|
sleep "$SETTLE"
|
|
for shot in files:browser photos:gallery photos_map:places-map computers:devices \
|
|
sync:sync-folders conflicts:activity \
|
|
preferences_sync:preferences-sync preferences_apps:preferences-apps; do
|
|
name=${shot%%:*}
|
|
wants "$name" || continue
|
|
"$BIN/pdfs-app" --page "${shot#*:}"
|
|
shoot "$name"
|
|
done
|
|
quit "$app"
|
|
|
|
if wants prompt_gtk; then
|
|
output 860x723
|
|
"$BIN/pdfs-prompt" --gtk &
|
|
prompt=$!
|
|
sleep 1
|
|
# The window has no --query; type one, as a person would.
|
|
# The first key only sets up the keymap.
|
|
command -v wtype >/dev/null && wtype -k Shift_L -s 200 report
|
|
shoot prompt_gtk
|
|
quit "$prompt"
|
|
trim prompt_gtk
|
|
fi
|
|
if wants prompt_fzf; then
|
|
if command -v fzf >/dev/null && command -v alacritty >/dev/null; then
|
|
output 800x600
|
|
alacritty -o font.size=11 -e "$BIN/pdfs-prompt" --fzf --inner --query report &
|
|
term=$!
|
|
shoot prompt_fzf
|
|
quit "$term"
|
|
trim prompt_fzf
|
|
else
|
|
echo "skipped prompt_fzf: needs fzf and alacritty" >&2
|
|
fi
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
# Inside the private session bus: an unlocked, empty keyring, the demo daemon,
|
|
# then the compositor running the capture above.
|
|
if [[ "${1:-}" == --session ]]; then
|
|
# A password it never asks for again: an empty one leaves no keyring.
|
|
printf demo | gnome-keyring-daemon --unlock --components=secrets >/dev/null
|
|
"$BIN/demo_daemon" serve "$PHOTOS" 2>"$PDFS_DEMO_ROOT/demo_daemon.log" &
|
|
daemon=$!
|
|
trap 'kill "$daemon" 2>/dev/null || true' EXIT
|
|
for _ in $(seq 50); do
|
|
[[ -S "$XDG_STATE_HOME/proton-drive-linux/control.sock" ]] && break
|
|
sleep 0.1
|
|
done
|
|
WLR_BACKENDS=headless WLR_LIBINPUT_NO_DEVICES=1 \
|
|
cage -- "$repo/scripts/screenshots.sh" --capture 2>"$PDFS_DEMO_ROOT/cage.log"
|
|
exit 0
|
|
fi
|
|
|
|
out="$repo/images"
|
|
shots=$all
|
|
website=
|
|
settle=3
|
|
profile=release
|
|
keep=
|
|
while (($#)); do
|
|
case "$1" in
|
|
--out) out=$(realpath -m -- "${2:?}"); shift ;;
|
|
--only) shots=${2:?}; shift ;;
|
|
--website) website=$(realpath -- "${2:?}"); shift ;;
|
|
--settle) settle=${2:?}; shift ;;
|
|
--debug) profile=debug ;;
|
|
--keep) keep=1 ;;
|
|
-h | --help) usage ;;
|
|
*) echo "unknown option: $1" >&2; usage ;;
|
|
esac
|
|
shift
|
|
done
|
|
for shot in ${shots//,/ }; do
|
|
[[ ",$all,$extra," == *",$shot,"* ]] || { echo "no screenshot called $shot" >&2; exit 2; }
|
|
done
|
|
for tool in cage grim wlr-randr magick dbus-run-session gnome-keyring-daemon cargo curl; do
|
|
command -v "$tool" >/dev/null || { echo "$tool is required" >&2; exit 2; }
|
|
done
|
|
|
|
# Demo photos, fetched once. Fixed picsum ids keep every run the same; a
|
|
# trailing -p marks a portrait one.
|
|
photos="${XDG_CACHE_HOME:-$HOME/.cache}/pdfs-screenshots"
|
|
mkdir -p "$photos"
|
|
for id in 10 11 13 15 16 17 28 29 37 42 43 49 54 57 58 76 82 83 84 96 101 103 110 \
|
|
111 116 119 122 128 129 135 142 145 152 164 167 174 176 180 184 188 192 200 \
|
|
210 218 219 225 231 237; do
|
|
size=600/400 file="$photos/$id.jpg"
|
|
if ((id % 7 == 0)); then size=400/600 file="$photos/$id-p.jpg"; fi
|
|
[[ -s "$file" ]] || curl -fsSL "https://picsum.photos/id/$id/$size.jpg" -o "$file" ||
|
|
{ rm -f "$file"; echo "could not fetch demo photo $id; skipped" >&2; }
|
|
done
|
|
|
|
cargo_flags=(--manifest-path "$repo/Cargo.toml" --locked)
|
|
[[ "$profile" == release ]] && cargo_flags+=(--release)
|
|
cargo build "${cargo_flags[@]}" -p pdfs-gui --bin pdfs-app --bin pdfs-prompt
|
|
cargo build "${cargo_flags[@]}" -p pdfs-core --example demo_daemon
|
|
target=$(cargo metadata --manifest-path "$repo/Cargo.toml" --format-version 1 --no-deps |
|
|
python3 -c 'import json, sys; print(json.load(sys.stdin)["target_directory"])')
|
|
bin="$(mktemp -d)"
|
|
ln -s "$target/$profile/pdfs-app" "$target/$profile/pdfs-prompt" \
|
|
"$target/$profile/examples/demo_daemon" "$bin/"
|
|
|
|
root=$(mktemp -d -t pdfs-screenshots.XXXXXX)
|
|
cleanup() {
|
|
rm -rf "$bin"
|
|
if [[ -n "$keep" ]]; then echo "kept $root" >&2; else rm -rf "$root"; fi
|
|
}
|
|
trap cleanup EXIT
|
|
mkdir -p "$root"/{home,config,state,cache,data} "$root/run" "$out"
|
|
chmod 700 "$root/run"
|
|
# The user's own fonts, so the shots look like the app does here.
|
|
mkdir -p "$root/data/fonts"
|
|
[[ -d "$HOME/.local/share/fonts" ]] && cp -rs "$HOME/.local/share/fonts/." "$root/data/fonts/"
|
|
mkdir -p "$root/config/proton-drive-linux"
|
|
cat >"$root/config/proton-drive-linux/config.json" <<'EOF'
|
|
{
|
|
"proton_theme": true,
|
|
"tray_hidden": true,
|
|
"update_check": false,
|
|
"online_map": false,
|
|
"files_view": { "list": false },
|
|
"ignore_patterns": [".git/", "node_modules/", "target/", "*~", "*.swp", ".DS_Store",
|
|
"*.iso", "build/", "*.sqlite-wal"],
|
|
"open_with": {
|
|
"rules": [
|
|
{ "match": ["@text", "*.md"], "command": ["nvim"], "terminal": true },
|
|
{ "match": ["@image"], "command": ["loupe"] }
|
|
]
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Only a close button, as GNOME shows it.
|
|
mkdir -p "$root/config/gtk-4.0"
|
|
printf '[Settings]\ngtk-decoration-layout=:close\n' >"$root/config/gtk-4.0/settings.ini"
|
|
|
|
# The demo user's home, so paths read "Home / …" for them, not for you. A
|
|
# folder that does not exist takes no writes; everything goes to XDG_*.
|
|
home=/home/alex
|
|
[[ -e "$home" ]] && home="$root/home"
|
|
|
|
outer_bus=${DBUS_SESSION_BUS_ADDRESS:-unset}
|
|
env -i \
|
|
PATH="$PATH" LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 TZ="${TZ:-Europe/Berlin}" \
|
|
HOME="$home" \
|
|
XDG_CONFIG_HOME="$root/config" XDG_STATE_HOME="$root/state" \
|
|
XDG_CACHE_HOME="$root/cache" XDG_DATA_HOME="$root/data" \
|
|
XDG_RUNTIME_DIR="$root/run" \
|
|
PDFS_DEMO_ROOT="$root" PDFS_DEMO_OUTER_BUS="$outer_bus" \
|
|
GSETTINGS_BACKEND=memory ADW_DEBUG_COLOR_SCHEME=prefer-dark GTK_A11Y=none GDK_DEBUG=no-portals \
|
|
BIN="$bin" PHOTOS="$photos" OUT="$out" SHOTS="$shots" SETTLE="$settle" \
|
|
dbus-run-session -- "$repo/scripts/screenshots.sh" --session 2>"$root/session.log"
|
|
|
|
for shot in ${shots//,/ }; do
|
|
[[ -s "$out/$shot.png" ]] || echo "missing: $out/$shot.png (logs: --keep)" >&2
|
|
done
|
|
if [[ -n "$website" ]]; then
|
|
"$website/scripts/sync-screenshots.sh" "$repo"
|
|
fi
|