Added fallback if colormode file doesn't exi--

This commit is contained in:
midn8hustlr
2024-03-17 14:35:23 +05:30
parent c5d6fa15a8
commit 6f0ca3acaa
2 changed files with 15 additions and 7 deletions
@@ -65,7 +65,9 @@ const ColorSchemeSettingsRevealer = () => {
}); });
} }
function calculateSchemeInitIndex(optionsArr, searchValue = 'monochrome') { function calculateSchemeInitIndex(optionsArr, searchValue = 'tonalspot') {
if (searchValue == '')
searchValue = 'tonalspot';
const flatArray = optionsArr.flatMap(subArray => subArray); const flatArray = optionsArr.flatMap(subArray => subArray);
const result = flatArray.findIndex(element => element.value === searchValue); const result = flatArray.findIndex(element => element.value === searchValue);
const rowIndex = Math.floor(result / optionsArr[0].length); const rowIndex = Math.floor(result / optionsArr[0].length);
@@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# check if no arguments # check if no arguments
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
echo "Usage: colorgen.sh /path/to/image (--apply)" echo "Usage: colorgen.sh /path/to/image (--apply)"
@@ -8,15 +7,22 @@ if [ $# -eq 0 ]; then
fi fi
# check if the file ~/.cache/ags/user/colormode.txt exists. if not, create it. else, read it to $lightdark # check if the file ~/.cache/ags/user/colormode.txt exists. if not, create it. else, read it to $lightdark
colormodefile="$HOME/.cache/ags/user/colormode.txt"
lightdark="dark" lightdark="dark"
transparency="opaque" transparency="opaque"
materialscheme="tonalspot" materialscheme="tonalspot"
if [ ! -f "$HOME/.cache/ags/user/colormode.txt" ]; then if [ ! -f $colormodefile ]; then
echo "dark\nopaque\ntonalspot" > "$HOME/.cache/ags/user/colormode.txt" echo "dark" > $colormodefile
echo "opaque" >> $colormodefile
echo "tonalspot" >> $colormodefile
elif [[ $(wc -l < $colormodefile) -ne 3 || $(wc -w < $colormodefile) -ne 3 ]]; then
echo "dark" > $colormodefile
echo "opaque" >> $colormodefile
echo "tonalspot" >> $colormodefile
else else
lightdark=$(sed -n '1p' "$HOME/.cache/ags/user/colormode.txt") lightdark=$(sed -n '1p' $colormodefile)
transparency=$(sed -n '2p' "$HOME/.cache/ags/user/colormode.txt") transparency=$(sed -n '2p' $colormodefile)
materialscheme=$(sed -n '3p' "$HOME/.cache/ags/user/colormode.txt") materialscheme=$(sed -n '3p' $colormodefile)
fi fi
backend="material" # color generator backend backend="material" # color generator backend
if [ ! -f "$HOME/.cache/ags/user/colorbackend.txt" ]; then if [ ! -f "$HOME/.cache/ags/user/colorbackend.txt" ]; then