feat(editor): finalize M2 content workspace UX
This commit is contained in:
1 parent
93e23ba194
commit
106d947c98
69 files changed
+5893
-4343
No files matched your search
@@ -10,7 +10,8 @@ readonly STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/blacksite-editor"
|
||||
readonly LOG_FILE="$STATE_DIR/launch.log"
|
||||
readonly STATUS_FILE="$STATE_DIR/splash.status"
|
||||
readonly SPLASH="$REPO/scripts/editor/splash.py"
|
||||
readonly CARGO_LANE="$REPO/scripts/codex/cargo_lane.py"
|
||||
readonly BUILD_PROGRESS="$REPO/scripts/editor/build_progress.py"
|
||||
readonly BUILD_STORAGE="$REPO/scripts/codex/build_storage.py"
|
||||
|
||||
build_only=false
|
||||
project_browser=false
|
||||
@@ -78,27 +79,55 @@ close_splash() {
|
||||
}
|
||||
trap close_splash EXIT
|
||||
|
||||
focus_existing() {
|
||||
find_existing() {
|
||||
local pid executable
|
||||
while read -r pid; do
|
||||
[[ -n "$pid" ]] || continue
|
||||
executable="$(readlink -f "/proc/$pid/exe" 2>/dev/null || true)"
|
||||
if [[ "$executable" == "$binary" ]]; then
|
||||
if command -v hyprctl >/dev/null 2>&1; then
|
||||
hyprctl dispatch focuswindow "pid:$pid" >/dev/null 2>&1 || true
|
||||
fi
|
||||
printf '%s\n' "$pid"
|
||||
return 0
|
||||
fi
|
||||
done < <(pgrep -x "$process_name" 2>/dev/null || true)
|
||||
return 1
|
||||
}
|
||||
|
||||
if ! $build_only && focus_existing; then
|
||||
exit 0
|
||||
fi
|
||||
focus_process() {
|
||||
local pid="$1"
|
||||
if command -v hyprctl >/dev/null 2>&1; then
|
||||
hyprctl dispatch focuswindow "pid:$pid" >/dev/null 2>&1 || true
|
||||
fi
|
||||
}
|
||||
|
||||
running_binary_is_current() {
|
||||
local pid="$1"
|
||||
local running_identity current_identity
|
||||
running_identity="$(stat -Lc '%d:%i' "/proc/$pid/exe" 2>/dev/null || true)"
|
||||
current_identity="$(stat -Lc '%d:%i' "$binary" 2>/dev/null || true)"
|
||||
[[ -n "$running_identity" && "$running_identity" == "$current_identity" ]]
|
||||
}
|
||||
|
||||
build_current_editor() {
|
||||
write_status "Checking build storage" "Validating the managed development lane" 6
|
||||
if ! python3 "$BUILD_STORAGE" enforce --phase pre >>"$LOG_FILE" 2>&1; then
|
||||
write_status "Build storage limit reached" \
|
||||
"Open the launch log for the checked storage report" 6 error
|
||||
return 1
|
||||
fi
|
||||
|
||||
python3 "$BUILD_PROGRESS" "$STATUS_FILE" "$LOG_FILE"
|
||||
local build_result=$?
|
||||
|
||||
if ! python3 "$BUILD_STORAGE" enforce --phase post >>"$LOG_FILE" 2>&1; then
|
||||
printf '%s\n' \
|
||||
"warning: build-storage postflight failed; see the report above" \
|
||||
>>"$LOG_FILE"
|
||||
fi
|
||||
return "$build_result"
|
||||
}
|
||||
|
||||
mkdir -p "$STATE_DIR"
|
||||
exec 9>"$STATE_DIR/launch.lock"
|
||||
exec 9>"$STATE_DIR/build.lock"
|
||||
if ! flock -n 9; then
|
||||
exit 0
|
||||
fi
|
||||
@@ -117,13 +146,50 @@ if ! cd "$REPO"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Capture the process before Cargo may atomically replace the on-disk executable. A launcher click
|
||||
# always checks/builds source updates first; it never silently focuses a stale process and makes the
|
||||
# user believe the running editor already contains the rebuilt UI.
|
||||
existing_pid=""
|
||||
if ! $build_only; then
|
||||
existing_pid="$(find_existing || true)"
|
||||
fi
|
||||
|
||||
if ! build_current_editor; then
|
||||
if $build_only; then
|
||||
tail -n 120 "$LOG_FILE" >&2
|
||||
else
|
||||
keep_splash=true
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$existing_pid" ]] && kill -0 "$existing_pid" 2>/dev/null; then
|
||||
focus_process "$existing_pid"
|
||||
if running_binary_is_current "$existing_pid"; then
|
||||
write_status "Editor already open" "Focused the current development build" 100 close
|
||||
else
|
||||
write_status "Update ready" "Close and reopen the editor to activate it" 100 close
|
||||
if command -v notify-send >/dev/null 2>&1; then
|
||||
notify-send --app-name="Blacksite Editor" \
|
||||
"Blacksite update ready" \
|
||||
"Close the running editor normally, then reopen it to activate the rebuilt UI." \
|
||||
>/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
# The status above already asked the splash process to close. Prevent the EXIT trap from
|
||||
# replacing the meaningful "already open" or "update ready" result with a startup message.
|
||||
splash_pid=""
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if $build_only; then
|
||||
exec python3 "$CARGO_LANE" exec dev -- cargo build -p editor --bin editor
|
||||
printf 'Blacksite editor and project browser are current.\n'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -x "$binary" ]]; then
|
||||
write_status "Editor build unavailable" \
|
||||
"Run blacksite-editor --build-only from a terminal" 100 error
|
||||
"The managed build completed without the requested binary" 100 error
|
||||
keep_splash=true
|
||||
exit 1
|
||||
fi
|
||||
@@ -175,6 +241,11 @@ watch_editor_window() {
|
||||
"The process is still running; check the launch log" 100 error
|
||||
}
|
||||
|
||||
# The lock protects the managed build and startup handoff, not the editor runtime. Leaving this
|
||||
# descriptor inherited across `exec` prevents later build-only updates for as long as the editor is
|
||||
# open.
|
||||
flock -u 9
|
||||
exec 9>&-
|
||||
watch_editor_window "$$" &
|
||||
exec "$binary" >>"$LOG_FILE" 2>&1
|
||||
|
||||
|
||||
Reference in new issue
Block a user