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

[Request]: (share_plus) Migrate to package:web to support WASM #2603

Closed
IchordeDionysos opened this issue Feb 17, 2024 · 10 comments · Fixed by #2709
Closed

[Request]: (share_plus) Migrate to package:web to support WASM #2603

IchordeDionysos opened this issue Feb 17, 2024 · 10 comments · Fixed by #2709
Labels
enhancement New feature or request triage

Comments

@IchordeDionysos
Copy link
Contributor

Plugin

share_plus

Use case

Compiling to WASM

Proposal

The short version:

Migrate usage of dart:html to package:web
Migrate usage of dart:js, dart:js_util, and package:js to dart:js_interop
This will allow compiling to WASM engine instead of just JavaScript on web.

Full migration guide: https://dart.dev/interop/js-interop/package-web

@IchordeDionysos IchordeDionysos added enhancement New feature or request triage labels Feb 17, 2024
@IchordeDionysos IchordeDionysos changed the title [Request]: Migrate to package:web to support WASM [Request]: (share_plus) Migrate to package:web to support WASM Feb 17, 2024
@sgehrman
Copy link

2 weeks and nothing. What is taking so long??????

@miquelbeltran
Copy link
Member

2 weeks and nothing. What is taking so long??????

#2600 (comment)

In case you need this change urgently, you can also run a local fork with your changes. If you do, please consider submitting a PR with the change and your findings.

@vbuberen
Copy link
Collaborator

vbuberen commented Feb 29, 2024

2 weeks and nothing. What is taking so long??????

This is an open source project, so you are more than welcome to do this yourself. Otherwise you can't demand anything from people who support packages in their free time.

@muhib349
Copy link
Contributor

Trying to work on this issue, however, I'm not getting any leads to initialize the navigator and how to use the share method, if anyone has an idea please let me know. thanks

@miquelbeltran
Copy link
Member

Do you have a fork/branch somewhere @muhib349 to have a look?

@muhib349
Copy link
Contributor

Do you have a fork/branch somewhere @muhib349 to have a look?

Yes, you can have a look on this branch,

https://github.com/muhib349/plus_plugins/tree/issue2603

@IchordeDionysos
Copy link
Contributor Author

@muhib349 you used the correct navigator, however it seems like the share method is not yet supported on the package:web.

What you could do is instead of relying on the package:web, use dart:js_interop and write your own JavaScript interop function.

This is how it's written in the package:web.

It could look a bit like:

import 'dart:js_interop';

extension type Navigator._(JSObject _) implements JSObject {
  # todo: Use correct return type and parameters :)
  external void share();
}

Then you can use that custom Navigator class and call it just like it would exist.
You wouldn't have to depend on package:web at all.

You might be required to set the minimum Dart Version to 3.3 though to use those new Extension Types

I hope this helps.

@miquelbeltran
Copy link
Member

Yes, this helps a lot!

Keep in mind that the original dart:html share method did some extra work: https://api.dart.dev/stable/3.3.0/dart-html/Navigator/share.html, so maybe that will need to be done as well.

Also, a similar solution was discussed here for the missing deviceMemory property for Navigator: dart-lang/web#192 (comment)

And just for reference: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share

Finally, probably also worth opening a ticket on the dart-lang/web repo asking them to incorporate the missing method from dart:html.

@muhib349
Copy link
Contributor

Thanks a lot, @IchordeDionysos and @miquelbeltran. Meanwhile, I'm trying to implement.

@miquelbeltran
Copy link
Member

Well I gave it a go, but I am unable to make it work.

As extension function I defined this one, which I think matches the JS spec. Although I have no idea if this is correct or not.

extension on html.Navigator {
  external JSPromise share([JSObject? data]);
}

The problem I have also is that I don't know is how to properly convert a Map<String, dynamic> to a JSObject.
I gave a try with .toJSBox but no idea if the operation is valid or not.
The error I see on the console is just: "TypeError: Cannot read properties of undefined (reading 'apply')" which no idea what it means.

Another thing I couldn't figure out is how to create a File providing a JSArray<BlobPart>, so I commented out that part.

I honestly have no idea how to move this forward.

My wip branch is pushed in this repo as miquelbeltran/2603 if anyone wants to take a look at the last commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants