#!/bin/bash

# Deepin App Store Script
# This script integrates the Exec commands from deepin-home-appstore-client desktop files
# Supports both virus scan mode and main application mode

# Check if /usr/bin/deepin-security-loader exists and dbus version meets requirement
if [ -f "/usr/bin/deepin-security-loader" ]; then
    # Check dbus version
    DBUS_VERSION=$(dpkg-query -W -f='${Version}' dbus 2>/dev/null)
    if [ $? -eq 0 ]; then
        # Compare dbus version with 1.12.20.17-deepin1
        if dpkg --compare-versions "$DBUS_VERSION" ge "1.12.20.17-deepin1"; then
            # Use security loader with deepin-daemon group
            exec /usr/bin/deepin-security-loader --group deepin-daemon -- /usr/libexec/deepin/deepin-home-appstore-client "$@"
        else
            # Fallback to direct deepin-home-appstore-client
            exec /usr/libexec/deepin/deepin-home-appstore-client "$@"
        fi
    else
        # If dbus version check fails, use direct deepin-home-appstore-client
        exec /usr/libexec/deepin/deepin-home-appstore-client "$@"
    fi
else
    # Fallback to direct deepin-home-appstore-client
    exec /usr/libexec/deepin/deepin-home-appstore-client "$@"
fi
