Last active
August 7, 2022 07:27
-
-
Save habibg1232191/6b66bf309f2300213214fe0dda07dee4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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