Ejemplo n.º 1
0
        public async Task <List <Result> > QueryAsync(Query query, CancellationToken token)
        {
            var search = query.Search.ToLower();

            if (string.IsNullOrWhiteSpace(search))
            {
                return(pluginManager.GetDefaultHotKeys());
            }

            if ((DateTime.Now - lastUpdateTime).TotalHours > 12) // 12 hours
            {
                await pluginManager.UpdateManifest();

                lastUpdateTime = DateTime.Now;
            }

            return(search switch
            {
                var s when s.StartsWith(Settings.HotKeyInstall) => await pluginManager.RequestInstallOrUpdate(s, token),
                var s when s.StartsWith(Settings.HotkeyUninstall) => pluginManager.RequestUninstall(s),
                var s when s.StartsWith(Settings.HotkeyUpdate) => pluginManager.RequestUpdate(s),
                _ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
                {
                    hotkey.Score = StringMatcher.FuzzySearch(search, hotkey.Title).Score;
                    return hotkey.Score > 0;
                }).ToList()
            });
Ejemplo n.º 2
0
        public async Task <List <Result> > QueryAsync(Query query, CancellationToken token)
        {
            var search = query.Search;

            if (string.IsNullOrWhiteSpace(search))
            {
                return(pluginManager.GetDefaultHotKeys());
            }

            if ((DateTime.Now - lastUpdateTime).TotalHours > 12 && _manifestUpdateTask.IsCompleted) // 12 hours
            {
                _manifestUpdateTask = pluginManager.UpdateManifestAsync().ContinueWith(t =>
                {
                    lastUpdateTime = DateTime.Now;
                }, TaskContinuationOptions.OnlyOnRanToCompletion);
            }

            return(search switch
            {
                //search could be url, no need ToLower() when passed in
                var s when s.StartsWith(Settings.HotKeyInstall, StringComparison.OrdinalIgnoreCase)
                => await pluginManager.RequestInstallOrUpdate(search, token),
                var s when s.StartsWith(Settings.HotkeyUninstall, StringComparison.OrdinalIgnoreCase)
                => pluginManager.RequestUninstall(search),
                var s when s.StartsWith(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase)
                => await pluginManager.RequestUpdate(search, token),
                _ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
                {
                    hotkey.Score = StringMatcher.FuzzySearch(search, hotkey.Title).Score;
                    return hotkey.Score > 0;
                }).ToList()
            });