Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]: USB storage mount display in Thunar file manager #21901

Open
hansm629 opened this issue Oct 20, 2024 · 5 comments
Open

[feature]: USB storage mount display in Thunar file manager #21901

hansm629 opened this issue Oct 20, 2024 · 5 comments

Comments

@hansm629
Copy link

hansm629 commented Oct 20, 2024

After installing the Termux app (GitHub Actions build) with the MANAGE_EXTERNAL_STORAGE permission granted and enabling the Termux permission in Android Settings -> Apps -> Special app access -> All files access -> Termux,
I added the following script to .bashrc. This allowed USB storage to be mounted through USB OTG on a without root device.

Both reading and writing work perfectly on the USB storage path.

However, while the USB storage is mounted in real-time on the system, it does not appear in the Thunar file manager.

If I manually enter the path, I can easily access the USB storage in Thunar file manager, and both reading and writing work fine.

Could you update the Thunar file manager so that the mounted USB storage appears in the list?

find_most_recent_unreliable_storage_mount() {

    local return_value

    local i
    local storage_mounts_string
    local storage_mount
    local storage_mount_basename
    local unreliable_storage_mount
    local android_build_version_sdk
    local valid_number_regex='^[0-9]+$'

    local -a storage_mounts_array=()

    # Find android sdk/os version
    # Termux app exports ANDROID__BUILD_VERSION_SDK for `>= v0.119.0`
    if [[ ! "$ANDROID__BUILD_VERSION_SDK" =~ $valid_number_regex ]]; then
        android_build_version_sdk="$(unset LD_LIBRARY_PATH; unset LD_PRELOAD; getprop "ro.build.version.sdk")"
        return_value=$?
        if [ $return_value -ne 0 ] || [[ ! "$android_build_version_sdk" =~ $valid_number_regex ]]; then
            echo "Failure while finding \"ro.build.version.sdk\" property" 1>&2
            echo "ANDROID__BUILD_VERSION_SDK = \"$android_build_version_sdk\"" 1>&2
            if [ $return_value -eq 0 ]; then
                return_value=1
            fi
            return $return_value
        fi
    else
        android_build_version_sdk="$ANDROID__BUILD_VERSION_SDK"
    fi

    # If on Android `< 11`
    if [ "$android_build_version_sdk" -lt 30 ]; then
        echo "Cannot find unreliable storage mounts on Android sdk version '< 30'. Current sdk version is '$android_build_version_sdk'." 1>&2
        return 1
    fi

    storage_mounts_string="$(grep -E "^[^ ]+ /mnt/media_rw/[A-Z0-9]{4}-[A-Z0-9]{4} " /proc/mounts | cut -d' ' -f2)"
    return_value=$?
    if [ $return_value -ne 0 ]; then
        echo "Failure while finding most recent unreliable storage mount" 1>&2
        return $return_value
    fi

    if [ -z "$storage_mounts_string" ]; then
        echo "Failed to find any reliable or unreliable storage mounts" 1>&2
        return 1
    fi

    IFS=$'\n' read -r -d '' -a storage_mounts_array <<< "$storage_mounts_string"

    for (( i=${#storage_mounts_array[@]} - 1; i >= 0; i-- )) ; do
        storage_mount="${storage_mounts_array[i]}"
        storage_mount_basename="${storage_mount##*/}"

        grep -qE "^[^ ]+ /storage/$storage_mount_basename " /proc/mounts
        return_value=$?
        if [ $return_value -eq 1 ]; then
            unreliable_storage_mount="$storage_mount"
            break
        elif [ $return_value -ne 0 ]; then
            echo "Failure while finding if storage mount is unreliable" 1>&2
            return $return_value
        fi
    done

    if [ -z "$unreliable_storage_mount" ]; then
        echo "Failed to find any unreliable storage mounts" 1>&2
        return 1
    fi

    echo "$unreliable_storage_mount"

}

Screenshot_2024-10-20_19-41-39
7345
123
345

@hansm629 hansm629 added the package request A new package was requested label Oct 20, 2024
@twaik twaik changed the title [Package]: USB storage mount display in Thunar file manager [feature]: USB storage mount display in Thunar file manager Oct 20, 2024
@twaik
Copy link
Member

twaik commented Oct 20, 2024

@hansm629 It is not a package request, it is a feature request.

@twaik twaik added enhancement and removed package request A new package was requested labels Oct 20, 2024
@twaik
Copy link
Member

twaik commented Oct 20, 2024

Probably it can be done in some other way. But the problem is that we can not poll for storage status change, we will have to implement some poller which will invoke storage checking every second/two/five to stay up-to-date...
And it definitely will not be a bash script.
Also it is not specific to thunar, but to all file managers.

@hansm629
Copy link
Author

@twaik
As of now, there is the inconvenience of having to manually enter the path in Thunar, but the USB storage from USB OTG is recognized in real-time by the Termux system both when it's mounted and unmounted, without the need to input any additional commands.

If the mounted USB storage volume could be displayed in real-time in Thunar, it would be a significant leap forward for computing on Termux!

:)

@twaik
Copy link
Member

twaik commented Oct 20, 2024

for computing on Termux!

for UX, not for computing.

@hansm629
Copy link
Author

@twaik
From that perspective, it could indeed be seen as a simple UX improvement. (Since the terminal system already supports real-time mount/unmount.)

It would be great if this could be reflected as part of GUI usability improvements. The fact that it's now possible to mount USB storage on non-rooted devices, which was previously considered impossible, is already a huge advancement in itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants