-
Notifications
You must be signed in to change notification settings - Fork 259
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
Use KDE Connect's verification codes #1148
base: main
Are you sure you want to change the base?
Conversation
Also, I used Unicode 🔑 instead of an icon because I couldn't find a suitable icon in what Glade said was available. If there's a better way, let me know. One more thing - this is basically my first time writing anything approaching GTK/GObject/etc. code, so please review with extra scrutiny. I might have broken everything! |
You can run the daemon with GDB if necessary. Let me know if that's something you want help with and after I can add it to the contributing document.
These are fine to leave and not related to your PR. It's just a corner-case in GJS and GDBus related to virtual functions.
I think that the combined verification code is what needs to be shown in the notification, at least I think that's what Android does. I think the older keys are effectively being deprecated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I know this has been here a good long while already, but I jotted down a few things as I was perusing it just now.
</child> | ||
<child> | ||
<object class="GtkButton"> | ||
<property name="label" translatable="yes" context="Send a pair request to the device">Request pairing</property> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<property name="label" translatable="yes" context="Send a pair request to the device">Request pairing</property> | |
<property name="label" translatable="yes" comment="Send a pair request to the device">Request pairing</property> |
This should be a translator comment=
property, rather than a context=
. Contexts are typically used in a more structured way, usually as a hierarchy based on things like class names or high-level UI objects.1 (For example, obvious picks for the context of these messages might be GSConnectPreferencesDevicePanel
or Preferences|Device
.)
Comments, OTOH, are for supplying free-form hints about intended meaning to assist translators, as you've done. 👍
Notes
- (Contexts are used to categorize strings within the code, so that the same source-language string can be used in different situations where it would potentially get translated differently. Like, "Print" could be the title of a dialog, the label for an action button, or it may be used to refer to the output of a printer. Those might be three completely different words in some languages. So there would be three different translatable "Print" strings in the translation master, each tagged with a different context.)
<child> | ||
<object class="GtkLabel"> | ||
<!-- n-columns=3 n-rows=3 --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these dimension comments inserted automatically by some tool, or did you place them manually?
I don't love embedding narration into code, especially as hidden comment text. Simple reason: I have never, ever seen a narrative comment get updated when subsequent changes to the code turn it into a complete LIE. Not one single time. Any narrative comment that's more than a year or two old, or is located in a file that's had more than 20 commits touch it since then, has a roughly 99% chance of being completely false. And the only thing worse than a comment that describes code, is a comment that describes code incorrectly.
...But if some tool manages those, then I suppose it's fine. At least when that tool is used to make changes, they'll presumably be brought up to date.
src/service/device.js
Outdated
// let b = ByteArray.toGBytes(remoteCert.certificate); | ||
let a = ByteArray.toGBytes(ByteArray.fromString('a')); | ||
let b = ByteArray.toGBytes(ByteArray.fromString('b')); | ||
// Lexographic a < b comparison; this is what the < operator on QByteArray does |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "lexicographic"
src/service/device.js
Outdated
verifyCode = checksum.get_string(); | ||
checksum.free(); | ||
|
||
return verifyCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your comment mentioned segfaults... according to the Checksum docs...
get_string()
Returns:
(String
) — the hexadecimal representation of the checksum. The
returned string is owned by the checksum and should not be modified
or freed.
I'm gonna go out on a limb and say that means it's probably NOT OK to access the Checksum-owned string after freeing the Checksum. Perhaps, to be safe...?
verifyCode = GLib.strdup(checksum.get_string());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Note that you'd then have to free the newly-allocated verifyCode
String at some later point, once you're finished with it.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that is bizarre so I've asked about it in the #javascript channel. SpiderMonkey should be able to handle this without the GLib.strdup()
, but I'm surprise that function is even in our bindings and that it seems to work! GLib.free()
is definitely a no-go in GJS, so I'm not sure if this will leak memory or if SM can free it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andyholmes Heh, always fun when the soft underbelly of a native C API is exposed to a higher-level lanugage. Just like Python's lazy garbage collector frees developers from worrying much about allocation lifetimes... in theory.
Until you find yourself working with SWIG-generated C/C++ library bindings in Python. Then, unless both the native library and its bindings are really meticulous, you definitely start to care about your object lifetimes. In C++, not properly cleaning up your allocations "merely" leaks memory. But if Python's gc goes stomping around, cleaning up for you, invalidating pointers it hasn't been told are still very much in use over on the native side, You're Gonna Have A Bad Time™.
src/preferences/device.js
Outdated
// Action setup | ||
this._setupActions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phew, there's that mystery solved! 😈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, I recall feeling the same way writing it. But it looked out of place otherwise 😂
Closing this as completed, since it was brought home by @daniellandau in #1493 and is now merged. Thanks @strugee ! |
Whoops. Premature close, as there's more to this PR than what went in with #1493. Reopening, and attempting to reconcile with the current |
That actually wasn't hard at all, in terms of actual change conflicts. Whether the code on this branch is still compatible with the |
Hey, sorry for disappearing - life got in the way :-) Glad to hear my work was useful for #1493. |
Fixes #1091
Still TODO:
Some notes on the segfaults: they seem to happen during the pairing process. I think there's a race condition or something like that during the verification code computation. Most of the time I just get
Segmentation fault (core dumped)
, but occasionally I get a longer assertion error:The UTF-8 errors come from the preferences pane and all look like this: