public async void Run(IBackgroundTaskInstance taskInstance) { Debug.WriteLine($"{nameof(ActiveThemeBackgroundTask)} - {nameof(Run)} - Begun"); // Register the Monitoring Events taskInstance.Canceled += TaskInstance_Canceled; taskInstance.Task.Completed += Task_Completed; taskInstance.Task.Progress += Task_Progress; // Create the deferal and jump into the Task _deferral = taskInstance.GetDeferral(); // Create the Active theme Service var activeThemeService = new ActiveThemeService(); // Preform the service for the Active Desktop Theme var desktopTheme = activeThemeService.GetActiveDesktopTheme(); if (desktopTheme != null) { var desktopNextRunSetting = new ActiveDesktopThemeNextRunSetting(); if (DateTime.UtcNow >= desktopNextRunSetting.Value && desktopTheme.WallpaperChangeFrequency.TotalMilliseconds > 0.0) { Debug.WriteLine($"{nameof(ActiveThemeBackgroundTask)} - Active Desktop - Changing Desktop Background"); await activeThemeService.NextDesktopBackground(); } else { Debug.WriteLine($"{nameof(ActiveThemeBackgroundTask)} - Active Desktop - Not enough time passed"); } } // Preform the service for the Active Lockscreen Theme var lockscreenTheme = activeThemeService.GetActiveLockscreenTheme(); if (lockscreenTheme != null) { var lockscreenNextRunSetting = new ActiveLockscreenThemeNextRunSetting(); if (DateTime.UtcNow >= lockscreenNextRunSetting.Value && lockscreenTheme.WallpaperChangeFrequency.TotalMilliseconds > 0.0) { Debug.WriteLine($"{nameof(ActiveThemeBackgroundTask)} - Active Lockscreen - Changing Lockscreen Background"); await activeThemeService.NextLockscreenBackground(); } else { Debug.WriteLine($"{nameof(ActiveThemeBackgroundTask)} - Active Lockscreen - Not enough time passed"); } } // Update the ActiveThemeLastRun ActiveThemeTaskLastRunSetting activeThemeTaskLastRun = new ActiveThemeTaskLastRunSetting(); activeThemeTaskLastRun.Value = DateTime.UtcNow; // Trigger the task is compelted Debug.WriteLine($"{nameof(ActiveThemeBackgroundTask)} - {nameof(Run)} - Completed"); _deferral.Complete(); }
public async override void OnNavigatedTo() { ActiveWallpaperTheme = m_activeThemeService.GetActiveDesktopTheme(); ActiveLockscreenTheme = m_activeThemeService.GetActiveLockscreenTheme(); CurrentWallpaperImagePath = m_activeThemeService.GetCurrentDesktopImagePath(); CurrentLockscreenImagePath = m_activeThemeService.GetCurrentLockscreenImagePath(); NextWallpaperImagePath = m_activeThemeService.GetNextDesktopImagePath(); NextLockscreenImagePath = m_activeThemeService.GetNextLockscreenImagePath(); Debug.WriteLine($"Active Wallpaper Theme: {ActiveDesktopThemeSetting.Value} - {ActiveWallpaperTheme?.ID} - {ActiveWallpaperTheme?.Name}"); Debug.WriteLine($"Active Lockscreen Theme: {ActiveLockscreenThemeSetting.Value} - {ActiveLockscreenTheme?.ID} - {ActiveLockscreenTheme?.Name}"); }