diff --git a/js/core/src/init.tsx b/js/core/src/init.tsx index 17b102e..62a88f9 100644 --- a/js/core/src/init.tsx +++ b/js/core/src/init.tsx @@ -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() diff --git a/js/core/src/search-index.ts b/js/core/src/search-index.ts index 7b2ebd0..31caaec 100644 --- a/js/core/src/search-index.ts +++ b/js/core/src/search-index.ts @@ -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); } \ No newline at end of file diff --git a/js/typings/index.d.ts b/js/typings/index.d.ts index d1ace34..61d2791 100644 --- a/js/typings/index.d.ts +++ b/js/typings/index.d.ts @@ -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; show_preferences_required_view(entrypointId: string, pluginPreferencesRequired: boolean, entrypointPreferencesRequired: boolean): void; - load_search_index(searchItems: AdditionalSearchItem[], refreshSearchList: boolean): Promise; + reload_search_index(searchItems: AdditionalSearchItem[], refreshSearchList: boolean): Promise; 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; diff --git a/rust/server/src/model.rs b/rust/server/src/model.rs index a14ad64..8bf7af6 100644 --- a/rust/server/src/model.rs +++ b/rust/server/src/model.rs @@ -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)] diff --git a/rust/server/src/plugins/js/mod.rs b/rust/server/src/plugins/js/mod.rs index b92fdf9..a6280a5 100644 --- a/rust/server/src/plugins/js/mod.rs +++ b/rust/server/src/plugins/js/mod.rs @@ -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, } } diff --git a/rust/server/src/plugins/js/search.rs b/rust/server/src/plugins/js/search.rs index d17b9fb..8a156e6 100644 --- a/rust/server/src/plugins/js/search.rs +++ b/rust/server/src/plugins/js/search.rs @@ -11,7 +11,7 @@ use crate::plugins::js::PluginData; use crate::search::{SearchIndex, SearchIndexItem}; #[op] -async fn load_search_index(state: Rc>, generated_commands: Vec, refresh_search_list: bool) -> anyhow::Result<()> { +async fn reload_search_index(state: Rc>, generated_commands: Vec, refresh_search_list: bool) -> anyhow::Result<()> { let (plugin_id, plugin_uuid, repository, mut search_index, icon_cache) = { let state = state.borrow(); diff --git a/rust/server/src/plugins/mod.rs b/rust/server/src/plugins/mod.rs index be09932..706ccf3 100644 --- a/rust/server/src/plugins/mod.rs +++ b/rust/server/src/plugins/mod.rs @@ -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); } }