#!/bin/bash
#Zenityでランチャーを制作
while true 
do
	do=$(zenity --info --title="Caramel Launcher" --width=400 --window-icon="/usr/Caramel/logo/logow.png" --text="Caramel OSへようこそ！
何をしたいですか？" --ok-label="システムの更新" --extra-button="アプリの追加" --extra-button="開発者のサイトを見る" --extra-button="ときえのきの曲を聞く" --extra-button="設定" --extra-button="終了")
	if [ "x$do" = "x終了" ];then
		end=$(zenity --question --width=250 --window-icon="/usr/Caramel/logo/logow.png" --title="確認" --text="終了してもよろしいですか？" )
		if [ "x$?" = "x0" ];then #0で終了
			echo "終了します"
			exit 0
		fi
	elif [ "x$do" = "x開発者のサイトを見る" ];then
		xdg-open https://blog.caramelos.xyz/
		sleep 2
		zenity --info --title="実行しました" --window-icon="/usr/Caramel/logo/logow.png" --width=430 --text="https://caramelos.xyzにアクセスしました。"
	elif [ "x$do" = "xときえのきの曲を聞く" ];then
		music=$(zenity --list --title="曲を選んでください" --text="どの曲を聞きたいですか？" --width=400 --height=400 --window-icon="/usr/Caramel/logo/logow.png" --column="リスト" "Caramel OS公式テーマソング" "Serene Linux公式テーマソング" "Freedom" "Polaris" "心の叫び ft.初音ミク" "心の叫び ft.健音テイ" "進むべきカタチ" "人生ゲームネット廃人編 ft.初音ミク" "人生ゲームネット廃人編 ft.健音テイ" "more...")
		if [ "x$?" = "x0" ];then
			musicerr=0
			if [ "x$music" = "xFreedom" ];then
				xdg-open ~/Music/ときえのき/freedom_初音ミク.mp3
			elif [ "x$music" = "xPolaris" ];then
				xdg-open ~/Music/ときえのき/Polaris_重音テト.mp3
			elif [ "x$music" = "x心の叫び ft.初音ミク" ];then
				xdg-open ~/Music/ときえのき/心の叫び_初音ミク.mp3
			elif [ "x$music" = "x心の叫び ft.健音テイ" ];then
				xdg-open ~/Music/ときえのき/心の叫び_健音テイ.mp3
			elif [ "x$music" = "x進むべきカタチ" ];then
				xdg-open ~/Music/ときえのき/進むべきカタチ_初音ミク.mp3
			elif [ "x$music" = "x人生ゲームネット廃人編 ft.初音ミク" ];then
				xdg-open ~/Music/ときえのき/人生ゲームネット廃人編_初音ミク.mp3
			elif [ "x$music" = "x人生ゲームネット廃人編 ft.健音テイ" ];then
				xdg-open ~/Music/ときえのき/人生ゲームネット廃人編_健音テイ.mp3
			elif [ "x$music" = "xCaramel OS公式テーマソング" ];then
				xdg-open ~/Music/ときえのき/NETNEET_初音ミク.mp3
			elif [ "x$music" = "xSerene Linux公式テーマソング" ];then
				xdg-open ~/Music/ときえのき/Serene_my_life_初音ミク.mp3
			elif [ "x$music" = "xmore..." ];then
				xdg-open ~/Music/ときえのき/
			else
				musicerr=1
			fi
			if [ "x$musicerr" = "x0" ];then
				if [ "x$music" = "xmore..." ];then
					echo "more!"
				else
					notify-send -u critical "Caramel Launcher" "$musicを再生しています"
				fi
			fi
		fi
	elif [ "x$do" = "xアプリの追加" ];then
		aptcom="apt-get install -y "
		snacom="snap install "
		app=$(zenity --list --title="アプリを選んでください" --text="どのアプリケーションを追加しますか？" --width=400 --height=400 --window-icon="/usr/Caramel/logo/logow.png" --column="リスト" "Firefox" "LibreOffice" "Spotify" "gufw" "Java実行環境 (jdk)")
		if [ "x$?" = "x0" ];then
			if [ "x$app" = "xFirefox" ];then
				com="$aptcom""firefox"
			elif [ "x$app" = "xLibreOffice" ];then
				com="$aptcom""libreoffice"
			elif [ "x$app" = "xSpotify" ];then
				com="$snacom""spotify"
			elif [ "x$app" = "xgufw" ];then
				com="$aptcom""gufw"
			elif [ "x$app" = "xJava実行環境 (jdk)" ];then
				com="$aptcom""openjdk-8-jdk"
			fi
			echo "実行予定:$com"
			zenity --warning --title="重要" --window-icon="/usr/Caramel/logo/logow.png" --width=430 --text="インストールを実行します。
途中でキャンセルすると、その後の処理にエラーが出る場合があります。
余程の事がない限りは、中断しないでください。
インストールの実行には、インターネット接続が必要です。"
			if [ "x$?" = "x0" ];then #罰を押したらキャンセルできる
				ping -c 2 caramelos.xyz
				if [ "x$?" = "x0" ];then
					(
					echo "5" ; sleep 1
					pass=$(zenity --password --window-icon="/usr/Caramel/logo/logow.png" --title="認証が必要です" --text="ユーザーのパスワードを入力してください。")
					echo "10" ; sleep 1
					while :
					do
						echo "# 最新版のパッケージを探しています…"
						hoge=$(echo $pass | sudo -S apt-get update)
						echo "実行しました";sleep 5
						test=$?
						if [ "x$test" = "x1" ];then
							pass=$(zenity --password --window-icon="/usr/Caramel/logo/logow.png" --title="パスワードが違います" --text="ユーザーのパスワードを入力してください。")
						else
							break
						fi
					done
					echo "50"
					echo "# インストールを実行しています…"
					hoge=$(echo $pass | sudo -S $com)
					echo "90"
					echo "# もうしばらくお待ちください…"
					notify-send -u critical "Caramel Launcher" "インストールが完了しました";sleep 1
					echo "100"
					sleep 1
					)| 
					instart=$(zenity --window-icon="/usr/Caramel/logo/logow.png" --progress --width=450 --auto-close --time-remaining --title="インストール実行中" --text="最新版のパッケージを探しています…");
					if [ "x$?" = "x0" ];then
						zenity --info --width=300 --window-icon="/usr/Caramel/logo/logow.png" --title="完了" --text="インストールが完了しました。"
					else
						zenity --warning --width=300 --window-icon="/usr/Caramel/logo/logow.png" --title="中断" --text="インストールが中断されました。"
					fi
				else
					zenity --warning --width=300 --window-icon="/usr/Caramel/logo/logow.png" --title="オフライン" --text="ネットワークにアクセスできません。"
				fi
			fi
		else
			zenity --info --width=300 --window-icon="/usr/Caramel/logo/logow.png" --title="キャンセル" --text="インストールがキャンセルされました。"
		fi
	elif [ "x$do" = "x設定" ];then
		nedo=$(zenity --info --title="Caramel OSの設定" --width=400 --window-icon="/usr/Caramel/logo/logow.png" --text="オプションを選んでください。" --ok-label="起動音の変更" --extra-button="このOSについて" --extra-button="戻る")
		nextdo=$?
		if [ "x$nextdo" = "x0" ];then
			/bin/Caramel/bootsound
		elif [ "x$nedo" = "xこのOSについて" ];then
			/bin/Caramel/infome-gtk
		fi
	else
		/bin/Caramel/update
	fi
	echo リターン！
done
