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

PWA manifest and new @ini_theme_color replacement #2241

Merged
merged 13 commits into from Apr 5, 2018
Merged

PWA manifest and new @ini_theme_color replacement #2241

merged 13 commits into from Apr 5, 2018

Conversation

micgro42
Copy link
Collaborator

@micgro42 micgro42 commented Jan 24, 2018

Hi,

this is another go at adding an app manifest to DokuWiki in order to provide PWA functionality.

It supports the config cascade and adds a new event MANIFEST_SEND.

  • I'm currently not entirely happy with how I select the default images. It is just a list of possible locations and I take the ones I can get.

  • Further, Google Lighthouse reports that we need an icon with at least 192px to support the automatic installer prompt and an icon of at least 512px for a custom splash screen.

  • Also, wep apps should have a theme color. I would like to take it from the style.ini. Should I use an existing one (which?) or create a new guranteed placeholder in the style.ini for this?

  • The general code structure could still be improved. Maybe move the Manifest class to inc/ and the jsonToArray() method to conutils.php?

replaces #2163
fixes #2156

@micgro42 micgro42 changed the title feat: provide web app manifest (dynamically geneated) provide dynamically geneated web app manifest Jan 24, 2018
This should have been part of the previous commit
5e0255e

Some simple static defaults for the PWA manifest
The goal is to make the css replacement accessible in other contexts,
for example for the manifest.
This also adds the default theme color for the DokuWiki template as the
green from the existing links.
@micgro42
Copy link
Collaborator Author

micgro42 commented Feb 1, 2018

I have extracted some functions from lib/exe/css.php, so we can use replacements in the manifest.

Further, I have added the green from the existing links (#008800) as DokuWiki's default theme color. Is that alright or should we choose a different color?

@micgro42 micgro42 changed the title provide dynamically geneated web app manifest PWA manifest and new @ini_theme_color replacement Feb 1, 2018
define('DOKU_INC', __DIR__ . '/../../');
}
require_once(DOKU_INC . 'inc/init.php');

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this check if the action is enabled before sending the manifest?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! I'll look into it. If it isn't enabled we send a 400?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be a 404 I'd say.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in ac6ceee

Copy link
Collaborator

@splitbrain splitbrain left a comment

Choose a reason for hiding this comment

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

I like this a lot already. I think the way images are added is still a bit weird. I don't know what formats are required but maybe we could start to use SVG only here? Eg. look for wiki:logo.svg, :logo.svg, wiki:dokuwiki.svg and use whichever we find first only.

inc/load.php Outdated
@@ -82,6 +82,7 @@ function load_autoload($name){
'RemoteAPI' => DOKU_INC.'inc/remote.php',
'RemoteAPICore' => DOKU_INC.'inc/RemoteAPICore.php',
'Subscription' => DOKU_INC.'inc/subscription.php',
'StyleUtil' => DOKU_INC.'inc/StyleUtil.php',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be needed because the file is namespaced and the autoloader should take care of this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also the class seems to be named StyleUtils?


if (!actionOK('manifest')) {
http_status(404, 'Manifest has been disabled in DokuWiki configuration.');
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

return in global scope feels weird. Should this be exit()?

}

trigger_error('JSON decoding error "' . $jsonErrorText . '" for file ' . $file, E_USER_WARNING);
return [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This error handling seems excessive. First of all it could probably be better handled with all the error codes in a lookup array (with the JSON* constants as the key).

Then I'm wondering about using trigger_error(). Have you tried what happens when you pass invalid json to json_decode()? I would assume that it already does trigger an error that would need to be supressed with @. When we do hande this ourselves I'd think an exception would be the better way?

inc/Manifest.php Outdated
':wiki:favicon.svg',
':favicon.svg',
'images/favicon.svg',
':wiki:favicon.ico',
Copy link
Collaborator

Choose a reason for hiding this comment

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

are .ico files supported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't read the spec yet, but MDN has them in their example: https://developer.mozilla.org/en-US/docs/Web/Manifest#icons

inc/Manifest.php Outdated
':favicon.ico',
'images/favicon.ico',
':wiki:logo',
];
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're basically adding all of these if we find them, right? It would be nice to fall back to the DokuWiki logo if none could be found.

inc/Manifest.php Outdated
$look = [
':wiki:logo.png',
':logo.png',
'images/logo.png',
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does this refer to? There is no images folder in dokuwiki. There might be one in the template but you wouldn't want that one if you already found one in wiki:logo.png?

@micgro42
Copy link
Collaborator Author

micgro42 commented Mar 6, 2018

@splitbrain I would like to limit the included icons to a small set of sensible defaults. The user has already many opportunities to overwrite these defaults.

The official spec https://www.w3.org/TR/2018/WD-appmanifest-20180222/#icons-member states explicitly that both .ico and .svg are valid and hints some use-cases. Do we have a SVG version of the DokuWiki logo?

@splitbrain
Copy link
Collaborator

Yes we have a SVG version (see https://www.dokuwiki.org/logo). We could include it next to the png version in the wiki namespace. We could also adjust the template to make use of it?

Defining SVG both as 17x17 and 512x512 is intended to support custom
splash screens, though the documentation is somewhat unclear. This
currently satisfies the Google Lighthouse auditing tool.
This color is for example shown in Chrome on Android as menu-bar
coloring.
Since StyleUtils has a namespace, it is already handled correctly by the
autoloader. This is further underlined by the fact that the removed line
isn't actually working because of the missing `s` in the classname.
This isn't really the best place for that error handling.
@micgro42 micgro42 merged commit 430a27b into master Apr 5, 2018
@micgro42 micgro42 deleted the manifest branch April 5, 2018 07:51
@micgro42 micgro42 mentioned this pull request Apr 5, 2018
4 tasks
micgro42 added a commit to cosmocode/dokuwiki-template-sprintdoc that referenced this pull request Apr 24, 2018
A recent DokuWiki merge request changed how the style.ini can be
accessed: dokuwiki/dokuwiki#2241
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.

Adding manifest.json to make it PWA ?
3 participants