sentry-dart icon indicating copy to clipboard operation
sentry-dart copied to clipboard

Replace custom Platform & PlatformChecker with package platform

Open vaind opened this issue 10 months ago • 7 comments

Description

Replace:

  • dart/lib/src/platform/platform.dart
  • dart/lib/src/platform_checker.dart

with https://pub.dev/packages/platform

Update: we've done some improvements/refactors in PlatformChecker but this issue is blocked until dart officially adds support for web as well, see https://github.com/dart-lang/core/pull/862

vaind avatar Jan 30 '25 09:01 vaind

@vaind Hey! Just started this and i'm seeing that example_web_compile_test.dart fails, as a file in the package uses dart:io

https://github.com/dart-lang/core/blob/main/pkgs/platform/lib/src/interface/local_platform.dart

Not sure how to circumvent this. Any suggestions?

denrase avatar Feb 17 '25 15:02 denrase

You should be checking for "kIsWeb" (or do the same check in Dart code) before using the platform package.

ueman avatar Feb 17 '25 15:02 ueman

You should be checking for "kIsWeb" (or do the same check in Dart code) before using the platform package.

we can definitely work around this but then we'd still have to use the existing impl for web so not sure if it's worth it to use it? wdyt

buenaflor avatar Feb 17 '25 15:02 buenaflor

Any suggestions?

Is there a branch I can have a look at?

vaind avatar Feb 18 '25 10:02 vaind

@vaind Pushed the code i had locally. Pretty much replaced our Platform definition in favour of package:platform/platform.dart, but here we have the issue that dart:io is used.

denrase avatar Feb 18 '25 13:02 denrase

I've missed that package:platform doesn't support web at the moment. I've opened a draft PR to add support but for now, we cannot use it.

At the very least, I've taken a stab at cleaning up PlatformChecker (moving actual platform-specific stuff to the Platform) and added TODOs for potential improvements. @denrase see https://github.com/getsentry/sentry-dart/pull/2730 what do you think about these changes and the TODOs in PlatformChecker. Also, feel free to pick it up as I won't have the capacity to do so in the next couple of days, other than fixing any CI issues with #2730

vaind avatar Feb 18 '25 21:02 vaind

@vaind Thank you for your insights and the PR, i'll take a look at it. 🙇

denrase avatar Feb 19 '25 14:02 denrase