Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ await ImageLoaderHelper.GetConvertedImageAsPng(outStream,
#endregion

#region Carousel
private bool _isCarouselInitialized = false;

private async Task StartCarouselAutoScroll(int delaySeconds = 5)
{
Expand All @@ -444,18 +445,22 @@ private async Task StartCarouselAutoScroll(int delaySeconds = 5)

try
{
CarouselToken ??= new CancellationTokenSourceWrapper();
while (true)
{
CarouselToken ??= new CancellationTokenSourceWrapper();

await Task.Delay(TimeSpan.FromSeconds(delaySeconds), CarouselToken.Token);
_isCarouselInitialized = true;
if (!IsCarouselPanelAvailable) return;
if (ImageCarousel.SelectedIndex != GameCarouselData?.Count - 1
&& ImageCarousel.SelectedIndex < ImageCarousel.Items.Count - 1)
ImageCarousel.SelectedIndex++;
else
for (int i = GameCarouselData?.Count ?? 0; i > 0; i--)
{
while (!WindowUtility.IsCurrentWindowInFocus())
{
await Task.Delay(RefreshRate, CarouselToken.Token);
}
if (i - 1 >= 0 && i - 1 < ImageCarousel.Items.Count)
{
ImageCarousel.SelectedIndex = i - 1;
Expand All @@ -464,7 +469,9 @@ private async Task StartCarouselAutoScroll(int delaySeconds = 5)
{
await Task.Delay(100, CarouselToken.Token);
}
else break;
}
break;
}
}
catch (TaskCanceledException)
Expand Down Expand Up @@ -496,6 +503,12 @@ public async Task CarouselRestartScroll(int delaySeconds = 5)

public async ValueTask CarouselStopScroll()
{
// Wait until Carousel is fully initialized to invoke the cts cancellation
while (!_isCarouselInitialized)
{
await Task.Delay(500);
}

if (CarouselToken is { IsCancellationRequested: false, IsDisposed: false, IsCancelled: false })
{
await CarouselToken.CancelAsync();
Expand Down
2 changes: 2 additions & 0 deletions CollapseLauncher/XAMLs/MainApp/TrayIcon.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public void ToggleMainVisibility(bool forceShow = false)
MainTaskbarToggle.Text = _showApp;
// Increase refresh rate to 1000ms when main window is hidden
RefreshRate = RefreshRateSlow;
m_homePage?.CarouselStopScroll();
LogWriteLine("Main window is hidden!");

// Spawn the hidden to tray toast notification
Expand All @@ -307,6 +308,7 @@ public void ToggleMainVisibility(bool forceShow = false)
EfficiencyModeWrapper(false);
PInvoke.SetForegroundWindow(mainWindowHandle);
MainTaskbarToggle.Text = _hideApp;
m_homePage?.CarouselRestartScroll();
// Revert refresh rate to its default
RefreshRate = RefreshRateDefault;
LogWriteLine("Main window is shown!");
Expand Down
Loading