| 1 | package App::SD::Server; | ||
| 2 | use Any::Moose; | ||
| 3 | extends 'Prophet::Server'; | ||
| 4 | |||
| 5 | has with_browser => ( | ||
| 6 | isa => 'Bool', | ||
| 7 | is => 'rw', | ||
| 8 | default => 0, | ||
| 9 | ); | ||
| 10 | |||
| 11 | =head2 database_bonjour_name | ||
| 12 | |||
| 13 | Returns the name this database should use to announce itself via bonjour | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | sub database_bonjour_name { | ||
| 18 | my $self = shift; | ||
| 19 | my $name = $self->app_handle->setting( label => 'project_name' )->get->[0]; | ||
| 20 | my $uuid = $self->handle->db_uuid; | ||
| 21 | return "$name ($uuid)"; | ||
| 22 | |||
| 23 | } | ||
| 24 | |||
| 25 | |||
| 26 | sub css { | ||
| 27 | return shift->SUPER::css(@_), "/static/sd/css/main.css"; | ||
| 28 | } | ||
| 29 | |||
| 30 | sub js { | ||
| 31 | return shift->SUPER::js(@_); | ||
| 32 | } | ||
| 33 | |||
| 34 | # open up a browser after the server has been started (basically a | ||
| 35 | # hook for the browser command) | ||
| 36 | sub after_setup_listener { | ||
| 37 | my $self = shift; | ||
| 38 | |||
| 39 | local $SIG{CHLD}; # allow browser to be run with system() | ||
| 40 | |||
| 41 | if ( $self->with_browser ) { | ||
| 42 | $self->open_browser( url => 'http://localhost:' . $self->port ); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | sub open_browser { | ||
| 47 | my $self = shift; | ||
| 48 | my %args = (@_); | ||
| 49 | my $opener = $self->open_url_cmd; | ||
| 50 | |||
| 51 | if (!$opener) { | ||
| 52 | warn "I'm unable to figure out what browser I should open for you.\n"; | ||
| 53 | return; | ||
| 54 | } | ||
| 55 | |||
| 56 | system($opener, $args{url}) && die "Couldn't run $opener: $!"; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub open_url_cmd { | ||
| 60 | my $self = shift; | ||
| 61 | |||
| 62 | if ( $^O eq 'darwin' ) { | ||
| 63 | return 'open'; | ||
| 64 | } | ||
| 65 | elsif ( $^O eq 'MSWin32' ) { | ||
| 66 | return 'start'; | ||
| 67 | } | ||
| 68 | |||
| 69 | for my $cmd (qw|x-www-browser htmlview | ||
| 70 | gnome-open gnome-moz-remote | ||
| 71 | firefox iceweasel opera www-browser w3m lynx|) { | ||
| 72 | my $cmd_path = `which $cmd`; | ||
| 73 | chomp($cmd_path); | ||
| 74 | if ( $cmd_path && -f $cmd_path && -x _ ) { | ||
| 75 | return $cmd_path; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | no Any::Moose; | ||
| 81 | 1; | ||
| 82 |