Okay so it think this is working now. It now shos up in the plugins
list. I've made a few changes, but I think the main fix required was as
"Use" statement at the top of the module.

I'm not sure if the sub enabled & sub getFunctions are required.



package Plugins::PreventStandby::Plugin;

# $Id: Plugin.pm 6838 2006-04-06 18:19:53Z dsully $

# PreventStandby.pm by Julian Neil ([EMAIL PROTECTED])
#
# Prevent the server machine from going into standby when it is
streaming
# music to any clients.  Only works in Windows because it uses the
CPAN
# Win32:API module.
#
# Excuse my perl.. first time I've ever used it.
#
# Thanks to the PowerSave plugin by Jason Holtzapplefor some basics,
# to various ppl on the slim forums and to CPAN and the Win32::API
module.
#
#-> Changelog
#
# 1.0 - 2006-04-05 - Initial Release

use strict;
use Slim::Utils::Misc;
use Slim::Utils::OSDetect;
use Win32::API;

# how many seconds between checks for playing clients
my $interval = 60;

# keep the timer so we can kill it if we want
my $timer = undef;

# reference to the windows function of same name
my $SetThreadExecutionState = undef;

sub getDisplayName {
        return 'PLUGIN_PREVENTSTANDBY';
}

sub enabled {
        return ($::VERSION ge '6.1');
}

sub getFunctions {
        return '';
}

sub checkClientActivity {

        $timer = undef;

        for my $client (Slim::Player::Client::clients()) {

                my $playmode = $client->playmode();

                $::d_plugins && msgf("Prevent Standby plugin: client %s in 
playmode
%s\n", $client->name, $playmode);

                if ($playmode ne 'stop' && $playmode ne 'pause') {

                        $::d_plugins && msg("Prevent Standby plugin: setting 
thread
execution state\n");

                        if (defined $SetThreadExecutionState) {
                                $SetThreadExecutionState->Call(1);
                        }

                        startTimer();

                        return 1;
                }
        }

        startTimer();

        return 0;
}

sub startTimer {

$::d_plugins && msg("Prevent Standby plugin: startTimer
called\n");
        if (!defined $timer && defined $SetThreadExecutionState) {

                $::d_plugins && msg("Prevent Standby plugin: starting timer\n");

                $timer = Slim::Utils::Timers::setTimer(0, time + $interval,
\&checkClientActivity);

                $::d_plugins && !defined($timer) && msg("Prevent Standby plugin:
starting timer failed\n");
        }

        return defined($timer);
}

sub stopTimer {

        if (defined($timer)) {

                Slim::Utils::Timers::killSpecific($timer);
                $timer = undef;
        }
}

sub initPlugin {
$::d_plugins && msg("Initialising Prevent Standby plugin: Only
available under Windows\n");
        if (Slim::Utils::OSDetect::OS() eq 'win') {

                $SetThreadExecutionState = Win32::API->new('kernel32',
'SetThreadExecutionState', 'N', 'N');

                return startTimer();
        }

        $::d_plugins && msg("Prevent Standby plugin: Only available under
Windows\n");
}

sub shutdownPlugin {
        stopTimer();
}

sub strings { return '
PLUGIN_PREVENTSTANDBY
        EN      Windows: Prevent System Standby While Playing
'};

1;

__END__


-- 
oreillymj
------------------------------------------------------------------------
oreillymj's Profile: http://forums.slimdevices.com/member.php?userid=699
View this thread: http://forums.slimdevices.com/showthread.php?t=22785

_______________________________________________
beta mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/beta

Reply via email to