private async Task WidgetsBackgroundUpdate() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); UserViewModel user = await ChannelSession.GetCurrentUser(); foreach (var widgetGroup in ChannelSession.Settings.OverlayWidgets.GroupBy(ow => ow.OverlayName)) { IOverlayService overlay = this.GetOverlay(widgetGroup.Key); if (overlay != null) { overlay.StartBatching(); foreach (OverlayWidget widget in widgetGroup) { try { if (widget.IsEnabled) { bool isInitialized = widget.Item.IsInitialized; if (!isInitialized) { await widget.Item.Initialize(); } if (!isInitialized || !widget.DontRefresh) { OverlayItemBase item = await widget.Item.GetProcessedItem(user, new List <string>(), new Dictionary <string, string>()); if (item != null) { await overlay.SendItem(item, widget.Position, new OverlayItemEffects()); } } } else { await widget.Item.Disable(); } } catch (Exception ex) { Logger.Log(ex); } } await overlay.EndBatching(); } } await Task.Delay(ChannelSession.Settings.OverlayWidgetRefreshTime * 1000); }); }
private async Task WidgetsBackgroundUpdate() { long updateSeconds = 0; await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); UserViewModel user = await ChannelSession.GetCurrentUser(); foreach (var widgetGroup in ChannelSession.Settings.OverlayWidgets.GroupBy(ow => ow.OverlayName)) { IOverlayService overlay = this.GetOverlay(widgetGroup.Key); if (overlay != null) { overlay.StartBatching(); foreach (OverlayWidgetModel widget in widgetGroup) { try { if (widget.IsEnabled) { if (!widget.Item.IsInitialized) { await widget.Initialize(); } else if (widget.SupportsRefreshUpdating && widget.RefreshTime > 0 && (updateSeconds % widget.RefreshTime) == 0) { await widget.UpdateItem(); } } else { if (widget.Item.IsInitialized) { await widget.Disable(); } } } catch (Exception ex) { Logger.Log(ex); } } await overlay.EndBatching(); } } await Task.Delay(1000); updateSeconds++; }); }
private async void Overlay_OnWebSocketConnectedOccurred(object sender, EventArgs e) { IOverlayService overlay = (IOverlayService)sender; this.OnOverlayConnectedOccurred(overlay, new EventArgs()); overlay.StartBatching(); foreach (OverlayWidgetModel widget in ChannelSession.Settings.OverlayWidgets.Where(ow => ow.OverlayName.Equals(overlay.Name))) { try { if (widget.IsEnabled) { await widget.ShowItem(); await widget.LoadCachedData(); await widget.UpdateItem(); } } catch (Exception ex) { Logger.Log(ex); } } await overlay.EndBatching(); }