Skip to content

Instantly share code, notes, and snippets.

@habibg1232191
Last active August 7, 2022 07:27
Show Gist options
  • Select an option

  • Save habibg1232191/6b66bf309f2300213214fe0dda07dee4 to your computer and use it in GitHub Desktop.

Select an option

Save habibg1232191/6b66bf309f2300213214fe0dda07dee4 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Threading;
using DynamicData.Binding;
using July.Core.Plugin;
using July.Core.Services;
using ReactiveUI;
namespace July.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
private CancellationToken _cancellationToken;
private CancellationTokenSource _cancellationTokenSource;
private List<IWallpaperInfo> _wallpapers = new();
private string _searchString = "";
public List<IWallpaperInfo> Wallpapers
{
get => _wallpapers;
set => this.RaiseAndSetIfChanged(ref _wallpapers, value);
}
public string SearchString
{
get => _searchString;
set
{
Dispatcher.UIThread.Post(LoadWallpapers);
this.RaiseAndSetIfChanged(ref _searchString, value);
}
}
public MainWindowViewModel()
{
_cancellationTokenSource = new CancellationTokenSource();
_cancellationToken = _cancellationTokenSource.Token;
Dispatcher.UIThread.Post(LoadWallpapers);
}
private async void LoadWallpapers()
{
_cancellationTokenSource.Cancel();
_cancellationTokenSource = new CancellationTokenSource();
_cancellationToken = _cancellationTokenSource.Token;
Wallpapers = (await WallpaperPluginService.SelectedPlugin.Search(SearchString, 1, _cancellationToken)).ToList();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment