Ok, I'm optionally tacking a Server Power Control menu onto the web UI Extras menu via Slim::Web::Pages->addPageLinks. The page is a menu populated by an array constructed by the addPageFunction-ed sub which then passes it to the page in the params. So far, so good.
What I'm finding, though, is that after the 1st rendering of my page, my addPageFunction-ed sub never gets called again even if it has different items to render on the page.
E.G.:
User clicks on "Server Power Control" menu item on "Extras" menu. Server Power Control menu gets displayed. User clicks on "Home". User goes into the plugin settings and changes options which effect which items should show on the Server Power Control menu. User closes settings. User clicks on Server Power Control menu on Extras menu...but the changed settings aren't reflected on the displayed page. Checking the log shows that the page rendering sub wasn't called the 2nd time.
What should be the correct approach here? Is there a SC function I should call to force the re-rendering?
I've tried adding..
<meta http-equiv="Cache-Control" content="no-cache" />
..to the html in my page, but that doesn't do any good. This seems to be a SC cache issue, not a browser cache issue.
How do I force the page to be re-rendered by my function every time?
Results 1 to 10 of 11
-
2009-04-14, 15:02 #1
Slim::Web::HTTP::addPageFunction question..
-
2009-04-14, 17:49 #2Senior Member
- Join Date
- Oct 2005
- Posts
- 2,769
That's very odd. You're registering your URL in initPlugin() with code like this, passing a reference to the sub?
I've never seen anything like what you describe.Code:Slim::Web::HTTP::addPageFunction("plugins/SettingsManager/control.html", \&Plugins::SettingsManager::Web::handleWeb); # and hopefully adding CSRF protection with something like # the following, which protects any attempt to request the web function # with an SM_action param Slim::Web::HTTP::protect('plugins\/SettingsManager\/control\.htm\?.*\bSM_action\=');http://www.tux.org/~peterw/
Note: The best way to reach me is email or PM, as I don't spend time on the forums.
Free plugins: AllQuiet Auto Dim/AutoDisplay BlankSaver ContextMenu DenonSerial
FuzzyTime KidsPlay KitchenTimer PlayLog PowerCenter/BottleRocket SaverSwitcher
SettingsManager SleepFade StatusFirst SyncOptions VolumeLock
-
2009-04-14, 19:56 #3
Well, from initPlugin, I'm calling a function in another package that registers the url. The code called looks like this:
See anything obviously wrong there? This differs in some details from your example: I'm not escaping the "/"s in the URLs and I'm calling protectURI() rather than protect().Code:In Plugin.pm: sub initPlugin { my ($class) = @_; $class->SUPER::initPlugin(); ... # Tack our menu onto the SC WebUI home page Extras menu.. Plugins::SrvrPowerCtrl::WebUI->new($class); Plugins::SrvrPowerCtrl::WebUI::ActivateWebUI($g{prefs}->bInclude_WebInterface); } In WebUI.pm: my $plugin; # the main plugin class sub new { my $class = shift; $plugin = shift; $class->SUPER::new($plugin); } my $bWebUIIsActive = 0; sub ActivateWebUI { my $bEnable = shift; my $url = 'plugins/SrvrPowerCtrl/html/webui.html'; my $url1 = 'plugins/SrvrPowerCtrl/html/action.html'; my $url2 = 'plugins/SrvrPowerCtrl/html/actiondone.html'; my $url3 = 'plugins/SrvrPowerCtrl/html/actioncanceled.html'; if ($bEnable) { #Don't re-activate if already active.. if (!$bWebUIIsActive) { #Tack our menu onto the Extras menu.. Slim::Web::Pages->addPageLinks("plugins", { $plugin->getDisplayName() => $url }); Slim::Web::Pages->addPageLinks("icons", { $plugin->getDisplayName() => $plugin->_pluginDataFor('icon') }); Slim::Web::HTTP::addPageFunction($url, \&RenderWebUIMenu); Slim::Web::HTTP::protectURI($url); #add page handlers for the other pages.. Slim::Web::HTTP::addPageFunction($url1, \&RenderActionPage); Slim::Web::HTTP::protectURI($url1); Slim::Web::HTTP::addPageFunction($url2, \&RenderActionDonePage); Slim::Web::HTTP::protectURI($url2); Slim::Web::HTTP::addPageFunction($url3, \&RenderActionCanceledPage); Slim::Web::HTTP::protectURI($url3); $bWebUIIsActive = 1; } } else { if ($bWebUIIsActive) { #Kill our menu on the Extras menu.. Slim::Web::Pages->addPageLinks("plugins", { $plugin->getDisplayName() => undef }); $bWebUIIsActive = 0; } } $g{log}->debug("WebUI is " . (($bEnable && $bWebUIIsActive) ? "active" : "not active") . "!"); return ($bEnable && $bWebUIIsActive); } # Draws the plugin's web ui page off the extras menu.. sub RenderWebUIMenu { my ($client, $params) = @_; my @actions = (); $g{log}->debug("Called! params == $params"); #Plugins::SrvrPowerCtrl::Util::logHashElements($params); foreach my $item (@{$g{aActions}}) { if ($item->{menuindex} ge 0) { push (@actions, uc($item->{'action'})); } } $params->{actionlist} = \@actions; return Slim::Web::HTTP::filltemplatefile($params->{path}, $params); }
-
2009-04-15, 09:07 #4
Can anyone shed any light on this? This is really hanging me up.
-
2009-04-15, 09:09 #5Senior Member
- Join Date
- Oct 2005
- Location
- Ireland
- Posts
- 11,252
Can you attach the html ?
Are you sure the browser is forwarding the "GET" request - enable http logging to make sure.
-
2009-04-15, 14:25 #6
OK, here is the http for the "menu" file..which I based on the Digital Inputs plugin menu:
webui.html:
Code:[%- pagetitle = 'PLUGIN_SRVRPOWERCTRL_MODULE_NAME' | string %] [% pwd_list = BLOCK %] [% "PLUGIN_SRVRPOWERCTRL_MODULE_NAME" | string %] [% END %] [%- extJsScripts = BLOCK -%] <script type="text/javascript" src="[% webroot %]html/Browse.js?r=[% revision %]"></script> [%- END -%] [% PROCESS pageheader.html %] <div id="browsedbHeader"><br/>[% "PLUGIN_SRVRPOWERCTRL_MENU_CHOOSE_BELOW" | string %]<br/> </div> [% WRAPPER contentcontainer; odd = 1; %] [% FOREACH action = actionlist %] [% WRAPPER contentitem %] <a class="browseItemLink" href="[% webroot %]plugins/SrvrPowerCtrl/html/action.html?action=[% action | uri %]">[% 'PLUGIN_SRVRPOWERCTRL_SERVER_' _ action | string %]</a> [% END; odd = odd ? 0 : 1 -%] [%- END %] [% END %] [% PROCESS pagefooter.html %]
-
2009-04-15, 14:34 #7
One thing that I'm noticing is this:
Each time the SC home page is refreshed, the addPageFunction gets called four times for the Digital Inputs plugin's html files, a la:
Is addPageFunction something that must be continuously called? I.E. does the function referenced by addPageFunction get called only once and is then no longer associated with the web page? If so, how does the plugin "hook" the home page so that addPageFunction gets called appropriately?Code:[09-04-15 15:04:26.8353] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/list.html/ [09-04-15 15:04:26.8378] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/set.html/ [09-04-15 15:04:26.8413] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/LineIn/set.html/ ... [09-04-15 15:04:28.3975] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/list.html/ [09-04-15 15:04:28.4000] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/set.html/ [09-04-15 15:04:28.4035] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/LineIn/set.html/ ... [09-04-15 15:04:31.3606] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/list.html/ [09-04-15 15:04:31.3631] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/set.html/ [09-04-15 15:04:31.3666] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/LineIn/set.html/ ... [09-04-15 15:04:32.8688] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/list.html/ [09-04-15 15:04:32.8713] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/DigitalInput/set.html/ [09-04-15 15:04:32.8748] Slim::Web::HTTP::addPageFunction (2880) Adding handler for regular expression /plugins/LineIn/set.html/ ...
-
2009-04-15, 15:11 #8Senior Member
- Join Date
- Oct 2005
- Posts
- 2,769
http://www.tux.org/~peterw/
Note: The best way to reach me is email or PM, as I don't spend time on the forums.
Free plugins: AllQuiet Auto Dim/AutoDisplay BlankSaver ContextMenu DenonSerial
FuzzyTime KidsPlay KitchenTimer PlayLog PowerCenter/BottleRocket SaverSwitcher
SettingsManager SleepFade StatusFirst SyncOptions VolumeLock
-
2009-04-15, 19:34 #9
OK, I've made progress on this and it seems to be working now.
Lessons learned:
1). For whatever reason, addPageFunction seems to like it better when the referenced web pages are in:
/var/lib/squeezecenter/Plugins/SrvrPowerCtrl/HTML/EN/plugins/SrvrPowerCtrl
..rather than..
/var/lib/squeezecenter/Plugins/SrvrPowerCtrl/HTML/EN/plugins/SrvrPowerCtrl/html
This follows the example of the DigitalInput and the LineIn plugins, anyway.
2). addPageFunction takes a regex for the url value. I really needed to more carefully escape the whole url, including the ".". So, my main menu page needs to be expressed as:
my $url = 'plugins\/SrvrPowerCtrl\/webui[.]html';
..and since I'm passing parameters onto the other pages in the form of url?action=someaction, they need to be expressed, regex-wise, in this form:
my $url1 = 'plugins\/SrvrPowerCtrl\/action[.]html.*';
So...live and learn.
-
2009-04-15, 22:02 #10
Slim::Web::HTTP::addPageFunction question..
> /var/lib/squeezecenter/Plugins/SrvrPowerCtrl/HTML/EN/plugins/SrvrPowerCtrl
>
> ..rather than..
>
> /var/lib/squeezecenter/Plugins/SrvrPowerCtrl/HTML/EN/plugins/SrvrPowerCtrl/html
Might be due to the issue you mention below: /SrvrPowerCtrl.html/ would
match this path.
> my $url = 'plugins\/SrvrPowerCtrl\/webui[.]html';
Make this
my $url = 'plugins\/SrvrPowerCtrl\/webui\.html';
> ..and since I'm passing parameters onto the other pages in the form of
> url?action=someaction, they need to be expressed, regex-wise, in this
> form:
No, parameters should be taken into account automatically.
Michael

Reply With Quote

