Created
December 13, 2016 22:59
-
-
Save dniku/a1fe72db22d60615083f0320b2e47e8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Gtk2 '-init'; | |
use Gtk2::Unique; | |
my $window = Gtk2::Window->new('toplevel'); | |
my $app = Gtk2::UniqueApp->new( | |
"org.shit-got-loose", undef, | |
select => 1, | |
nothing => 2, | |
); | |
if ( $app->is_running ) { | |
my $cmdid = 1; | |
my $text = "hello world"; | |
print "Sending $cmdid, text => $text\n"; | |
$app->send_message( $cmdid, text => $text ); | |
} | |
else { | |
$app->watch_window($window); | |
my $app_watch_id = $app->signal_connect( | |
'message-received' => sub { | |
my ( $app, $cmd, $message, $time ) = @_; | |
print "Received IPC command: $cmd\n"; | |
print "Message: $message\n"; | |
if (defined $message->get) { | |
print "defined!\n"; | |
} | |
else { | |
print "undefined :(\n"; | |
} | |
if ( defined $cmd ) { | |
if ( $cmd eq 'select' ) { | |
print "received select\n"; | |
print "text: "; | |
my $text = $message->get_text; # kaboom | |
print $text . "\n"; | |
} | |
elsif ( $cmd eq 'nothing' ) { | |
print "received nothing\n"; | |
print "text: "; | |
my $text = $message->get_text; # kaboom | |
print $text . "\n"; | |
} | |
} | |
return 'ok'; | |
} | |
); | |
Gtk2->main; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment