package AmphetaDesk::OS::MacOSX; ############################################################################### # This package handles all the GUI routines for the MacOSX operating system. # # It requires various modules to be compiled into the runtime wrapper script # # - these modules are assumed to be there. If not, oopsy, we got problems. # # # # LIST OF ROUTINES BELOW: # # gui_init - start the gui and display the window. # # gui_listen - listen for window events for our gui. # # gui_note - send a note to our gui window. # # open_url - open a url in the system's default browser. # # _things - various routines that control the gui and should be private. # ############################################################################### use strict; use AmphetaDesk::Settings; use AmphetaDesk::Utilities; use Fcntl; require Exporter; use vars qw( @ISA @EXPORT ); @ISA = qw( Exporter ); @EXPORT = qw( gui_init gui_listen gui_note open_url ); # our event hooks. if we receive a request from the # OS X wrapper that matches one of these, then we call # the matching routine. note that our() is fine here # since OS X comes with Perl 5.6+ anyways. our %cmds = ( REFRESH => \&_gui_cmd_refresh ); ############################################################################### # gui_init - start the gui and display the window. # ############################################################################### # USAGE: # # gui_init; # # # # NOTES: # # This routine loads specific libraries specific to the OS and attempts to # # do everything necessary to start up a GUI window and start listening for # # events. Further down in this file, you should see supplementary GUI # # routines (starting with _) that are part of the GUI happenings this # # routine inits. # # # # RETURNS: # # 1; this routine always returns happily. # ############################################################################### sub gui_init { # set reading from STDIN to non-blocking. my $flags = 0; fcntl(STDIN, F_GETFL, $flags) or die "Couldn't get flags for STDIN : $!\n"; $flags |= O_NONBLOCK; fcntl(STDIN, F_SETFL, $flags) or die "Couldn't set flags for STDIN: $!\n"; return 1; } ############################################################################### # gui_listen - listen for window events for our gui. # ############################################################################### # USAGE: # # gui_listen; # # # # NOTES: # # This routine checks the event queue and sees if there is anything that # # needs to be done. It's called from the main loop of our program. # # # # RETURNS: # # 1; this routine always returns happily. # ############################################################################### sub gui_listen { my $lin; # set to non-blocking in gui_init(). if (defined ($lin=)) { # parse out the command prefix, keyword, and args chomp $lin; my ($prefix, $cmd, @args) = split(/ /, $lin); # only accept input with prefix 'CMD'. if the subroutine # for the CMD is found, we rush off to execution. if ((uc $prefix) eq 'CMD') { $cmds{uc $cmd}->() if (defined $cmds{uc $cmd}); } } return 1; } ############################################################################### # gui_note - send a note to our gui window. # ############################################################################### # USAGE: # # gui_note("This is a gui window line. Yup."); # # # # NOTES: # # Much like note(), only we send our message to our os specific gui window. # # # # RETURNS: # # 1; this routine always returns happily. # ############################################################################### sub gui_note { # eventually, this will do something a bit more meaningful. my ($message) = @_; print STDOUT $message . "\n"; return 1; } ############################################################################### # open_url - open a url in the system's default browser. # ############################################################################### # USAGE: # # open_url( ); # # # # OS SPECIFIC NOTES: # # Since it's nigh near impossible for us to figure out the default browser # # much less the path to said browser in MacOSX, we simply display a # # message telling the user what to do. # # # # # # RETURNS: # # 1; we instruct the user to open their browser if we can't. # ############################################################################### sub open_url { # construct our url. my $url = "http://127.0.0.1:" . get_setting("urls_port") . "/index.html"; # we spit out our suggestion just to catch all instances. note("GUI_CMD OPEN_URL $url", 1) if $ENV{DYLD_LIBRARY_PATH}; note("If your browser doesn't load, go to <$url>.", 1); return 1; } ############################################################################### # _things - various routines that control the gui and should be private. # ############################################################################### # USAGE: # # These are internally called by the GUI and shouldn't be publically # # used. So stop poking around here. Sheesh. Flippin' nosy people. Sigh. # ############################################################################### sub _gui_cmd_refresh { # helloooooooo, nurse! note("Refreshing the channel list...", 1); note("--------------------------------------------------------------------------------", 1); # do the dirty deed of download and open. my $url = "http://127.0.0.1:" . get_setting("urls_port") . "/index.html"; AmphetaDesk::MyChannels::download_my_channels(); note("GUI_CMD OPEN_URL $url", 1) if $ENV{DYLD_LIBRARY_PATH}; return 1; } 1;