From 1dfe6e3b8f027e7697f775fad9efbe479748a842 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Wed, 25 Sep 2019 03:45:20 +0900 Subject: [PATCH] =?utf8?q?TimelineScheduler=E3=81=A7=E8=87=AA=E5=8B=95?= =?utf8?q?=E6=9B=B4=E6=96=B0=E3=81=AE=E7=84=A1=E5=8A=B9=E5=8C=96=E3=81=8C?= =?utf8?q?=E8=80=83=E6=85=AE=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA?= =?utf8?q?=E3=81=84=E4=B8=8D=E5=85=B7=E5=90=88=E3=82=92=E4=BF=AE=E6=AD=A3?= =?utf8?q?=20(thx=20@kamemory!)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: c8b60400 ("タイムラインの定期更新に使用するタイマーの間隔を動的に制御する") --- OpenTween/Resources/ChangeLog.txt | 1 + OpenTween/TimelineScheduler.cs | 153 +++++++++++++++++++++++++++----------- OpenTween/Tween.cs | 15 ++-- 3 files changed, 121 insertions(+), 48 deletions(-) diff --git a/OpenTween/Resources/ChangeLog.txt b/OpenTween/Resources/ChangeLog.txt index 3633b421..a7b98aa3 100644 --- a/OpenTween/Resources/ChangeLog.txt +++ b/OpenTween/Resources/ChangeLog.txt @@ -3,6 +3,7 @@ ==== Ver 2.4.1-dev(2019/xx/xx) * FIX: 「タブを一覧の下に表示する」を無効にすると起動時にエラーが発生する不具合を修正 (thx @mulsys!) * FIX: 発言一覧の選択状態が正しく描画されない不具合を修正 + * FIX: 更新間隔を0秒に設定した場合に自動更新が停止されない不具合を修正 (thx @kamemory!) ==== Ver 2.4.0(2019/09/24) * NEW: Twemoji 12.0.0 に対応しました diff --git a/OpenTween/TimelineScheduler.cs b/OpenTween/TimelineScheduler.cs index 434d1518..8dcc1663 100644 --- a/OpenTween/TimelineScheduler.cs +++ b/OpenTween/TimelineScheduler.cs @@ -78,6 +78,30 @@ namespace OpenTween public TimeSpan UpdateIntervalConfig { get; set; } = Timeout.InfiniteTimeSpan; public TimeSpan UpdateAfterSystemResume { get; set; } = Timeout.InfiniteTimeSpan; + public bool EnableUpdateHome + => this.UpdateIntervalHome != Timeout.InfiniteTimeSpan; + + public bool EnableUpdateMention + => this.UpdateIntervalMention != Timeout.InfiniteTimeSpan; + + public bool EnableUpdateDm + => this.UpdateIntervalDm != Timeout.InfiniteTimeSpan; + + public bool EnableUpdatePublicSearch + => this.UpdateIntervalPublicSearch != Timeout.InfiniteTimeSpan; + + public bool EnableUpdateUser + => this.UpdateIntervalUser != Timeout.InfiniteTimeSpan; + + public bool EnableUpdateList + => this.UpdateIntervalList != Timeout.InfiniteTimeSpan; + + public bool EnableUpdateConfig + => this.UpdateIntervalConfig != Timeout.InfiniteTimeSpan; + + public bool EnableUpdateSystemResume + => this.UpdateAfterSystemResume != Timeout.InfiniteTimeSpan; + public Func? UpdateHome; public Func? UpdateMention; public Func? UpdateDm; @@ -116,6 +140,9 @@ namespace OpenTween public void SystemResumed() { + if (!this.EnableUpdateSystemResume) + return; + this.SystemResumedAt = DateTimeUtc.Now; this.systemResumeMode = true; this.RefreshSchedule(); @@ -145,33 +172,54 @@ namespace OpenTween var round = TimeSpan.FromSeconds(1); // 1秒未満の差異であればまとめて実行する var tasks = UpdateTask.None; - var nextScheduledHome = this.LastUpdateHome + this.UpdateIntervalHome; - if (nextScheduledHome - now < round) - tasks |= UpdateTask.Home; + if (this.EnableUpdateHome) + { + var nextScheduledHome = this.LastUpdateHome + this.UpdateIntervalHome; + if (nextScheduledHome - now < round) + tasks |= UpdateTask.Home; + } - var nextScheduledMention = this.LastUpdateMention + this.UpdateIntervalMention; - if (nextScheduledMention - now < round) - tasks |= UpdateTask.Mention; + if (this.EnableUpdateMention) + { + var nextScheduledMention = this.LastUpdateMention + this.UpdateIntervalMention; + if (nextScheduledMention - now < round) + tasks |= UpdateTask.Mention; + } - var nextScheduledDm = this.LastUpdateDm + this.UpdateIntervalDm; - if (nextScheduledDm - now < round) - tasks |= UpdateTask.Dm; + if (this.EnableUpdateDm) + { + var nextScheduledDm = this.LastUpdateDm + this.UpdateIntervalDm; + if (nextScheduledDm - now < round) + tasks |= UpdateTask.Dm; + } - var nextScheduledPublicSearch = this.LastUpdatePublicSearch + this.UpdateIntervalPublicSearch; - if (nextScheduledPublicSearch - now < round) - tasks |= UpdateTask.PublicSearch; + if (this.EnableUpdatePublicSearch) + { + var nextScheduledPublicSearch = this.LastUpdatePublicSearch + this.UpdateIntervalPublicSearch; + if (nextScheduledPublicSearch - now < round) + tasks |= UpdateTask.PublicSearch; + } - var nextScheduledUser = this.LastUpdateUser + this.UpdateIntervalUser; - if (nextScheduledUser - now < round) - tasks |= UpdateTask.User; + if (this.EnableUpdateUser) + { + var nextScheduledUser = this.LastUpdateUser + this.UpdateIntervalUser; + if (nextScheduledUser - now < round) + tasks |= UpdateTask.User; + } - var nextScheduledList = this.LastUpdateList + this.UpdateIntervalList; - if (nextScheduledList - now < round) - tasks |= UpdateTask.List; + if (this.EnableUpdateList) + { + var nextScheduledList = this.LastUpdateList + this.UpdateIntervalList; + if (nextScheduledList - now < round) + tasks |= UpdateTask.List; + } - var nextScheduledConfig = this.LastUpdateConfig + this.UpdateIntervalConfig; - if (nextScheduledConfig - now < round) - tasks |= UpdateTask.Config; + if (this.EnableUpdateConfig) + { + var nextScheduledConfig = this.LastUpdateConfig + this.UpdateIntervalConfig; + if (nextScheduledConfig - now < round) + tasks |= UpdateTask.Config; + } await this.RunUpdateTasks(tasks, now).ConfigureAwait(false); } @@ -264,33 +312,54 @@ namespace OpenTween // 次に更新が予定される時刻を判定する var min = DateTimeUtc.MaxValue; - var nextScheduledHome = this.LastUpdateHome + this.UpdateIntervalHome; - if (nextScheduledHome < min) - min = nextScheduledHome; + if (this.EnableUpdateHome) + { + var nextScheduledHome = this.LastUpdateHome + this.UpdateIntervalHome; + if (nextScheduledHome < min) + min = nextScheduledHome; + } - var nextScheduledMention = this.LastUpdateMention + this.UpdateIntervalMention; - if (nextScheduledMention < min) - min = nextScheduledMention; + if (this.EnableUpdateMention) + { + var nextScheduledMention = this.LastUpdateMention + this.UpdateIntervalMention; + if (nextScheduledMention < min) + min = nextScheduledMention; + } - var nextScheduledDm = this.LastUpdateDm + this.UpdateIntervalDm; - if (nextScheduledDm < min) - min = nextScheduledDm; + if (this.EnableUpdateDm) + { + var nextScheduledDm = this.LastUpdateDm + this.UpdateIntervalDm; + if (nextScheduledDm < min) + min = nextScheduledDm; + } - var nextScheduledPublicSearch = this.LastUpdatePublicSearch + this.UpdateIntervalPublicSearch; - if (nextScheduledPublicSearch < min) - min = nextScheduledPublicSearch; + if (this.EnableUpdatePublicSearch) + { + var nextScheduledPublicSearch = this.LastUpdatePublicSearch + this.UpdateIntervalPublicSearch; + if (nextScheduledPublicSearch < min) + min = nextScheduledPublicSearch; + } - var nextScheduledUser = this.LastUpdateUser + this.UpdateIntervalUser; - if (nextScheduledUser < min) - min = nextScheduledUser; + if (this.EnableUpdateUser) + { + var nextScheduledUser = this.LastUpdateUser + this.UpdateIntervalUser; + if (nextScheduledUser < min) + min = nextScheduledUser; + } - var nextScheduledList = this.LastUpdateList + this.UpdateIntervalList; - if (nextScheduledList < min) - min = nextScheduledList; + if (this.EnableUpdateList) + { + var nextScheduledList = this.LastUpdateList + this.UpdateIntervalList; + if (nextScheduledList < min) + min = nextScheduledList; + } - var nextScheduledConfig = this.LastUpdateConfig + this.UpdateIntervalConfig; - if (nextScheduledConfig < min) - min = nextScheduledConfig; + if (this.EnableUpdateConfig) + { + var nextScheduledConfig = this.LastUpdateConfig + this.UpdateIntervalConfig; + if (nextScheduledConfig < min) + min = nextScheduledConfig; + } delay = min - DateTimeUtc.Now; diff --git a/OpenTween/Tween.cs b/OpenTween/Tween.cs index edfcc650..7756c6de 100644 --- a/OpenTween/Tween.cs +++ b/OpenTween/Tween.cs @@ -1388,12 +1388,15 @@ namespace OpenTween private void RefreshTimelineScheduler() { - this.timelineScheduler.UpdateIntervalHome = TimeSpan.FromSeconds(SettingManager.Common.TimelinePeriod); - this.timelineScheduler.UpdateIntervalMention = TimeSpan.FromSeconds(SettingManager.Common.ReplyPeriod); - this.timelineScheduler.UpdateIntervalDm = TimeSpan.FromSeconds(SettingManager.Common.DMPeriod); - this.timelineScheduler.UpdateIntervalPublicSearch = TimeSpan.FromSeconds(SettingManager.Common.PubSearchPeriod); - this.timelineScheduler.UpdateIntervalUser = TimeSpan.FromSeconds(SettingManager.Common.UserTimelinePeriod); - this.timelineScheduler.UpdateIntervalList = TimeSpan.FromSeconds(SettingManager.Common.ListsPeriod); + static TimeSpan intervalSecondsOrDisabled(int seconds) + => seconds == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(seconds); + + this.timelineScheduler.UpdateIntervalHome = intervalSecondsOrDisabled(SettingManager.Common.TimelinePeriod); + this.timelineScheduler.UpdateIntervalMention = intervalSecondsOrDisabled(SettingManager.Common.ReplyPeriod); + this.timelineScheduler.UpdateIntervalDm = intervalSecondsOrDisabled(SettingManager.Common.DMPeriod); + this.timelineScheduler.UpdateIntervalPublicSearch = intervalSecondsOrDisabled(SettingManager.Common.PubSearchPeriod); + this.timelineScheduler.UpdateIntervalUser = intervalSecondsOrDisabled(SettingManager.Common.UserTimelinePeriod); + this.timelineScheduler.UpdateIntervalList = intervalSecondsOrDisabled(SettingManager.Common.ListsPeriod); this.timelineScheduler.UpdateIntervalConfig = TimeSpan.FromHours(6); this.timelineScheduler.UpdateAfterSystemResume = TimeSpan.FromSeconds(30); -- 2.11.0