Javascript Apple Dashboard小部件设置超时不工作
我正在开发一个基于日历的仪表板小部件,希望在新的一天开始时自动更新它。然而,我似乎无法让它真正更新。在浏览器中运行似乎效果不错。我也尝试过手动输入setTimeout延迟到更短的时间(比如1或2分钟),这似乎有效 这是我的代码:Javascript Apple Dashboard小部件设置超时不工作,javascript,widget,dashboard,Javascript,Widget,Dashboard,我正在开发一个基于日历的仪表板小部件,希望在新的一天开始时自动更新它。然而,我似乎无法让它真正更新。在浏览器中运行似乎效果不错。我也尝试过手动输入setTimeout延迟到更短的时间(比如1或2分钟),这似乎有效 这是我的代码: function Calendar() { var _self = this; this.daytimer = null; this.daytimerAction = function() { _self.updateCurre
function Calendar() {
var _self = this;
this.daytimer = null;
this.daytimerAction = function() {
_self.updateCurrentDate();
}
this.resetDaytimer();
}
Calendar.prototype.resetDaytimer = function() {
var today = new Date(),
tomorrow = new Date();
if (this.daytimer) {
clearTimeout(this.daytimer);
this.daytimer = null;
}
tomorrow.setDate(today.getDate() + 1);
tomorrow.setHours(0);
tomorrow.setMinutes(0);
tomorrow.setSeconds(1);
this.daytimer = setTimeout(this.daytimerAction, tomorrow.getTime() - today.getTime());
};
Calendar.prototype.updateCurrentDate = function() {
// Run code to update the day display
this.resetDaytimer();
};
有什么想法吗?我能想到的唯一一件事是,当dashboard不运行时,dashboard正在暂停/取消setTimeout。也许有一种方法可以在重新激活仪表板时重置超时?解决了这个问题。概述了可用于重新启动计时器以及直接调用updateCurrentDate()
的widget.onshow
事件。还有一个小部件.onhide
事件可用于暂停计时器