Do not call command generators before reloading search index after frecency mark

This commit is contained in:
Exidex 2024-09-05 20:52:46 +02:00
parent 960d773b91
commit bfe3589cd7
No known key found for this signature in database
GPG key ID: 46D8D21671EB48FA
7 changed files with 34 additions and 11 deletions

View file

@ -1,6 +1,6 @@
import { FC } from "react";
import { runCommandGenerators, runGeneratedCommand } from "./command-generator";
import { loadSearchIndex } from "./search-index";
import { reloadSearchIndex } from "./search-index";
import { clearRenderer } from "gauntlet:renderer";
// @ts-expect-error does typescript support such symbol declarations?
@ -213,7 +213,12 @@ async function runLoop() {
}
case "ReloadSearchIndex": {
runCommandGenerators()
.then(() => loadSearchIndex(false));
.then(() => reloadSearchIndex(false));
break;
}
case "RefreshSearchIndex": {
// noinspection ES6MissingAwait
reloadSearchIndex(false)
break;
}
}
@ -221,7 +226,7 @@ async function runLoop() {
}
runCommandGenerators()
.then(() => loadSearchIndex(true));
.then(() => reloadSearchIndex(true));
(async () => {
await runLoop()

View file

@ -4,6 +4,6 @@ import { generatedCommandSearchIndex } from "./command-generator";
const denoCore: DenoCore = Deno[Deno.internal].core;
const InternalApi = denoCore.ops;
export async function loadSearchIndex(refreshSearchList: boolean) {
await InternalApi.load_search_index(generatedCommandSearchIndex(), refreshSearchList);
export async function reloadSearchIndex(refreshSearchList: boolean) {
await InternalApi.reload_search_index(generatedCommandSearchIndex(), refreshSearchList);
}

View file

@ -6,7 +6,7 @@ interface DenoCore {
ops: InternalApi
}
type PluginEvent = ViewEvent | NotReactsKeyboardEvent | RunCommand | RunGeneratedCommand | OpenView | CloseView | OpenInlineView | ReloadSearchIndex
type PluginEvent = ViewEvent | NotReactsKeyboardEvent | RunCommand | RunGeneratedCommand | OpenView | CloseView | OpenInlineView | ReloadSearchIndex | RefreshSearchIndex
type RenderLocation = "InlineView" | "View"
type ViewEvent = {
@ -55,6 +55,10 @@ type ReloadSearchIndex = {
type: "ReloadSearchIndex"
}
type RefreshSearchIndex = {
type: "RefreshSearchIndex"
}
type PropertyValue = PropertyValueString | PropertyValueNumber | PropertyValueBool | PropertyValueUndefined
type PropertyValueString = { type: "String", value: string }
type PropertyValueNumber = { type: "Number", value: number }
@ -99,7 +103,7 @@ interface InternalApi {
entrypoint_preferences_required(entrypointId: string): Promise<boolean>;
show_preferences_required_view(entrypointId: string, pluginPreferencesRequired: boolean, entrypointPreferencesRequired: boolean): void;
load_search_index(searchItems: AdditionalSearchItem[], refreshSearchList: boolean): Promise<void>;
reload_search_index(searchItems: AdditionalSearchItem[], refreshSearchList: boolean): Promise<void>;
op_react_replace_view(render_location: RenderLocation, top_level_view: boolean, entrypoint_id: string, container: UiWidget): void;
show_plugin_error_view(entrypoint_id: string, render_location: RenderLocation): void;

View file

@ -78,6 +78,7 @@ pub enum JsUiEvent {
text: String,
},
ReloadSearchIndex,
RefreshSearchIndex,
}
// FIXME this could have been serde_v8::AnyValue but it doesn't support undefined, make a pr?
@ -137,6 +138,7 @@ pub enum IntermediateUiEvent {
text: String,
},
ReloadSearchIndex,
RefreshSearchIndex,
}
#[derive(Debug, Deserialize, Serialize)]

View file

@ -41,7 +41,7 @@ use crate::plugins::js::plugins::applications::{list_applications, open_applicat
use crate::plugins::js::plugins::numbat::run_numbat;
use crate::plugins::js::plugins::settings::open_settings;
use crate::plugins::js::preferences::{entrypoint_preferences_required, get_entrypoint_preferences, get_plugin_preferences, plugin_preferences_required};
use crate::plugins::js::search::load_search_index;
use crate::plugins::js::search::reload_search_index;
use crate::plugins::js::ui::{clear_inline_view, fetch_action_id_for_shortcut, op_component_model, op_inline_view_endpoint_id, op_react_replace_view, show_plugin_error_view, show_preferences_required_view};
use crate::plugins::run_status::RunStatusGuard;
use crate::search::{SearchIndex, SearchIndexItem};
@ -121,6 +121,7 @@ pub enum OnePluginCommandData {
modifier_meta: bool,
},
ReloadSearchIndex,
RefreshSearchIndex,
}
#[derive(Clone, Debug)]
@ -189,6 +190,9 @@ pub async fn start_plugin_runtime(data: PluginRuntimeData, run_status_guard: Run
OnePluginCommandData::ReloadSearchIndex => {
Some(IntermediateUiEvent::ReloadSearchIndex)
}
OnePluginCommandData::RefreshSearchIndex => {
Some(IntermediateUiEvent::RefreshSearchIndex)
}
}
}
}
@ -500,7 +504,7 @@ deno_core::extension!(
entrypoint_preferences_required,
// search
load_search_index,
reload_search_index,
// clipboard
clipboard_read_text,
@ -659,6 +663,7 @@ fn from_intermediate_to_js_event(event: IntermediateUiEvent) -> JsUiEvent {
}
IntermediateUiEvent::OpenInlineView { text } => JsUiEvent::OpenInlineView { text },
IntermediateUiEvent::ReloadSearchIndex => JsUiEvent::ReloadSearchIndex,
IntermediateUiEvent::RefreshSearchIndex => JsUiEvent::RefreshSearchIndex,
}
}

View file

@ -11,7 +11,7 @@ use crate::plugins::js::PluginData;
use crate::search::{SearchIndex, SearchIndexItem};
#[op]
async fn load_search_index(state: Rc<RefCell<OpState>>, generated_commands: Vec<AdditionalSearchItem>, refresh_search_list: bool) -> anyhow::Result<()> {
async fn reload_search_index(state: Rc<RefCell<OpState>>, generated_commands: Vec<AdditionalSearchItem>, refresh_search_list: bool) -> anyhow::Result<()> {
let (plugin_id, plugin_uuid, repository, mut search_index, icon_cache) = {
let state = state.borrow();

View file

@ -415,6 +415,13 @@ impl ApplicationManager {
})
}
pub fn request_search_index_refresh(&self, plugin_id: PluginId) {
self.send_command(PluginCommand::One {
id: plugin_id,
data: OnePluginCommandData::RefreshSearchIndex
})
}
pub fn handle_open(&self, href: String) {
match open::that_detached(&href) {
Ok(()) => tracing::info!("Opened '{}' successfully.", href),
@ -603,7 +610,7 @@ impl ApplicationManager {
tracing::warn!(target = "rpc", "error occurred when marking entrypoint frecency {:?}", err)
}
self.request_search_index_reload(plugin_id);
self.request_search_index_refresh(plugin_id);
}
}