-
Notifications
You must be signed in to change notification settings - Fork 30
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
Determine KDE Connect's DBUS_SESSION_BUS_ADDRESS on Windows #44
base: master
Are you sure you want to change the base?
Conversation
3754e8e
to
e476910
Compare
Well, this is quite a dance to go through. I do note that Also, I vaguely recall it being a requirement to write registry keys to install a native host on windows, do you know off-hand if my recollection is correct, and would that mean we'd need to deal with UAC or something for the installer? I'm afraid I haven't spent any real time on Windows in decades, so I appreciate the assistance. |
Oh, wow, after just now hearing of
Reading the Section and obtaining its contents is trivial. Finding KDE Connect's installation directory is not. There's two issues there:
Once KDE Connect's path has been determined, the hashing can be done in kdeconnect-chrome-extension. I looked at the D-Bus code: you take the location of where libdbus.dll is,
You're right, but UAC would only be an issue if you're wanting to do a system-wide install (really, you'd just have to relaunch). Both Chrome (and its derivatives I presume) and Firefox read a per-user registry key on Windows for manifest paths, which doesn't require special privileges to write to.
I'm very much appreciative of this. The approach I've used currently may be... well... convoluted but kdeconnect-chrome-extension has saved me time nevertheless on Windows. |
This is good analysis, not as straight-forward as I was hoping. I'm open to this approach if you agree it would be cleaner than the current method. I'll sort out the installer stuff once it's decided what the path is here. |
e476910
to
5526cc2
Compare
I'm not sure on what GitHub PR etiquette is, to be honest, so I've just rebased the branch this PR is pointing to with code that does the Section reading. It is more complex, but the possible race condition between reading the TCP tables and scanning the processes isn't a problem any more. EDIT: unless you're getting something else calling itself kdeconnect-indicator.exe, this way will always connect to KDE Connect's D-Bus daemon too To try and obtain KDE Connect's path, the following is tried:
For the Windows Store code, I've split the path determination code for both ways into separate files for readability purposes. I can merge the code into one file or get rid of a method entirely. Both do not rely on any undocumented code; however, borrowing a trick from syscall_unix.go's Once the path has been found, the hashed version is cached (naïvely - assumes a single thread) to avoid the path lookups. But the Section is always read. IMO the path isn't likely to change, but relaunching KDE Connect (slightly more likely to happen) may cause its dbus-daemon to change ports. I do not know Go at all, so if there's basic errors or better ways to do things (or even better names for functions or variables), let me know or just have at it. Cheers. |
Sorry for the delay, been a little busy. I think my preference would be to include only the generic implementation that searches for running processes, since that gives us the best coverage for install methods, and lets us drop a bunch of code. I'll try to find time for a proper review over this weekend. |
No worries. Getting rid of the Windows Store-specific code is probably for the best... The one thing I need to add: capping the maximum amount of data read from the Section/Mapping, as I cannot imagine in practice a DBUS_SESSION_BUS_ADDRESS greater than, say, 64Kb. Thanks. |
You should not use that path. And you can't access it easily anyway. |
An execution alias wouldn't help any here. libdbus, when creating its Section with the information that is needed, doesn't use one but does hash the actual path it's in. In any case, getting the actual path isn't a problem any more - it's pulled from the running processes. I did write code to read it from the Windows APIs designed for getting Store applications' information, but removed it following pdf's comments. |
Oh, in that case you are doing it right. Sorry. |
Yes. This code caches the Section name to open, which, as you point out, is liable to change in the case of an update. I don't consider fixing it a huge priority yet, because there's no way (as far as I can tell) to get this native extension to refresh its connection to KDE Connect's D-Bus daemon anyway*. In the two months I've been running this on Windows, I've only had it mess up once, at which point I just disabled and re-enabled the extension and all was well... * I assume there's no need for such a thing in Linux, where the Session Bus is provided by the system |
So basically, it's refreshed every time you restart a browser? |
Yes |
I feel like I need to apologise for the further delays here - I have some of the required changes staged, but I need to replace the installer code with something that will work on Windows and I just haven't made the time yet. |
This adds support for determining KDE Connect's dbus-daemon's session bus's address on Windows. I haven't tested to see if this breaks building on Linux.
Outdated
It works like this:Get a list of processes in the same Windows session as the one kdeconnect-chrome-extension.exe is running in (on a system where multiple users are logged in at the same time, this avoids possibly connecting to the wrong KDE Connect instance)
For any dbus-daemon.exe processes, store their PIDs
Read the system's TCP table and for anything listening to a port bound on 127.0.0.1, see if the PID matches one collected in step 2
If so, call
org.freedesktop.DBus.NameHasOwner
and see iforg.kde.kdeconnect
has registered on the bus. If that is the case, the connection string is cached and the connection is returnedSee #44 (comment)
If this is acceptable, the remaning two issues for fully fledged Windows support would be to adapt the installer (climenu won't build on Windows) and updating godbus to v5.
(As an aside, if someone's interested in adding macOS support...)
EDIT: This requires a newer version of golang.org/x/sys than the one that is automatically pulled in by
glide
as a dependency