#!/bin/bash

#---------------------------------------------------------------------
# File information.

# File:     uchromium
# Purpose:  Single-instance wrapper (Laclin-specific)
# License:  BSD-style (for this file only)
# Revision: 250831

#---------------------------------------------------------------------
# Wrapper parameters.

BASEDIR=/opt/uchromium/program
BINDIR=$BASEDIR
LIBDIR=$BASEDIR
SNDFLAG=true
TARGET=$BINDIR/chrome
PROGNAME="UChromium"

#---------------------------------------------------------------------
# Run the target if it's available.

if [ -f $TARGET ]; then         # Run the target
                                # If there are no parameters, start in
                                # user's home directory
    if [ "x$1" = "x" ]; then cd; fi

    if [ "@$SNDFLAG" == "@true" ]; then
        resetpcmvol             # Adjust volume
    fi
    if [ -d $LIBDIR ]; then     # Adjust LD_LIBRARY_PATH
        LD_LIBRARY_PATH=$LIBDIR:$LD_LIBRARY_PATH
        export LD_LIBRARY_PATH
    fi

    PATH=$BINDIR:$PATH          # Adjust PATH

    for x in alsa cairo cups eudev expat gtkcore nspr nss xorg
    do
        . srcpkgpaths $x
    done

    /laclin/lacutil/single-instance --wait --usepid \
"/opt/uchromium/program/chrome" \
$TARGET \
--no-sandbox \
--password-store=basic \
--test-type $* >& /dev/null &

    exit
fi

#---------------------------------------------------------------------
# Display a missing-program dialog.

TITLE="$PROGNAME isn't installed"
/laclin/lacutil/single-instance \
--wait --usewin "^$TITLE" \
zenity --error --no-wrap --title="$TITLE" --text="$TITLE"
