Skip to content

Add mobile web app support (Add to Home Screen)#91

Open
kraftbj wants to merge 8 commits intotrunkfrom
mobile-web-app
Open

Add mobile web app support (Add to Home Screen)#91
kraftbj wants to merge 8 commits intotrunkfrom
mobile-web-app

Conversation

@kraftbj
Copy link
Copy Markdown
Collaborator

@kraftbj kraftbj commented Mar 6, 2026

Summary

Enables Press This to work as a standalone mobile web app that can be added to the home screen on Android and iOS. Implements the core features from #2 (originally WordPress core Trac #33195).

  • Add Web App Manifest served via REST endpoint (/press-this/v1/manifest) with Share Target API support (Android)
  • Add mobile web app meta tags (mobile-web-app-capable, apple-mobile-web-app-capable, theme-color, etc.)
  • Add app icons (pencil on WordPress blue) at 180px, 192px, and 512px
  • Handle standalone display mode: skip window.close() in redirects, add "View Site" and "New Post" menu items
  • Sync fallback script dependencies with generated asset file

Share Target

The manifest share_target reuses Press This's existing GET params (?u=...&t=...), so sharing a URL from another Android app opens Press This with the URL pre-filled — no editor changes needed.

Future enhancements

These are out of scope for this PR but documented for future work:

  • Service Worker — cache app shell for instant loading (caveat: iOS evicts SW cache after ~7 days of inactivity)
  • Apple splash screensapple-touch-startup-image tags per device resolution
  • Push notifications — notify of pending drafts or publishing status (requires iOS 16.4+)
  • Share Target file sharing — accept shared images/files via POST + multipart/form-data
Feature Android iOS
Add to Home Screen Yes Yes
Standalone mode Yes Yes
Share Target Yes No (WebKit limitation)

Test plan

  • Load Press This, view source — confirm all meta tags present in <head>
  • Fetch /wp-json/press-this/v1/manifest — confirm valid JSON with correct dynamic URLs
  • Android: Open in Chrome, install as app, launch from home screen — confirm standalone mode with pencil icon
  • iOS: Open in Safari, Share > Add to Home Screen, launch — confirm standalone mode with proper icon
  • Android: Install PWA, share a URL from another app — confirm Press This opens with the shared URL
  • In standalone mode: confirm "More actions" menu shows "View Site" and "New Post" options
  • In standalone mode: publish a post — confirm redirect goes to the post URL instead of trying window.close()
  • Launch from home screen with no URL params — confirm editor loads as empty post

Enable Press This to work as a standalone mobile web app via Add to
Home Screen on Android and iOS. Adds Web App Manifest with Share Target
API support, app icons, mobile web app meta tags, and standalone mode
UI handling.

Closes #2

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kraftbj kraftbj requested a review from Copilot March 6, 2026 23:30
Copy link
Copy Markdown
Contributor

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

Adds Progressive Web App (Add to Home Screen) support for Press This, including a web app manifest endpoint and UI behavior tweaks for standalone display mode.

Changes:

  • Serve a Web App Manifest via a new public REST endpoint, including Share Target support.
  • Add standalone-mode behavior adjustments (redirect behavior + menu items).
  • Add mobile web app meta tags and icon/manifest links in the Press This HTML head.

Reviewed changes

Copilot reviewed 5 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/components/PressThisEditor.js Detects standalone mode to adjust redirect behavior.
src/components/Header.js Adds standalone-only menu items and standalone detection.
press-this-plugin.php Registers a new REST route and returns the manifest JSON.
includes/class-press-this-assets.php Syncs script dependencies by adding wp-keyboard-shortcuts.
class-wp-press-this-plugin.php Injects mobile web app meta tags and manifest/icon links.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Set Content-Type to application/manifest+json per W3C spec. Localize
the app name in both the manifest endpoint and the apple-mobile-web-app-title
meta tag for translation support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +189 to +191
return (
window.matchMedia( '(display-mode: standalone)' ).matches ||
window.navigator.standalone === true
Comment on lines +104 to +106
() =>
window.matchMedia( '(display-mode: standalone)' ).matches ||
window.navigator.standalone === true,
Comment on lines +421 to +446
{ isStandalone && (
<>
<MenuItem
href={ siteUrl }
onClick={ onClose }
>
{ __(
'View Site',
'press-this'
) }
</MenuItem>
<MenuItem
onClick={ () => {
// Reload without query params for a blank post.
window.location.href =
window.location.pathname;
onClose();
} }
>
{ __(
'New Post',
'press-this'
) }
</MenuItem>
</>
) }
Comment on lines 195 to +202
function performSafeRedirect( url, inParentWindow = false ) {
const safeUrl = safeRedirect( url );

// In standalone mode there's no opener window, so always redirect self.
if ( isStandaloneMode() ) {
window.location.href = safeUrl;
return;
}
@kraftbj kraftbj added this to the 2.1.0 milestone Mar 16, 2026
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 7 out of 10 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +143 to +151
register_rest_route(
'press-this/v1',
'/manifest',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'press_this_rest_manifest',
'permission_callback' => '__return_true',
)
);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

press_this_register_rest_routes() uses WP_REST_Server::READABLE for the new /manifest route, but other routes in the same function use string literals (e.g., 'POST'). Please make the methods style consistent within this file (either use 'GET' here, or convert the other routes to WP_REST_Server constants).

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +109
// Detect standalone display mode (added to home screen).
const isStandalone = useMemo(
() =>
( typeof window.matchMedia === 'function' &&
window.matchMedia( '(display-mode: standalone)' ).matches ) ||
window.navigator.standalone === true,
[]
);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

Standalone-mode detection logic is duplicated in both Header and PressThisEditor (matchMedia (display-mode: standalone) + navigator.standalone). Consider extracting this into a shared utility so the detection stays consistent and future changes only need to be made in one place.

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +193
function isStandaloneMode() {
return (
( typeof window.matchMedia === 'function' &&
window.matchMedia( '(display-mode: standalone)' ).matches ) ||
window.navigator.standalone === true
);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

Standalone-mode detection logic is duplicated (also implemented in Header.js). Consider reusing a shared helper (e.g., in src/utils) so there’s a single source of truth for standalone detection.

Copilot uses AI. Check for mistakes.
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