Skip to content

Conversation

@ferdnyc
Copy link
Member

@ferdnyc ferdnyc commented Feb 7, 2025

Remove _listDirectories() from the SFTP plugin code, and never try to probe the root of the remote device mount (since it's always a permission-denied path on Android). Instead, use the multiPaths / pathNames keys in the SFTP packet body to determine the director(y/ies) on the remote device.

Instead of creating a single symlink to the device's root path in the by-name directory, turn the by-name/${device_name} path into a directory, populated on mount with a symlink to each of the device paths supplied in the packet.

Build the Files menu for the device with a list of these shared path names, each of which (although KDE Connect seems to be back to just a single shared directory, again) will open the remote path associated with that share-name. Unmounts (either explicit via the Files submenu, or observed) will remove these symlinks from the device directory (which is kept around for future mounts).

...This all works great, from the Preferences device interface. If I open the "Mobile Settings" interface, click on my paired device, and use the vertical ellipsis (︙) menu, I can choose "Mount" to mount the remote share, and that menu entry is replaced with a "Files" submenu that, when entered, shows the name of my remotely-accessible share ("Internal Storage", on my Samsung phone) and the "Unmount" option. I can click "Internal Storage" to open the URL of the remote path, or "Unmount' to disconnect and turn the "Files" submenu back into "Mount".

Yay, right?

Only problem, it completely breaks in the user menu. For some reason, there, the Files submenu doesn't work at all. It shows up when "Mount" is activated, but attempting to enter it just closes the user menu instead of revealing the submenu contents.

So, until that's fixed, this gets draft status. Ideas on how to fix that (along with any other reviews) more than welcome!

(If/when it actually works right...)
Fixes #1203
Fixes #1861
Fixes #1857
Fixes #1794
Fixes #1610
...and probably more beyond that.

@ferdnyc ferdnyc added help wanted An issue that needs contributors needs review A contribution that needs code review labels Feb 7, 2025
@ferdnyc ferdnyc marked this pull request as draft February 7, 2025 02:06
@ferdnyc
Copy link
Member Author

ferdnyc commented Feb 7, 2025

This PR currently also adds a bunch of debugging to the SFTP plugin, which I'm personally inclined to leave in there permanently. (Except for the one bit that dumps out the remote-directory mapping object, that's clearly an unnecessary level of "debug printf" output that I simply forgot I'd left in there.)

But debug messages in general, I say: love 'em, want 'em, need more of 'em! One of the things that can be frustrating in working on the GSConnect codebase is that there's precious little output even in debug mode, other than the ubiquitous packet dumps and (if you're lucky) tracebacks from any exceptions caught. Which means that communication-heavy plugins like SMS, connectivity, and MPRIS (now that I've discovered its accidental spamminess, as documented in #1919) can be overwhelming as they incessantly chatter back and forth with the other end of the connection. Which only worsens the problem that operations in other plugins like SFTP, the ones that involve minimal kdeconnect packet traffic, occur in such relative silence that it feels like you have absolutely no idea what's happening on most of the time, and no way to find out, either.

...Oh, and I changed at least one call to the underlying ssh-keygen tool so that if it produces any stderr output, that gets logged with logError() rather than debug(). Because why would we only want to see error messages when debugging is activated?!?

@mavit
Copy link
Contributor

mavit commented Feb 9, 2025

Only problem, it completely breaks in the user menu. For some reason, there, the Files submenu doesn't work at all. It shows up when "Mount" is activated, but attempting to enter it just closes the user menu instead of revealing the submenu contents.

I'm away from my computer, so can't test this to confirm, but this sounds a lot like #1794?

@ferdnyc
Copy link
Member Author

ferdnyc commented Feb 9, 2025

@mavit Yup, sounds the same. (Well, I haven't tried using keyboard nav to open the submenu, but even if that works it's not really useful so I'll just assume it does.)

@ferdnyc
Copy link
Member Author

ferdnyc commented Feb 10, 2025

OK, I think I have a plan for this, but it's going to mean a fairly substantial re-re-working of the whole setup.

I got to thinking: The thing about the SFTP plugin is, because of the way it works (handing off operation to Gvfs completely), mounted shares aren't really tied to the device at all. You could shut down GSConnect, the mount would still be there. You could unpair the device, the mount would still be there. It's even theoretically possible that you could disconnect the device from GSConnect, and the mount would still be there. (Probably not, because it would be disconnected from SFTP as well, but it's theoretically possible.)

The mount can also be disconnected outside the control of the device, by the user Ejecting it in Nautilus/Nemo/etc. (It can be created the same way, if KDE Connect hasn't shut down its SFTP server, but let's ignore that.)

So, because (once mounted) a device's shared filesystem really has nothing to do with that device anymore, I think the mounts list should be taken out of the device menu.

Instead, I want to add a new section to the GSConnect menu, above the device list, that shows mounted shares from any/all devices. Each would be labeled (in a translatable string, for locales where the :-separated label doesn't make sense) as ${device.name}: ${mount.name}, where the latter comes from the KDE Connect app.

So, if I Mount the remote storage of my Samsung Galaxy A53 phone, the menu would show this:

GSConnect: Mounted Shares Menu

When I unmount the (last) share, the entire "Mounted Shares" section disappears. If the device disconnects, but the mount is still there, it stays and only the device section is removed.

So, effectively, the monitoring of mounts would be taken out of the hands of the SFTP plugin, and given to a new GSConnect service. The device plugins would be responsible for:

  1. Sending sftp.request packets to the paired device, in response to a Mount command from the user
  2. Forwarding along mountable-share data, when sftp packets come in from the paired device (in response to the previous)
  3. Passing along Unmount commands from the user, to disconnect any mounted shares for its device
  4. Swapping Mount for Unmount (and vice versa) in the device menu actions list

Now, don't ask me (a) how I'm going to represent this in panel mode, or (b) how I'm going to represent it in the GSConnect preferences interface. Because I have no idea.

Copy link
Collaborator

@andyholmes andyholmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me. Probably some nifty JS tricks that could be used, but the code is very readable.

👍 from me, assuming it's tested in the real world :)

Add a new utility module for file/directory tools. Currently it
contains only the filesystem-name sanitization code that used to
live in service/plugins/sftp.js (used when creating filesystem
objects with names based on device names).
Remove `_listDirectories()` from the SFTP plugin code, and never
try to probe the root of the remote device mount (since it's
always a permission-denied path on Android). Instead, use the
`multiPaths` / `pathNames` keys in the SFTP packet body to
determine the director(y/ies) on the remote device.

Instead of creating a single symlink to the device's root path
in the `by-name` directory, turn the `by-name/${device_name}`
path into a directory, populated on mount with a symlink to each
of the device paths supplied in the packet.

Build the `Files` menu for the device with a list of these shared
path names, each of which (although KDE Connect seems to be back
to just a single shared directory, again) will open the remote path
associated with that share-name. Unmounts (either explicit via the
Files submenu, or observed) will remove these symlinks from the
device directory (which is kept around for future mounts).
@wcbing
Copy link

wcbing commented Jun 2, 2025

Thanks for reminding me, I realized that I should change the address to /sdcard instead of facing the blank space.🤣

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

Labels

help wanted An issue that needs contributors needs review A contribution that needs code review

Projects

None yet

4 participants