cozy / cozy-flagship-app

GNU Affero General Public License v3.0
9 stars 1 forks source link

[VO-258] feat: Allow to send logs my email after clicking on a deep link #1137

Closed Ldoppea closed 7 months ago

Ldoppea commented 9 months ago

In order to allow sending logs whatever if the app is logged or not, or even when the app is stuck on SplashScreen, the easiest way to trigger sending logs is to use deep links

By implementing this, user can now click on cozy://enablelogs or https://links.mycozy.cloud/flagship/enablelogs links to tell the app to start recording logs into a local file

They can then click on cozy://sendlogs or https://links.mycozy.cloud/flagship/sendlogs links to trigger the OS send email intent pre-filled with log files and Cozy's support email

Finally then can click on cozy://disablelogs or https://links.mycozy.cloud/flagship/disablelogs links to tell the app to stop recording logs

This method is not the most user friendly but it has the advantage to be resilient to UI bugs

We may want to find a more user friendly method in the future and keep this one for exceptional cases (or internal ones)


This feature is based on the react-native-file-logger plugin, that does not need to be configured with cozy-minilog as it captures all console calls and redirect them to a file

By default react-native-file-logger will redirect all logs to a file in the app's cache directory

Daily rolling is enabled and the max file size is 5 files of 1MB

We want to decrease the log level to Info so all the app's logs are redirected

Finally ${now} [${level}] is added before all log in the resulting file


TODO:

Improvement ideas:

zatteo commented 9 months ago

Add another deep link to enable/disable logging to file and disable it by default

I think it may be needed before releasing.

Checks if GPS Memory logs are included

Currently, GPS Memory messages are logged to a cozy-minilog logger AND to react-native-background-geolocation logger. So it should. In the next weeks, I will try to not send them to Sentry, but I want to keep them in the console for debugging purpose.

zatteo commented 9 months ago

Can't wait to see it in production. Will be very useful.

Ldoppea commented 8 months ago

I added a new commit to this PR: https://github.com/cozy/cozy-flagship-app/pull/1137/commits/f121a8b5866e284eb206fa997865861d50f16243

This ones makes the feature "opt-in" and the user now needs to click a UL to enable login into files.

Also I found a bug on iOS when the app is connected. If for some reason the splashscreen is hidden while the email pane is opened, then the splashscreen plugin will hide the email pane instead (because it blindly hides the topmost view)

I'll have to find a workaround for this, either by showing an email_splashscreen while the email pane is opened, or by finding a way to fix the bootsplash library so it always hide the correct view. I'm not sure yet on to do these

In theory the email_splashscreen option would work great, but I have to find how to wait for the email pane to be closed. For now the method directly resolves its promise when called.

The sendLogFilesByEmail method shows a MFMAilComposeViewController and then resolves But this view's callback is the didFinishWithResult method which has no access to the promise. I'll have to find a way to keep the promise pointer between the two methods

Ldoppea commented 8 months ago

This PR is ready for review, I fixed previous issue by patching react-native-file-logger package in https://github.com/cozy/cozy-flagship-app/pull/1137/commits/9157df2f39a93d2450236a4175bc3907e04fdbb7