#!/bin/bash

# basic menu activated from the top left

MENUENTRIES="{blue icon=apps} Applications
{blue icon=settings} Settings
{blue icon=terminal} Terminal
{blue icon=info} Info
{green icon=book-open} Documentation
{green icon=keyboard} Keybinds
{red icon=poweroff} Shutdown
{red icon=x} Close menu"

# installing is only offered when running from the live iso
# (same detection as ins itself: /run/archiso/cowspace)
if [ -e /run/archiso/cowspace ]; then
    MENUENTRIES="{green icon=rocket} Install instantOS
$MENUENTRIES"
fi

CHOICE="$(echo "$MENUENTRIES" | instantmenu \
        --insensitive \
        --border-width 4 \
        --width auto \
        --line-height auto \
        --auto-confirm \
        --lines 10 \
        --position top-left \
        --match-mode dmenu \
        --animation-length 0)"

[ -z "$CHOICE" ] && exit

echo "$CHOICE"
case "$CHOICE" in
    *Install*)
        echo "launching installer"
        # run in a terminal like the welcome app does
        kitty -e ins arch install &
        ;;
    *Applications)
        sleep 0.05
        appmenu &
        ;;
    *Keybinds)
        ins keyhelp --gui &
        ;;
    *Settings)
        ins settings --gui &
        ;;
    *Info)
        kitty -e sh -c 'fastfetch && echo -ne "$(cat /usr/share/instantutils/thanks.txt | sed "s/^/   /g")" && sleep 60m' &
        ;;
    *Shutdown)
        instantshutdown &
        ;;
    *Terminal)
        kitty &
        ;;
    *Documentation)
        xdg-open 'https://instantos.io/docs/' &
        ;;
    *menu)
        echo "closed menu"
        ;;
    *)
        echo "other choice"
        instantmenu_smartrun "startmenu" "$CHOICE"
        ;;
esac

exit
