-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy path03-progress-pulsate.php
48 lines (36 loc) · 1.09 KB
/
03-progress-pulsate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
use React\EventLoop\Loop;
require __DIR__ . '/../vendor/autoload.php';
$launcher = new Clue\React\Zenity\Launcher();
$builder = new Clue\React\Zenity\Builder();
$progress = $launcher->launchZen($builder->pulsate('Pseudo-processing...'));
$texts = array(
'Preparing',
'Downloading',
'Unpacking',
'Patching',
'Bootstrapping',
'Building',
'Cleaning',
'Finishing'
);
$timer = Loop::addPeriodicTimer(2.0, function ($timer) use ($progress, $texts) {
static $i = 0;
if (isset($texts[$i])) {
$text = $texts[$i++];
$text = '[' . $i . '/' . count($texts) . '] ' . $text . '...';
$progress->setText($text);
} else {
$progress->complete();
}
});
$progress->promise()->then(function () use ($timer, $builder, $launcher) {
$timer->cancel();
$launcher->launch($builder->info('Done'));
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
$progress->promise()->then(null, function() use ($timer, $builder, $launcher) {
$timer->cancel();
$launcher->launch($builder->error('Canceled'));
});