Skip to content

feat(plugins): typed invoke arguments for mobile plugins#8076

Merged
lucasfernog merged 19 commits intodevfrom
feat/mobile-typed-invoke-args
Oct 23, 2023
Merged

feat(plugins): typed invoke arguments for mobile plugins#8076
lucasfernog merged 19 commits intodevfrom
feat/mobile-typed-invoke-args

Conversation

@lucasfernog
Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

This PR changes the plugin command API to enforce typed arguments instead of relying on on-demand argument processing via invoke.getString, invoke.getInt, invoke.getObject etc.

New API for Android:

class Options(val recursive: Boolean = false)

class ExampleArgs(val path: String?, val options: Options?, val enabled: Boolean = true)

@TauriPlugin
class ExamplePlugin(private val activity: Activity): Plugin(activity) {
    @Command
    fun run(invoke: Invoke) {
        val args = invoke.parseArgs(ExampleArgs::class.java)
        invoke.resolveObject(args)
    }
}

New API for iOS:

class Options: Decodable {
  let recursive: Bool = false
}

class ExampleArgs: Decodable {
  let path: String?
  let enabled: Bool = true
  let options: Options?
}

class ExamplePlugin: Plugin {
  @objc public func run(_ invoke: Invoke) throws {
    let args = try invoke.parseArgs(ExampleArgs.self)
    invoke.resolve(args)
  }
}

Note that you can also resolve with an object instead of the generic JSObject class / dictionary.

@lucasfernog lucasfernog requested a review from a team as a code owner October 21, 2023 17:44
@lucasfernog
Copy link
Copy Markdown
Member Author

lucasfernog commented Oct 21, 2023

seems like the jackson dependency costs 1MB on the AAB size, maybe we can optimize that or find a better package for this (though AFAIK there's no Java expert on the team 😂 )

amrbashir
amrbashir previously approved these changes Oct 23, 2023
Copy link
Copy Markdown
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

Android sounds OK to me

// If call was made with a list of specific permission aliases to request, save them
// to be requested
val providedPerms: JSArray = invoke.getArray("permissions", JSArray())
// TODO val providedPerms: JSArray = invoke.getArray("permissions", JSArray())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why was this changed to TODO? should it be solved in this PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oops missed this one, thanks for catching it @amrbashir

@amrbashir
Copy link
Copy Markdown
Member

seems like the jackson dependency costs 1MB on the AAB size, maybe we can optimize that or find a better package for this (though AFAIK there's no Java expert on the team 😂 )

Java yikes, do these developers exist any more 😂?

@lucasfernog lucasfernog merged commit 198abe3 into dev Oct 23, 2023
@lucasfernog lucasfernog deleted the feat/mobile-typed-invoke-args branch October 23, 2023 17:09
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