View console log in note editor#6808
Conversation
There was a problem hiding this comment.
I like the result, but I think we should spend a little time planning one as there's a lot of options on how to implement it.
Could we create a linked issue to discuss the design of this feature?
We definitely should be avoiding static state wherever possible as it potentially leaks memory and is harder to test and reason about.
My first impression would be: maybe this could be implemented as a toolbar icon in the previewer (also with a "copy to clipboard" button), but I'm not currently certain about the best direction and don't want to propose an idea in a review that won't make it to reality.
|
Create issues #6810 I will look into adding option to previewer toolbar. I tried to not use static variable but Android Studio suggesting to use that. Copy to clipboard can be implemented. |
|
How to know in advance how much log to print? If want to print last 10 log but there are not 10 log. There are only 4 log. So how it can be implemented? |
There was a problem hiding this comment.
Don't worry about the test failures - it'll be sorted in a few hours when another maintainer approves my PR.
I'll write a "Circular Buffer" class which will help with the log lines later on today (remind me if I don't get back to it).
Consider writing a small class which contains line number and the line data, and store this. Do the string concatenation when someone requests the full log. This reduces the memory used in the application, and makes the process much faster - string operations are relatively slow, and if we can avoid doing them until necessary, it'll give a better user experience.
| protected String mTempAudioPath; | ||
|
|
||
| // Console log in JS api | ||
| private static String jsApiConsoleLog = ""; |
There was a problem hiding this comment.
Neither of these variables need to be static
| * Line: 7 | ||
| * Message: Some message | ||
| */ | ||
| StringBuilder sb = new StringBuilder(); |
There was a problem hiding this comment.
if (!enableDebugMode) {
return;
}
This means that we don't do additional processing unless we have debug mode enabled, the check can also be removed from showConsoleLog
| } | ||
| } | ||
|
|
||
| protected static void showConsoleLog(String log) { |
There was a problem hiding this comment.
| protected static void showConsoleLog(String log) { | |
| protected void showConsoleLog(String log) { |
|
|
||
| @JavascriptInterface | ||
| public void ankiJsConsoleLog(boolean enableLog) { | ||
| if (enableLog) { |
There was a problem hiding this comment.
Alt+Enter - Invert the if. It should help for readability
|
|
||
| View parentLayout = findViewById(android.R.id.content); | ||
|
|
||
| Snackbar snackbar = Snackbar.make(parentLayout, "Bebug Mode Enabled", Snackbar.LENGTH_LONG); |
There was a problem hiding this comment.
This would likely be better as a toast
We have UIUtils.showThemedToast
For future use: UIUtils.showSimpleSnackBar can also reduce code here and make it more readable.
|
|
||
| View parentLayout = findViewById(android.R.id.content); | ||
|
|
||
| Snackbar snackbar = Snackbar.make(parentLayout, "Bebug Mode Enabled", Snackbar.LENGTH_LONG); |
There was a problem hiding this comment.
Should be extracted to a string resource (02-strings.xml should do)
| Snackbar snackbar = Snackbar.make(parentLayout, "Bebug Mode Enabled", Snackbar.LENGTH_LONG); | |
| Snackbar snackbar = Snackbar.make(parentLayout, "Debug Mode Enabled", Snackbar.LENGTH_LONG); |
| .setAction("view", view -> { | ||
|
|
||
| AlertDialog.Builder builder = new AlertDialog.Builder(AbstractFlashcardViewer.this); | ||
| builder.setTitle("Console") |
There was a problem hiding this comment.
Ditto: extract to resource
|
I tried to make class but haven't got the expected result. Need help. After removing Extracted to resources.
|
…to console-log
|
Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
|
I found better option for this PR. I think it should be closed now. I used https://github.com/liriliri/eruda for getting dev tools in android. In card template I pasted the following. |
|
Also this can be used to create a new addon |
Yes! Exposing full power of javascript dev inside of ankidroid is going to be amazing (or already is amazing, in your dev branch! :-) ) |
|
Just a friendly notice (one per person, regardless of PR quantity) that we try to process OpenCollective payments monthly - it's time for Dec 2020 submissions - @infinyte7 you have an open PR as well that I am definitely aware of and watching, of course take all work in to account Process note: |
|
Thanks, That PR need to implement Note Editor addons. I am implementing those and also testing it more and more so when I mark it for review then reviewing that PR should take less time. |


Pull Request template
Purpose / Description
While editing note there may need to view console log to remove that error. But that require chrome desktop. This will give console log for that one. (Only text)
Fixes
Fixes #6810
Approach
Using Console APIs in WebView
How Has This Been Tested?
Tested on Real Device and Android emulator.
Learning (optional, can help others)
https://developer.android.com/guide/webapps/debugging
Checklist
Please, go through these checks before submitting the PR.
ifstatements)