#!/bin/sh
# SPDX-FileCopyrightText: 2026 Adam DePrince
# SPDX-License-Identifier: Apache-2.0
set -e
# Stop only this package's per-user service. Do not kill unrelated input or BLE readers.
if [ "$1" = remove ] && command -v loginctl >/dev/null 2>&1; then
    loginctl list-users --no-legend 2>/dev/null | while read -r uid name rest; do
        case "$uid" in ''|*[!0-9]*) continue ;; esac
        if [ -S "/run/user/$uid/bus" ]; then
            runuser -u "$name" -- env XDG_RUNTIME_DIR="/run/user/$uid" \
                DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus" \
                systemctl --user stop serenibrain-mouse.service || true
            runuser -u "$name" -- env XDG_RUNTIME_DIR="/run/user/$uid" \
                DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus" \
                gnome-extensions disable serenibrain-mouse@serenibrain.local || true
        fi
    done
fi
