Chandra
view release on metacpan or search on metacpan
examples/splash_example.pl view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../blib/lib", "$FindBin::Bin/../blib/arch";
use Chandra;
use Chandra::App;
use Chandra::Splash;
# We need a Chandra instance to bootstrap NSApplication and pump the
# macOS event loop so child windows (splash screens) actually render.
my $app = Chandra::App->new(
title => 'Splash Demo',
width => 1,
height => 1,
);
# Init the underlying webview â this bootstraps NSApplication
# (setActivationPolicy, finishLaunching, etc.) which is required
# before any child windows will display.
my $wv = $app->webview;
$wv->init;
# Non-blocking event loop pump â call repeatedly to keep GUI alive
sub pump { $wv->loop(0) for 1..5 }
# Pump + sleep helper
sub pump_sleep {
my ($secs) = @_;
my $end = time + $secs;
while (time < $end) {
pump();
select(undef, undef, undef, 0.02);
}
}
print <<'BANNER';
===========================================
Chandra::Splash â Interactive Demo
===========================================
Commands:
progress â Progress bar + status updates
custom â Custom HTML content
frameless â Frameless splash window
timeout â Auto-close after 2 seconds
app â $app->splash() convenience wrapper
quit â Exit
BANNER
# Helper: show splash, pump events, wait for a key, close
sub show_and_wait {
my ($s, $msg) = @_;
$s->show;
pump();
print " $msg\n" if $msg;
# Pump while waiting for input
require IO::Select;
my $sel = IO::Select->new(\*STDIN);
while (1) {
pump();
last if $sel->can_read(0.05);
}
my $discard = <STDIN>;
$s->close;
pump();
print " Closed.\n";
}
while (1) {
print "> ";
pump();
# Non-blocking stdin read with event loop pumping
require IO::Select;
my $sel = IO::Select->new(\*STDIN);
while (!$sel->can_read(0.05)) { pump(); }
my $cmd = <STDIN>;
last unless defined $cmd;
chomp $cmd;
$cmd =~ s/^\s+|\s+$//g;
last if $cmd eq 'quit' || $cmd eq 'q' || $cmd eq 'exit';
if ($cmd eq 'progress') {
( run in 0.706 second using v1.01-cache-2.11-cpan-39bf76dae61 )