You want to give users of your Klip the ability to choose a refresh rate, rather than locking the Klip to one fixed refresh rate.
Setup.addTab ("Refresh Rate");
c_refresh_rate = Setup[0].addComboBox("Every 15 minutes", "Every 30 minutes", "Every hour");
c_refresh_rate.onChange = fn_refresh_rate_onChange;
c_refresh_rate.selected = ((p = Prefs.getPref("refresh_rate")) != false ? Number(p) : 1);
The first line above adds a new tab to the Klip's setup window called "Refresh Rate". The second line creates a combobox on the leftmost tab, specified by Setup[0] (this is the tab we just created). The third line specifies an event handler for when the user changes the combobox, which we will define shortly.
The fourth line takes care of loading a stored preference, so that the combobox will not reset to its default value every time KlipFolio starts. The combobox selection is set to either the preference that is stored, or if no preference is stored "1" is used, which in this case defaults to "Every half hour" (the combobox items are numbered in sequential order starting at zero).
The only thing left to do is define the combobox event handler:
function fn_refresh_rate_onChange(index)
{
Prefs.setPref("refresh_rate", "" + (c_refresh_rate.selected));
setRefreshRate()
}
function setRefreshRate()
{
switch (c_refresh_rate.selected)
{
case 0: Prefs.refreshrate = 5; break;
case 1: Prefs.refreshrate = 30; break;
case 2: Prefs.refreshrate = 60; break;
}
}
The combobox event handler saves the preference, then calls the SetRefreshRate() function. SetRefreshRate() uses the combobox selection value to determine which refresh rate to use. The Prefs.refreshrate value is measured in minutes.
The SetRefreshRate() function is separate from the combobox event handler because SetRefreshRate() should also be called at the end of the onLoad() function to set the initial refresh rate to the user's preference.