コード例 #1
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()
            });
コード例 #2
0
        public Task InitAsync(PluginInitContext context)
        {
            Context             = context;
            Settings            = context.API.LoadSettingJsonStorage <Settings>();
            viewModel           = new SettingsViewModel(context, Settings);
            contextMenu         = new ContextMenu(Context);
            pluginManager       = new PluginsManager(Context, Settings);
            _manifestUpdateTask = pluginManager
                                  .UpdateManifestAsync(true)
                                  .ContinueWith(_ =>
            {
                lastUpdateTime = DateTime.Now;
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            return(Task.CompletedTask);
        }