-
Notifications
You must be signed in to change notification settings - Fork 761
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
Help Browser code execution #4883
Conversation
681b0a1
to
cfa4c63
Compare
I've built it on Windows and tested code execution in the Help Browser - works fine. I haven't had a chance to look deeper yet, but doesn't seem like there are any apparent issues with Windows at first glance. |
thanks for testing it @dyfer! |
4876831
to
dd568e7
Compare
6d8dd76
to
5ef0990
Compare
Rebased on 3.11 |
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.
thanks! i haven't tested it yet but i have a few questions about the code before reviewing further
@@ -159,7 +158,8 @@ void WebView::toPlainText(QcCallback* cb) const { | |||
void WebView::runJavaScript(const QString& script, QcCallback* cb) { | |||
if (page()) { | |||
if (cb) { | |||
page()->runJavaScript(script, cb->asFunctor()); | |||
// convert QVariant to string until we deal with QVariants | |||
page()->runJavaScript(script, [cb](const QVariant& t) { cb->call(t.toString()); }); |
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.
i don't understand this comment
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.
Fair enough :) Sorry for being criptic, now I also have to look it up again. We have a problem when passing a QVariant back into sclang:
- runJavascript takes a callback function, which gets converted to this QcCallback
- when the callback is called, sclang throws an error:
ERROR: Qt: Failed to write a slot when trying to run interpreter!
If anyone feels like trying it out, this code errors without this PR:
WebView().runJavaScript("1+1"){|res,e|res.class.postln}
This problem does not happen when we convert to string before calling the QCallback. I can definitely look deeper into this, and suggestions are very welcome :)
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.
Ok I've investigated a bit more and I think this maybe deserves another PR. I'll try to explain here:
- JavaScript can return a variety of types to sclang, so it gives a QVariant as argument to the callback.
- The callback fires, emitting a signal that is caught by a QSignalSpy
- QSignalSpy gets the argument as a void* (but it also gets its type), and throws it into a QVariant. Now we have a
QVariant<QVariant>
- QSignalSpy sends the arguments to QtCollider::runLang, which calls QtCollider::set, which fails for a
QVariant<QVariant>
I have a fix for QSignalSpy to avoid creating a QVariant<QVariant>
which makes possible to return Numbers, Strings and Arrays. The only type that still fails is QMap. I haven't tested if this code has consequences on any other call, it looks like a legit bugfix for me, I'm tempted to include it here... what do you think would be best?
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.
thanks for looking into it! since this is the last PR before the 3.11.2 release, let's just leave this as it is. if you're interested you can make another PR for it, i'd also be happy to take a look myself.
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.
ok, we keep it like it is then and I'll open another PR! Just to be extra clear, now all javascript calls from sclang will always return a string only
thanks for the quick update @elgiano . if you can address https://github.com/supercollider/supercollider/pull/4883/files#r509325107 i'm ready to review the rest of the PR after that :) |
Yeah, thanks for looking at it @brianlheim! |
I think I got what you meant now! I pushed all changes for your pre-review, I hope it's fine now :) |
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.
i think this approach makes sense overall. i have a few questions and then some comments assuming this is the way we want to proceed
8fbbb3a
to
cd869fa
Compare
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.
thanks @elgiano ! the code all looks good except for one whitespace thing. i want to test it out before approving/merging.
<onSelectionChanged, <onTitleChanged, <onUrlChanged, <onScrollPositionChanged, <onContentsSizeChanged, <onAudioMutedChanged, | ||
<onRecentlyAudibleChanged; | ||
<onSelectionChanged, <onTitleChanged, <onUrlChanged, <onScrollPositionChanged, <onContentsSizeChanged, <onAudioMutedChanged, | ||
<onRecentlyAudibleChanged, <enterInterpretsSelection = false; |
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.
please undo the whitespace changes
@@ -159,7 +158,8 @@ void WebView::toPlainText(QcCallback* cb) const { | |||
void WebView::runJavaScript(const QString& script, QcCallback* cb) { | |||
if (page()) { | |||
if (cb) { | |||
page()->runJavaScript(script, cb->asFunctor()); | |||
// convert QVariant to string until we deal with QVariants | |||
page()->runJavaScript(script, [cb](const QVariant& t) { cb->call(t.toString()); }); |
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.
thanks for looking into it! since this is the last PR before the 3.11.2 release, let's just leave this as it is. if you're interested you can make another PR for it, i'd also be happy to take a look myself.
QtCollider/factories.cpp
Outdated
@@ -26,6 +26,11 @@ | |||
|
|||
QC_DECLARE_QWIDGET_FACTORY(QLabel); | |||
|
|||
#ifdef SC_USE_QTWEBENGINE | |||
# include "widgets/QcWebView.h" |
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.
aghh, you need to add a space here for linting
# include "widgets/QcWebView.h" | |
# include "widgets/QcWebView.h" |
@elgiano do we use websockets for anything at all after this PR? |
After a little grep I haven't found any place where we are using them, which I also suspected. |
HelpSource/editor.js
Outdated
@@ -38,7 +38,10 @@ const init = () => { | |||
lineWrapping: true, | |||
viewportMargin: Infinity, | |||
extraKeys: { | |||
'Shift-Enter': evalLine | |||
// noop: prevent both codemirror and the browser to handle Shift-Enter | |||
'Shift-Enter': ()=>false |
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.
missing a comma here
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.
yesss, thanks for catching it! btw I changed to ()=>{} which looks like a more proper noop
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.
thanks again! i think this is all good. now that we are not using the websocket code, i would like to remove that too, but that can be done on the develop branch after the 3.11.2 release.
i also tested the latest version myself on macOS 10.14, windows 10, and arch linux, all fine.
Thanks a lot @brianlheim and @dyfer!!! |
Purpose and Motivation
Fixes #4542 and #4000
Explained more in detail in an RFC and open for discussion. Please let's discuss it, I don't want to push this in any way. I also would really benefit from some other pairs of eyes on it. And it needs testing on Windows.
RFC: https://github.com/elgiano/rfcs/blob/helpbrowser/rfcs/0009-helpbrowser-code-evaluation.md
Types of changes
To-do list
It works on Linux and Mac.
Missing testing on Windows. Also on Windows, thanks @dyfer