XUL-Gui
view release on metacpan or search on metacpan
lib/XUL/Gui.pm view on Meta::CPAN
. qq{ http://localhost:$$self{port}};
$self->status('launching default browser' . ($DEBUG ? ": $cmd" : ''));
system $cmd and die $!;
return
}
unless (@firefox) {
find sub {push @firefox, [length, $File::Find::name]
if /^(:?firefox|iceweasel|xulrunner.*)(?:-bin|\.exe)?$/i and -f} => $_
for grep {/mozilla|firefox|iceweasel|xulrunner/i }
map {
if (opendir my $dir => my $path = $_)
{map "$path/$_" => readdir $dir} else {}
}
$^O =~ /MSWin/ ? @ENV{qw/ProgramFiles ProgramFiles(x86)/} :
$^O =~ /darwin/ ? '/Applications' :
split /[:;]/ => $ENV{PATH};
@firefox = sort {$$a[0] < $$b[0]} @firefox
}
if (@firefox) {
my $app;
for ($$self{trusted}) {
defined and !$_ or $_ =
`"$firefox[0][1]" -v 2>&1` =~
/ (?: firefox | iceweasel ) \s+ [34]
| xulrunner \s+ (?: 1\.[5-9] | 2\.[0-3] )
/ix
}
if ($$self{trusted}) {
local $@;
eval {
require File::Spec;
require File::Temp;
$$self{dir} = File::Temp->newdir('xulgui_XXXXXX', TMPDIR => 1);
$$self{dir}->unlink_on_destroy(0); # for threads
my $dirname = $$self{dir}->dirname;
my $base = (File::Spec->splitdir($dirname))[-1];
my ($file, $dir) = map {my $method = $_;
sub {File::Spec->$method( $dirname, split /\s+/ => "@_" )}
} qw( catfile catdir );
mkdir $dir->($_) or die $!
for qw(chrome defaults), "chrome $base", 'defaults preferences';
open my $manifest, '>', $file->('chrome chrome.manifest') or die $!;
print $manifest "content $base file:$base/";
open my $boot, '>', $file->('chrome', $base, 'boot.xul') or die $!; {
no warnings 'redefine';
local *write = sub {
my $self = shift;
my $code = pop;
$self->status("write \n\t". join "\n\t", split /\n/, $code) if $DEBUG > 3;
$code
};
print $boot $$self{dispatch}{'/'}();
}
open my $prefs, '>', $file->('defaults preferences prefs.js') or die $!;
print $prefs qq {pref("toolkit.defaultChromeURI", "chrome://$base/content/boot.xul");};
open my $ini, '>', $app = $file->('application.ini') or die $!;
print $ini split /[\t ]+/ => qq {
[App]
Name=$base
Version=$XUL::Gui::VERSION
BuildID=$base
[Gecko]
MinVersion=1.6
MaxVersion=2.3
};
$self->status("trusted: $app") if $DEBUG > 2;
1
} or do {
chomp (my $err = ($@ or $!));
$self->status("trusted mode failed: $err");
$$self{trusted} = 0;
undef $app;
}
} else {
while ($firefox[0][1] =~ /xulrunner[^\/\\]$/i) {
shift @firefox;
unless (@firefox) {
status {}, 'firefox not found: xulrunner was found but trusted mode is disabled';
return
}
}
}
my $firefox = $firefox[0][1];
$firefox =~ tr./.\\. if $^O =~ /MSWin/;
my $cmd = qq{"$firefox" }
. ($app
? "-app $app"
: ($$self{chrome} ? '-chrome ' : '')
. qq{"http://localhost:$$self{port}"}
) . (q{ 1>&2 2>/dev/null} x ($^O !~ /MSWin/));
if ($$self{launch}) {
$self->status('launching firefox' . ($DEBUG ? ": $cmd" : ''));
if (not $$self{trusted} and $^O =~ /darwin/) {
system qq[osascript -e 'tell application "Firefox" to OpenURL "http://localhost:$$self{port}"']
} else {
$$self{ffpid} = open $$self{firefox} => "$cmd |";
}
} else {
status {}, "launch gui with:\n\t$cmd"
}
}
else {status {}, 'firefox not found: start manually'}
}}
sub CLONE {
local $@;
eval {$$active{client}->close};
eval {$$active{server}->close};
}
BEGIN {*cleanup = \&CLONE}
END {
( run in 1.770 second using v1.01-cache-2.11-cpan-98e64b0badf )