Skip to content

Conversation

nbradbury
Copy link
Contributor

@nbradbury nbradbury commented Aug 12, 2025

This PR updates the Jetpack REST connection flow to install the Jetpack plugin.

@oguzkocer I don't expect a full review from you, but it would be good to have your eyes on JetpackInstaller to verify I'm using wordpress-rs correctly.

To test

  • Make sure the application passwords and Jetpack REST connection experimental features are enabled
  • Switch to a self-hosted site that doesn't have Jetpack installed
  • My Site > Stats
  • Tap "Install Jetpack"
  • Tap Start
  • After the wp.com login step completes (which it will right away if the wp.com access token already exists), verify that the Jetpack plugin installation succeeds
  • Go to your site in the browser and verify the plugin is installed
  • Deactivate the plugin in the browser
  • Relaunch the app
  • Run the connection flow again and verify the plugin is activated

Note: The connection flow will be stuck on the "Connect your site" step after the plugin is installed. That will be tackled in the next PR.

Screen_recording_20250813_154231.mp4

@dangermattic
Copy link
Collaborator

dangermattic commented Aug 12, 2025

4 Warnings
⚠️ strings.xml files should only be updated on release branches, when the translations are downloaded by our automation.
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ Class JetpackInstaller is missing tests, but unit-tests-exemption label was set to ignore this.
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Aug 12, 2025

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr22119-77eaae8
Commit77eaae8
Direct Downloadjetpack-prototype-build-pr22119-77eaae8.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Aug 12, 2025

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr22119-77eaae8
Commit77eaae8
Direct Downloadwordpress-prototype-build-pr22119-77eaae8.apk
Note: Google Login is not supported on these builds.

@nbradbury nbradbury requested a review from Copilot August 13, 2025 11:27
Copilot

This comment was marked as outdated.

@nbradbury nbradbury requested a review from Copilot August 13, 2025 12:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements Jetpack plugin installation functionality for the Jetpack REST connection flow. When users connect to a self-hosted site without Jetpack installed, the app now handles plugin installation automatically as part of the connection process.

  • Adds a new JetpackInstaller class that uses the WordPress REST API to install and activate the Jetpack plugin
  • Updates the connection view model to integrate plugin installation as a proper step in the flow
  • Adds error handling for installation failures and inactive plugin states

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
strings.xml Adds error messages for Jetpack installation failures
JetpackRestConnectionViewModel.kt Integrates plugin installation step and improves flow control
JetpackRestConnectionScreen.kt Updates UI to handle new installation error types
JetpackInstaller.kt New class implementing Jetpack plugin installation via REST API

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@nbradbury nbradbury marked this pull request as ready for review August 13, 2025 12:46
@nbradbury nbradbury requested a review from adalpari August 13, 2025 12:46
@nbradbury nbradbury requested a review from oguzkocer August 13, 2025 20:19
}

private fun initApiClient(site: SiteModel): WpApiClient {
return WpApiClient(
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ What about moving this WpApiClient creation to. WpApiClientProvider, so we are sure every instance creation is done there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I can look into this for this subsequent PR which moves the WpApiClient initialization to a helper class.

Copy link

@@ -60,6 +63,9 @@ class JetpackRestConnectionViewModel @Inject constructor(
}
}

/**
* Called when all steps have completed successfully
*/
private fun onJobCompleted() {
appLogWrapper.d(AppLog.T.API, "$TAG: Jetpack connection job completed")
job?.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Not related to this PR, but out of curiosity. Why do we need to cancel the job when it's completed? A job is automatically finished when all its code is run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, that's not really necessary. I'll remove that in the next PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest auditing the job lifecycle because if the internal called methods can create their own scope, and the current job will finish while internally other threads are running. This happened to me when I tried to cancel uploads using jobs. It happened that OkHttp was handling the network calls on its own, so the external job was useless. So, since you are using worpdress-rs, which uses OkHttp, it would be great to double-check it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using a job so the flow could be cancellable, but you make a very good point. There really isn't a way to cancel any of the steps in this flow once they're underway - it only cancels moving to the next step. Perhaps it would make more sense to simply have an isCancelled flag so we can stop after the current step?

Copy link
Contributor

@adalpari adalpari Aug 14, 2025

Choose a reason for hiding this comment

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

Yeah, makes sense. Maybe just having a flag or a state is simpler and effective at the same time. If the job is not adding extra cancellable value, I would go for the simplest approach then, because of readability and maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the Linear project to include removing the job.

Copy link
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

Apart form the minor comments I did, it looks good to me! :shipit:

@nbradbury nbradbury merged commit f43b029 into trunk Aug 14, 2025
26 checks passed
@nbradbury nbradbury deleted the feature/jetpack-connect-install branch August 14, 2025 10:09
@oguzkocer
Copy link
Contributor

@oguzkocer I don't expect a full review from you, but it would be good to have your eyes on JetpackInstaller to verify I'm using wordpress-rs correctly.

@nbradbury I looked at the wordpress-rs usage and didn't spot any issues related to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants