-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebkit.pl
executable file
·70 lines (44 loc) · 1.2 KB
/
webkit.pl
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
=head1 NAME
webkit.pl - Embed a webkit widget in an application
=head1 SYNOPSIS
webkit.pl [OPTION]... [URI]
-h, --help print this help message
-u, --user-agent UA the user agent to use
Simple usage:
webkit.pl http://www.google.com/
=head1 DESCRIPTION
Display a web page.
=cut
use strict;
use warnings;
use Glib ':constants';
use Gtk3 -init;
use Gtk3::WebKit;
use Data::Dumper;
use Getopt::Long qw(:config auto_help);
use Pod::Usage;
sub main {
GetOptions(
'u|user-agent=s' => \my $user_agent,
) or pod2usage(1);
my ($url) = @ARGV;
$url ||= 'http://localhost:3001/';
my $window = Gtk3::Window->new('toplevel');
$window->set_default_size(800, 600);
$window->signal_connect(destroy => sub { Gtk3->main_quit() });
my $view = Gtk3::WebKit::WebView->new();
if ($user_agent) {
my $settings = $view->get_settings;
$settings->set('user-agent', $user_agent);
}
# Pack the widgets together
my $scrolls = Gtk3::ScrolledWindow->new();
$scrolls->add($view);
$window->add($scrolls);
$window->show_all();
$view->load_uri($url);
Gtk3->main;
return 0;
}
exit main() unless caller;