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

Basic PWA support #4430

Merged
merged 15 commits into from
Oct 2, 2023
72 changes: 72 additions & 0 deletions app/App/PwaManifestBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace BookStack\App;

use BookStack\Http\Controller;

class PwaManifestBuilder extends Controller
{
private function GenerateManifest()
{
return [
"name" => setting('app-name'),
"short_name" => setting('app-name'),
"start_url" => "./",
"scope" => "/",
"display" => "standalone",
"background_color" => (setting()->getForCurrentUser('dark-mode-enabled') ? setting('app-color-dark') : setting('app-color')),
"description" => setting('app-name'),
"theme_color" => (setting()->getForCurrentUser('dark-mode-enabled') ? setting('app-color-dark') : setting('app-color')),
"launch_handler" => [
"client_mode" => "focus-existing"
],
"orientation" => "portrait",
"icons" => [
[
"src" => setting('app-icon-64') ?: url('/icon-64.png'),
"sizes" => "64x64",
"type" => "image/png"
],
[
"src" => setting('app-icon-32') ?: url('/icon-32.png'),
"sizes" => "32x32",
"type" => "image/png"
],
[
"src" => setting('app-icon-128') ?: url('/icon-128.png'),
"sizes" => "128x128",
"type" => "image/png"
],
[
"src" => setting('app-icon-180') ?: url('/icon-180.png'),
"sizes" => "180x180",
"type" => "image/png"
],
[
"src" => setting('app-icon') ?: url('/icon.png'),
"sizes" => "256x256",
"type" => "image/png"
],
[
"src" => public_path('icon.ico'),
"sizes" => "48x48",
"type" => "image/vnd.microsoft.icon"
],
[
"src" => public_path('favicon.ico'),
"sizes" => "48x48",
"type" => "image/vnd.microsoft.icon"
],
],
];
}

/**
* Serve the application manifest.
* Ensures a 'manifest.json'
*/
public function manifest()
{
return response()->json($this->GenerateManifest());
}
}
6 changes: 5 additions & 1 deletion resources/views/layouts/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class="{{ setting()->getForCurrentUser('dark-mode-enabled') ? 'dark-mode ' : ''
<meta name="viewport" content="width=device-width">
<meta name="token" content="{{ csrf_token() }}">
<meta name="base-url" content="{{ url('/') }}">
<meta name="theme-color" content="{{ setting('app-color') }}"/>
<meta name="theme-color" content="{{(setting()->getForCurrentUser('dark-mode-enabled') ? setting('app-color-dark') : setting('app-color'))}}"/>

<!-- Social Cards Meta -->
<meta property="og:title" content="{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name') }}">
Expand All @@ -29,6 +29,10 @@ class="{{ setting()->getForCurrentUser('dark-mode-enabled') ? 'dark-mode ' : ''
<link rel="icon" type="image/png" sizes="64x64" href="{{ setting('app-icon-64') ?: url('/icon-64.png') }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ setting('app-icon-32') ?: url('/icon-32.png') }}">

<!-- PWA -->
<link rel="manifest" href="{{ url('/manifest.json') }}" />
<meta name="mobile-web-app-capable" content="yes" />

@yield('head')

<!-- Custom Styles & Head Content -->
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use BookStack\Api\ApiDocsController;
use BookStack\Api\UserApiTokenController;
use BookStack\App\HomeController;
use BookStack\App\PwaManifestBuilder;
use BookStack\Entities\Controllers as EntityControllers;
use BookStack\Http\Middleware\VerifyCsrfToken;
use BookStack\Permissions\PermissionsController;
Expand All @@ -20,6 +21,7 @@
Route::get('/status', [SettingControllers\StatusController::class, 'show']);
Route::get('/robots.txt', [HomeController::class, 'robots']);
Route::get('/favicon.ico', [HomeController::class, 'favicon']);
Route::get('/manifest.json', [PwaManifestBuilder::class, 'manifest']);

// Authenticated routes...
Route::middleware('auth')->group(function () {
Expand Down