WIP PWA support
This commit is contained in:
parent
c925ca2a41
commit
cba59e66c7
4
app.json
4
app.json
|
@ -20,6 +20,10 @@
|
||||||
"description": "Latte cache path",
|
"description": "Latte cache path",
|
||||||
"value": "/tmp/latte"
|
"value": "/tmp/latte"
|
||||||
},
|
},
|
||||||
|
"API_SIGNER": {
|
||||||
|
"description": "Signer method",
|
||||||
|
"value": "remote"
|
||||||
|
},
|
||||||
"API_SIGNER_URL": {
|
"API_SIGNER_URL": {
|
||||||
"description": "Remote signer url",
|
"description": "Remote signer url",
|
||||||
"value": "https://signtok.vercel.app/api"
|
"value": "https://signtok.vercel.app/api"
|
||||||
|
|
|
@ -19,6 +19,7 @@ class SettingsController {
|
||||||
}
|
}
|
||||||
self::redirect();
|
self::redirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function api() {
|
static public function api() {
|
||||||
// TODO, ADD COUNT
|
// TODO, ADD COUNT
|
||||||
if (isset($_POST['api-test_endpoints'])) {
|
if (isset($_POST['api-test_endpoints'])) {
|
||||||
|
@ -33,6 +34,14 @@ class SettingsController {
|
||||||
self::redirect();
|
self::redirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function misc() {
|
||||||
|
if (isset($_POST['misc-sw'])) {
|
||||||
|
$sw = $_POST['misc-sw'];
|
||||||
|
Cookies::set("misc-sw", $sw);
|
||||||
|
}
|
||||||
|
self::redirect();
|
||||||
|
}
|
||||||
|
|
||||||
static private function redirect() {
|
static private function redirect() {
|
||||||
$url = Misc::url('/settings');
|
$url = Misc::url('/settings');
|
||||||
header("Location: {$url}");
|
header("Location: {$url}");
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
/**
|
|
||||||
* Base for templates with a feed
|
|
||||||
*/
|
|
||||||
class RSSTemplate {
|
class RSSTemplate {
|
||||||
public string $title;
|
public string $title;
|
||||||
public string $desc;
|
public string $desc;
|
||||||
|
|
|
@ -6,14 +6,15 @@ use App\Helpers\Cookies;
|
||||||
use TikScraper\Constants\DownloadMethods;
|
use TikScraper\Constants\DownloadMethods;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base for templates with a feed
|
* Settings model with all possible config items
|
||||||
*/
|
*/
|
||||||
class SettingsTemplate extends BaseTemplate {
|
class SettingsTemplate extends BaseTemplate {
|
||||||
public array $downloaders = [];
|
public array $downloaders = [];
|
||||||
public array $themes = [];
|
public array $themes = [];
|
||||||
public bool $isTestEndpoints = false;
|
public bool $isTestEndpoints = false;
|
||||||
public string $currentDownloader;
|
public string $currentDownloader;
|
||||||
public string $currentTheme;
|
public string $currentTheme;
|
||||||
|
public bool $isServiceWorker = false;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct("Settings");
|
parent::__construct("Settings");
|
||||||
|
@ -27,5 +28,6 @@ class SettingsTemplate extends BaseTemplate {
|
||||||
$this->isTestEndpoints = Cookies::check('api-test_endpoints', 'yes');
|
$this->isTestEndpoints = Cookies::check('api-test_endpoints', 'yes');
|
||||||
$this->currentDownloader = Cookies::downloader();
|
$this->currentDownloader = Cookies::downloader();
|
||||||
$this->currentTheme = Cookies::theme();
|
$this->currentTheme = Cookies::theme();
|
||||||
|
$this->isServiceWorker = Cookies::check('misc-sw', 'yes');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="{path('/favicon-32x32.png')}">
|
<link rel="icon" type="image/png" sizes="32x32" href="{path('/favicon-32x32.png')}">
|
||||||
<link rel="icon" type="image/png" sizes="16x16" href="{path('/favicon-16x16.png')}">
|
<link rel="icon" type="image/png" sizes="16x16" href="{path('/favicon-16x16.png')}">
|
||||||
<link rel="manifest" href="{path('/site.webmanifest')}">
|
<link rel="manifest" href="{path('/site.webmanifest')}">
|
||||||
<meta property="og:title" content="ProxiTok" />
|
<meta property="og:site_name" content="ProxiTok" />
|
||||||
|
<meta property="og:title" content="{$title}" />
|
||||||
<meta property="og:description" content="Alternative frontend for TikTok" />
|
<meta property="og:description" content="Alternative frontend for TikTok" />
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
{if isset($has_rss)}
|
{if isset($has_rss)}
|
||||||
|
@ -15,4 +16,8 @@
|
||||||
<link rel="stylesheet" href="{path('/styles/vendor/cssgg.min.css')}">
|
<link rel="stylesheet" href="{path('/styles/vendor/cssgg.min.css')}">
|
||||||
<link rel="stylesheet" href="{path('/styles/vendor/bulma.min.css')}">
|
<link rel="stylesheet" href="{path('/styles/vendor/bulma.min.css')}">
|
||||||
<title>{$title} - ProxiTok</title>
|
<title>{$title} - ProxiTok</title>
|
||||||
|
{*/ Handles optional Service Worker /*}
|
||||||
|
{if \App\Helpers\Cookies::check('misc-sw', 'yes')}
|
||||||
|
<script src="{path('/scripts/setup_sw.js')}"></script>
|
||||||
|
{/if}
|
||||||
</head>
|
</head>
|
||||||
|
|
18
components/settings/misc.latte
Normal file
18
components/settings/misc.latte
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{embed '../form.latte', path: '/settings/misc', method: 'POST', submit: true}
|
||||||
|
{block fields}
|
||||||
|
<div class="field">
|
||||||
|
<label class="label">Enable service worker</label>
|
||||||
|
<div class="control">
|
||||||
|
<label class="radio">
|
||||||
|
<input type="radio" name="misc-sw" value="yes" n:attr="checked => $isServiceWorker" />
|
||||||
|
<span>Yes</span>
|
||||||
|
</label>
|
||||||
|
<label class="radio">
|
||||||
|
<input type="radio" name="misc-sw" value="no" n:attr="checked => !$isServiceWorker" />
|
||||||
|
<span>No</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<p class="help">This can be used to install the PWA version of ProxiTok</p>
|
||||||
|
</div>
|
||||||
|
{/block}
|
||||||
|
{/embed}
|
3
components/sw.latte
Normal file
3
components/sw.latte
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{if \App\Helpers\Cookies::check('misc-sw', 'yes')}
|
||||||
|
<script src="{path('/scripts/setup_sw.js')}"></script>
|
||||||
|
{/if}
|
|
@ -57,6 +57,7 @@ $router->mount('/settings', function () use ($router) {
|
||||||
$router->get('/', 'SettingsController@index');
|
$router->get('/', 'SettingsController@index');
|
||||||
$router->post('/general', 'SettingsController@general');
|
$router->post('/general', 'SettingsController@general');
|
||||||
$router->post('/api', 'SettingsController@api');
|
$router->post('/api', 'SettingsController@api');
|
||||||
|
$router->post('/misc', 'SettingsController@misc');
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->get('/discover', 'DiscoverController@get');
|
$router->get('/discover', 'DiscoverController@get');
|
||||||
|
|
9
scripts/setup_sw.js
Normal file
9
scripts/setup_sw.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
if (navigator.serviceWorker) {
|
||||||
|
navigator.serviceWorker.register('/sw.js').then(function (reg) {
|
||||||
|
console.log('Service worker registration was successful, scope: ', reg.scope);
|
||||||
|
}).catch(function (error) {
|
||||||
|
console.log('Service worker failed:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
17
sw.js
Normal file
17
sw.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
const PWA_PRELOAD = {
|
||||||
|
pages: ['/', '/about', '/settings'],
|
||||||
|
scripts: ['/scripts/navbar.js', '/scripts/themes/card.js'],
|
||||||
|
styles: ['/styles/bulma.min.css', '/styles/cssgg.min.css', '/styles/themes/card.css']
|
||||||
|
}
|
||||||
|
|
||||||
|
self.addEventListener("install", function(e) {
|
||||||
|
e.waitUntil(
|
||||||
|
caches.open("pwa").then(function(cache) {
|
||||||
|
return cache.addAll([
|
||||||
|
...PWA_PRELOAD.pages,
|
||||||
|
...PWA_PRELOAD.scripts,
|
||||||
|
...PWA_PRELOAD.styles
|
||||||
|
]);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
|
@ -5,9 +5,18 @@
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
{block content}
|
{block content}
|
||||||
<p class="title">General</p>
|
<div class="content">
|
||||||
{include '../components/settings/general.latte'}
|
<p class="title">General</p>
|
||||||
|
{include '../components/settings/general.latte'}
|
||||||
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<p class="title">Api</p>
|
<div class="content">
|
||||||
{include '../components/settings/api.latte'}
|
<p class="title">Api</p>
|
||||||
|
{include '../components/settings/api.latte'}
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<div class="content">
|
||||||
|
<p class="title">Misc</p>
|
||||||
|
{include '../components/settings/misc.latte'}
|
||||||
|
</div>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
Loading…
Reference in a new issue