-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Experiment: Admin PWA #33102
Merged
Experiment: Admin PWA #33102
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8807607
Admin PWA
ellatrix 53e0e2e
Remove accidental change
ellatrix 0c9b67b
Fix loading in Chrome
ellatrix deb33fe
Add service worker (needed for Chrome)
ellatrix c6af99a
Fix Chrome PWA
ellatrix 6b84258
colored icons wip
ellatrix f6f274e
clean up
ellatrix 8d6c0a7
Clean up
ellatrix fb80dc1
Fix spaces in Chrome
ellatrix 19cb71a
Try to prioritise maskable icon
ellatrix 3a9e14e
Try 'maskable any'
ellatrix a112140
Fix sizes
ellatrix 5018965
Move script to package
ellatrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Progressive Web App | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
add_filter( | ||
'admin_head', | ||
function() { | ||
$icon_sizes = array( 32, 180, 192, 270, 512 ); | ||
|
||
// Ideally we have the WordPress logo as the default app logo in the sizes | ||
// below. | ||
$icons = array(); | ||
|
||
if ( has_site_icon() ) { | ||
$type = wp_check_filetype( get_site_icon_url() ); | ||
|
||
foreach ( $icon_sizes as $size ) { | ||
$icons[] = array( | ||
'src' => get_site_icon_url( $size ), | ||
'sizes' => $size . 'x' . $size, | ||
'type' => $type['type'], | ||
); | ||
} | ||
} | ||
|
||
$manifest = wp_json_encode( | ||
array( | ||
'name' => get_bloginfo( 'name' ), | ||
'icons' => $icons, | ||
'display' => 'standalone', | ||
'orientation' => 'portrait', | ||
'start_url' => admin_url(), | ||
// Open front-end, login page, and any external URLs in a browser modal. | ||
'scope' => admin_url(), | ||
) | ||
); | ||
|
||
// Must be at the admin root so the scope is correct. Move to the | ||
// wp-admin folder when merging with core. | ||
$service_worker_url = admin_url( '?service-worker' ); | ||
|
||
echo '<link rel="manifest" href=\'data:application/manifest+json,' . $manifest . '\'>'; | ||
echo '<script> | ||
if( "serviceWorker" in window.navigator ) { | ||
window.addEventListener( "load", function() { | ||
window.navigator.serviceWorker.register( "' . $service_worker_url . '" ); | ||
} ); | ||
} | ||
</script>'; | ||
} | ||
); | ||
|
||
add_filter( | ||
'load-index.php', | ||
function() { | ||
if ( ! isset( $_GET['service-worker'] ) ) { | ||
return; | ||
} | ||
|
||
header( 'Content-Type: text/javascript' ); | ||
echo file_get_contents( __DIR__ . '/service-worker.js' ); | ||
exit; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* global self */ | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting | ||
self.addEventListener( 'install', function ( event ) { | ||
event.waitUntil( self.skipWaiting() ); | ||
} ); | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/API/Clients/claim | ||
self.addEventListener( 'activate', function ( event ) { | ||
event.waitUntil( self.clients.claim() ); | ||
} ); | ||
|
||
// Necessary for Chrome to show the install button. | ||
self.addEventListener( 'fetch', function () {} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PWA plugin makes use of
admin-ajax.php
for serving the service worker which also works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we could do that too :)