Skip to content
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

logs page for application #339

Closed
wants to merge 8 commits into from
Closed

Conversation

troy-lamerton
Copy link
Contributor

User friendly logcat page.

For example, to share logs page for YouTube app: http://localhost:9000/?appId=com.google.android.youtube

Useful for QA teams.

Copy link
Owner

@yume-chan yume-chan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

Overall looks good, however, as the package name suggests, it's just a demo. It's not meant to be a ready-to-use tool for anyone, so I don't want to add too many "high-level" features that are only some combination of the pre-existing "low-level" API calls. These features are better suited for your own folk, or the internal tool you developed completely from scratch.

A better way to contribute is adding the core logic to the adb package, then (optionally) adding the UI showing its usage in the demo.

For example, when I was working on the file manager and scrcpy demo, I found the rm -rf command is quite common, and its arguments require some quote escapement, so I added a shortcut to it in the adb package.

As the logcat is also a common command, you can add an Adb#logcat(options: LogcatOptions): LogcatStream method, where the options is an object corresponding to logcat's command line switches (It's fine to only have the appId you need now), and the return value may apply some transformations to the output to make it machine-parsable. So everyone can use logcat via API calls easier.

@@ -54,6 +54,8 @@ function App(): JSX.Element | null {
}, []);


const appId = new URLSearchParams(window.location.search).get('appId')
Copy link
Owner

Choose a reason for hiding this comment

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

Use the useLocation hook in Logcat.tsx to read querystring (the return value is almost same as window.location, but works with hash routers).

The final URL will look like /#/logcat?appId=com.google.android.youtube.

Benefits:

  1. Don't need to pass appId down to component here.
  2. Won't interfere with other routes that need other queries.

@@ -160,6 +170,7 @@ function App(): JSX.Element | null {
<CacheRoute
exact={route.exact}
path={route.path}
key={route.path}
Copy link
Owner

Choose a reason for hiding this comment

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

IIRC something didn't work when I added the key, best to not change it. (or add an eslint-disable if you bother)


try {
connectingRef.current = true;
const socket = await device.childProcess.shell();
Copy link
Owner

Choose a reason for hiding this comment

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

Does this still require an interactive shell? Can you childProcess.spawn a logcat process and "connect" it to xterm?

const UpIconProps = { iconName: 'ChevronUp' };
const DownIconProps = { iconName: 'ChevronDown' };

class AdbTerminal extends AutoDisposable {
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe move the class to a separete file to reuse it. Or even extract the whole component so it can be used like <XtermTerminal socket={socket} />

export const Logcat = withDisplayName('Logcat')(({
visible,
device,
applicationId,
Copy link
Owner

Choose a reason for hiding this comment

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

What will happen if appId is undefined? Will it output all logs from the device?

@yume-chan
Copy link
Owner

Note: Currently the CI is broken because the build script of book wrote something to stderr and Rush doesn't like it. Please ignore it.

@troy-lamerton
Copy link
Contributor Author

Note: Currently the CI is broken because the build script of book wrote something to stderr and Rush doesn't like it. Please ignore it.

Do you have an eta on a fix for the CI?

The main benefit in this PR for me is the automatic deployment.

@troy-lamerton
Copy link
Contributor Author

A better way to contribute is adding the core logic to the adb package, then (optionally) adding the UI showing its usage in the demo.

That will bloat the api though? I would prefer to work with an Adb interface that is the same as the adb command line tool.

Maybe this should be added to AdbExtensions or something along those lines.

@yume-chan
Copy link
Owner

Do you have an eta on a fix for the CI?

Fixed

That will bloat the api though?

Yes, but I don't think it currently has enough API to be bloated. 😭

One solution is to group all these binary wrappers in a separated namespace, for example adb.bin.rm() and adb.bin.logcat(). Tree-shaking won't remove unused class instance methods, but they are tiny so shouldn't be a big problem.

Maybe this should be added to AdbExtensions or something along those lines.

I can think of two patterns:

  1. import { Logcat } from 'adb-bin'; new Logcat(adb, options);, it nicely separates code so tree-shaking can always remove unused exports from adb-bin, but it still complicates API usage.
  2. adb.extends([Logcat]); adb.logcat(options);, a common pattern for library extensions. But it's impossible to get TypeScript typings to work with this.

@troy-lamerton
Copy link
Contributor Author

  • To run webadb I have to close Android Studio, and any other tool that uses adb.exe.
  • Is there a workaround for this? Or its a problem in WebUSB?

I explored this for a couple days and the above is blocking me.

@yume-chan
Copy link
Owner

Is there a workaround for this?

No, only one program can have access to a USB device at same time, see https://github.com/yume-chan/ya-webadb/blob/master/apps/book/src/basics/transportation.md#server

@yume-chan yume-chan mentioned this pull request Jan 10, 2022
39 tasks
@yume-chan
Copy link
Owner

I'm now working on a table-based logcat view. The remaining tasks are in #425.

Thus closing this PR.

@yume-chan yume-chan closed this Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants