Add ready check back.
This commit is contained in:
parent
3b2552523a
commit
6fd82da2d9
4 changed files with 47 additions and 18 deletions
|
@ -4,4 +4,5 @@ use Misuzu\Controllers\HomeController;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Route::get('/', 'index', HomeController::class),
|
Route::get('/', 'index', HomeController::class),
|
||||||
|
Route::get('/is_ready', 'isReady', HomeController::class),
|
||||||
];
|
];
|
||||||
|
|
|
@ -58,21 +58,23 @@ class Application
|
||||||
throw new \Exception('Invalid property.');
|
throw new \Exception('Invalid property.');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function __construct($config = null)
|
protected function __construct($configFile = null)
|
||||||
{
|
{
|
||||||
ExceptionHandler::register();
|
ExceptionHandler::register();
|
||||||
|
|
||||||
$this->addModule('router', new RouteCollection);
|
$this->addModule('router', $router = new RouteCollection);
|
||||||
$this->addModule('templating', new TemplateEngine);
|
$this->addModule('templating', $twig = new TemplateEngine);
|
||||||
$this->addModule('config', new ConfigManager($config));
|
$this->addModule('config', $config = new ConfigManager($configFile));
|
||||||
|
|
||||||
$this->templating->addFilter('json_decode');
|
$twig->addFilter('json_decode');
|
||||||
$this->templating->addFilter('byte_symbol');
|
$twig->addFilter('byte_symbol');
|
||||||
$this->templating->addFunction('byte_symbol');
|
$twig->addFunction('byte_symbol');
|
||||||
$this->templating->addFunction('session_id');
|
$twig->addFunction('session_id');
|
||||||
$this->templating->addFunction('config', [$this->config, 'get']);
|
$twig->addFunction('config', [$config, 'get']);
|
||||||
$this->templating->addFunction('route', [$this->router, 'url']);
|
$twig->addFunction('route', [$router, 'url']);
|
||||||
$this->templating->addPath('nova', __DIR__ . '/../views/nova');
|
$twig->addFunction('git_hash', [Application::class, 'gitCommitHash']);
|
||||||
|
$twig->addFunction('git_branch', [Application::class, 'gitBranch']);
|
||||||
|
$twig->addPath('nova', __DIR__ . '/../views/nova');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
|
|
|
@ -9,9 +9,11 @@ class HomeController extends Controller
|
||||||
{
|
{
|
||||||
$twig = Application::getInstance()->templating;
|
$twig = Application::getInstance()->templating;
|
||||||
|
|
||||||
$twig->addFunction('git_hash', [Application::class, 'gitCommitHash']);
|
|
||||||
$twig->addFunction('git_branch', [Application::class, 'gitBranch']);
|
|
||||||
|
|
||||||
return $twig->render('home.landing');
|
return $twig->render('home.landing');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isReady(): string
|
||||||
|
{
|
||||||
|
return 'no';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,10 @@
|
||||||
countdownFlashingTicks = 0,
|
countdownFlashingTicks = 0,
|
||||||
countdownLastString = '',
|
countdownLastString = '',
|
||||||
countdownFinish,
|
countdownFinish,
|
||||||
countdownIgnoreHidden = false;
|
countdownIgnoreHidden = false,
|
||||||
|
continueChecking = true,
|
||||||
|
checkClient = null,
|
||||||
|
checkTimeout;
|
||||||
|
|
||||||
function countdownSetup(container, target, finish) {
|
function countdownSetup(container, target, finish) {
|
||||||
countdownFinish = finish || null;
|
countdownFinish = finish || null;
|
||||||
|
@ -170,11 +173,32 @@
|
||||||
countdownDigits[i].setAttribute('data-digit', str[i]);
|
countdownDigits[i].setAttribute('data-digit', str[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = function () {
|
function checkIfFlashiiReady(continuous) {
|
||||||
|
continueChecking = !(!continuous);
|
||||||
|
|
||||||
|
if (checkClient === null) {
|
||||||
|
checkClient = new XMLHttpRequest();
|
||||||
|
|
||||||
|
checkClient.addEventListener('readystatechange', function () {
|
||||||
|
if (checkClient.readyState === 4 && (checkClient.status !== 200 || checkClient.responseText !== 'no'))
|
||||||
|
location.reload(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
checkClient.open('GET', '/is_ready?' + Date.now(), true);
|
||||||
|
checkClient.send();
|
||||||
|
|
||||||
|
if (continueChecking)
|
||||||
|
checkTimeout = setTimeout(function () { checkIfFlashiiReady(continueChecking); }, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function () {
|
||||||
var container = document.createElement('div');
|
var container = document.createElement('div');
|
||||||
container.className = 'countdown-container';
|
container.className = 'countdown-container';
|
||||||
document.getElementById('countdown').appendChild(container);
|
document.getElementById('countdown').appendChild(container);
|
||||||
countdownSetup(container, new Date("Mon, 1 27 2018 1:00:00 +0100"));
|
countdownSetup(container, new Date("Mon, 1 27 2018 1:00:00 +0100"), function () {
|
||||||
}
|
checkIfFlashiiReady(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue