-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: App list sorting tool (asc/desc A-Z) (#1300)
## Needs to be merged after Mainui sig handling #1193 as it uses -2, and #1299 unless rebased after this merges (as the NUM_TOOLS needs to be updated) - Tested on MM+ FW 0628, MM 1027, MM 0611 - Tested with Sandisk Ultra cards ## Adds a tool to sort the Apps list A-Z or Z-A based on their config.json LABEL. - Will add 2 tools to the Tweaks -> Tools menu
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
create_temp_dir() { | ||
mkdir -p /mnt/SDCARD/App.temp | ||
for dir in /mnt/SDCARD/App/*/; do | ||
if [ -f "$dir/config.json" ]; then | ||
mv "$dir" /mnt/SDCARD/App.temp/ | ||
fi | ||
done | ||
} | ||
|
||
read_and_store_labels() { | ||
temp_file="/mnt/SDCARD/temp_labels.txt" | ||
: > "$temp_file" | ||
|
||
for dir in /mnt/SDCARD/App.temp/*/; do | ||
if [ -f "$dir/config.json" ]; then | ||
label=$(awk -F'"' '/"label":/ {print $4}' "$dir/config.json") | ||
echo "$label:$dir" >> "$temp_file" | ||
fi | ||
done | ||
} | ||
|
||
sort_and_copy_back() { | ||
sort_order="$1" | ||
if [ "$sort_order" = "desc" ]; then | ||
sort_flag="-rf" | ||
else | ||
sort_flag="-f" | ||
fi | ||
|
||
sort $sort_flag "$temp_file" | while IFS=: read -r label dir; do | ||
mv "$dir" /mnt/SDCARD/App/ | ||
done | ||
} | ||
|
||
cleanup() { | ||
#restart mainui to refresh app list (if called from a button/script while main is running) | ||
if pgrep "MainUI" > /dev/null; then | ||
pkill -2 "MainUI" | ||
fi | ||
|
||
rm -rf /mnt/SDCARD/App.temp | ||
rm "$temp_file" | ||
} | ||
|
||
main() { | ||
sort_order="${1:-asc}" | ||
create_temp_dir | ||
read_and_store_labels | ||
sort_and_copy_back "$sort_order" | ||
cleanup | ||
} | ||
|
||
main "$@" |