Exemplo n.º 1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            _bag = new CompositeDisposable();
            NavigationService.Navigating += NavigationService_Navigating;

            _packageToggled = TvPackages.ReactiveKeyDown()
                              .Filter(x => x.EventArgs.Key == Key.Space)
                              .Map(_ => Unit.Default).Merge(TvPackages.ReactiveDoubleClick()
                                                            .Filter(x => {
                var hitTest = TvPackages.InputHitTest(x.EventArgs.GetPosition((IInputElement)x.Sender));
                return(!(hitTest is Rectangle));
            })
                                                            .Map(_ => Unit.Default))
                              .Map(_ => TvPackages.SelectedItem as PackageMenuItem)
                              .NotNull() !;

            _groupToggled =
                TvPackages.ReactiveKeyDown()
                .Filter(x => x.EventArgs.Key == Key.Space)
                .Map(_ => TvPackages.SelectedItem as PackageCategoryTreeItem)
                .NotNull() !;

            _presenter.Start().DisposedBy(_bag);

            TitleBarHandler.BindRepoDropdown(_bag, async x => {
                var app     = (PahkatApp)Application.Current;
                var repos   = (await app.PackageStore.RepoIndexes()).Values.ToArray();
                var records = await app.PackageStore.GetRepoRecords();

                TitleBarHandler.RefreshFlyoutItems(TitleBarReposButton, TitleBarReposFlyout, repos, records);
                // _presenter.BindNewRepositories(_sortedBy.Value);
            });

            ConfigureSortBy();

            TvPackages.Focus();
        }
        private async void SetRepository(Uri?url)
        {
            var app = (PahkatApp)Application.Current;

            var pahkat = app.PackageStore;
            var repos  = await pahkat.RepoIndexes();

            var records = await pahkat.GetRepoRecords();

            TitleBarHandler.RefreshFlyoutItems(TitleBarReposButton, TitleBarReposFlyout,
                                               repos.Values.ToArray(), records);

            await app.Dispatcher.InvokeAsync(() => {
                ILoadedRepository?repo = null;
                if (url == null)
                {
                    if (records.IsNullOrEmpty())
                    {
                        ShowNoLandingPage();
                        return;
                    }

                    if (!repos.Values.IsNullOrEmpty())
                    {
                        repo = repos.Values.First(r => records.ContainsKey(r.Index.Url));
                    }

                    if (repo == null)
                    {
                        ShowNoLandingPage();
                        return;
                    }
                }
                else if (url.Scheme == "divvun-installer")
                {
                    if (url.AbsolutePath == "detailed")
                    {
                        ShowNoLandingPage();
                        return;
                    }
                }
                else
                {
                    if (!repos.Values.IsNullOrEmpty())
                    {
                        repo = repos.Values.First(r => r.Index.Url == url);
                        repo ??= repos.Values.First(r => records.ContainsKey(r.Index.Url));
                    }

                    if (repo == null)
                    {
                        ShowNoLandingPage();
                        return;
                    }
                }

                if (repo == null)
                {
                    app.Settings.Mutate(file => {
                        Log.Warning("No repository found, setting selected repo to null");
                        file.SelectedRepository = null;
                    });
                    return;
                }

                if (repo.Index.LandingUrl == null)
                {
                    ShowNoLandingPage();
                    return;
                }

                TitleBarReposButton.Content = repo.Index.NativeName();
                _webBridge.SetRepository(repo);
                _webView.Load(repo.Index.LandingUrl.SetQueryParam("ts", DateTimeOffset.UtcNow));
            });
        }