Skip to content

Commit cb978f1

Browse files
committed
fix: 修复了亲和分可能无法统计的问题
1 parent e2e9835 commit cb978f1

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src-tauri/src/commands/program_service.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,17 @@ async fn launch_new_program(
105105
/// 统一记录一次“用户使用该程序/命令”的意图:
106106
/// - 由 ProgramManager 统一记录 ranker 与查询关联
107107
/// - 并保存配置
108-
async fn record_full_launch(state: &tauri::State<'_, Arc<AppState>>, program_guid: u64) {
108+
async fn record_full_launch(
109+
state: &tauri::State<'_, Arc<AppState>>,
110+
program_guid: u64,
111+
query_text: String,
112+
) {
109113
let program_manager = state.get_program_manager();
110-
111-
let last_query = state.get_last_search_query();
112114
debug!(
113115
"📝 记录使用: query='{}' -> GUID={}",
114-
last_query, program_guid
116+
query_text, program_guid
115117
);
116-
program_manager.record_query_launch(&last_query, program_guid);
118+
program_manager.record_query_launch(&query_text, program_guid);
117119

118120
debug!("💾 保存配置文件");
119121
save_config_to_file(false).await;
@@ -126,6 +128,7 @@ async fn launch_program_internal(
126128
program_guid: u64,
127129
ctrl: bool,
128130
shift: bool,
131+
query_text: String,
129132
override_method: Option<LaunchMethod>,
130133
) -> Result<(), String> {
131134
info!(
@@ -154,7 +157,7 @@ async fn launch_program_internal(
154157
if let LaunchMethod::BuiltinCommand(ref cmd_str) = program.launch_method {
155158
let result = execute_builtin_command(cmd_str).await;
156159
// 无论命令执行是否成功,都记录一次用户意图
157-
record_full_launch(&state, program_guid).await;
160+
record_full_launch(&state, program_guid, query_text).await;
158161
return result;
159162
}
160163

@@ -203,7 +206,7 @@ async fn launch_program_internal(
203206

204207
// 6. 统一记录本次用户意图
205208
// 无论是成功唤醒、启动新实例,还是唤醒失败但不启动,都代表了一次用户意图的完成。
206-
record_full_launch(&state, program_guid).await;
209+
record_full_launch(&state, program_guid, query_text).await;
207210

208211
Ok(())
209212
}
@@ -243,14 +246,13 @@ pub async fn get_program_count<R: Runtime>(
243246
/// - `ctrl`: 是否按下 Ctrl 键(请求管理员权限)
244247
/// - `shift`: 是否按下 Shift 键(唤醒已存在窗口)
245248
/// - `args`: 用户参数数组,无参数时传递空数组 []
246-
pub async fn launch_program<R: Runtime>(
247-
_app: tauri::AppHandle<R>,
248-
_window: tauri::Window<R>,
249+
pub async fn launch_program(
249250
state: tauri::State<'_, Arc<AppState>>,
250251
program_guid: u64,
251252
ctrl: bool,
252253
shift: bool,
253254
args: Vec<String>,
255+
query_text: String,
254256
) -> Result<(), String> {
255257
use crate::modules::parameter_resolver::SystemParameterSnapshot;
256258

@@ -265,7 +267,15 @@ pub async fn launch_program<R: Runtime>(
265267
.await
266268
.map_err(|e| format!("Failed to build launch method: {}", e))?;
267269

268-
launch_program_internal(state, program_guid, ctrl, shift, Some(override_method)).await
270+
launch_program_internal(
271+
state,
272+
program_guid,
273+
ctrl,
274+
shift,
275+
query_text,
276+
Some(override_method),
277+
)
278+
.await
269279
}
270280

271281
#[tauri::command]
@@ -333,9 +343,6 @@ pub async fn handle_search_text<R: Runtime>(
333343

334344
debug!("🔍 处理搜索请求: '{}'", search_text);
335345

336-
// 保存当前搜索查询
337-
state.set_last_search_query(search_text.clone());
338-
339346
let runtime_config = state.get_runtime_config();
340347

341348
let result_count = runtime_config.get_app_config().get_search_result_count();

src-tauri/src/state/app_state.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ pub struct AppState {
3939
game_mode: RwLock<bool>,
4040
/// 阻止所有的键盘输入
4141
is_keyboard_blocked: RwLock<bool>,
42-
/// 最后一次搜索的查询词
43-
last_search_query: RwLock<String>,
4442
/// 国际化翻译器
4543
translator: Arc<RwLock<Translator>>,
4644
/// 唤醒搜索栏前的前台窗口句柄
@@ -75,7 +73,6 @@ impl AppState {
7573
shortcut_manager: RwLock::new(None),
7674
game_mode: RwLock::new(false),
7775
is_keyboard_blocked: RwLock::new(false),
78-
last_search_query: RwLock::new(String::new()),
7976
translator: Arc::new(RwLock::new(Translator::new())),
8077
previous_foreground_window: RwLock::new(None),
8178
previous_selection: RwLock::new(None),
@@ -227,16 +224,6 @@ impl AppState {
227224
*self.is_keyboard_blocked.read()
228225
}
229226

230-
/// 设置最后一次搜索的查询词
231-
pub fn set_last_search_query(&self, query: String) {
232-
*self.last_search_query.write() = query;
233-
}
234-
235-
/// 获取最后一次搜索的查询词
236-
pub fn get_last_search_query(&self) -> String {
237-
self.last_search_query.read().clone()
238-
}
239-
240227
/// 获取翻译器的 RwLock 引用
241228
pub fn get_translator(&self) -> Arc<RwLock<Translator>> {
242229
Arc::clone(&self.translator)

src-ui/windows/Home.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ const confirmParameterInput = async () => {
409409
ctrl: session.ctrlKey,
410410
shift: session.shiftKey,
411411
args: session.collectedArgs,
412+
queryText: searchText.value,
412413
})
413414
} catch (error) {
414415
console.error('Failed to launch program with arguments:', error)
@@ -586,6 +587,7 @@ const launch_program = async (itemIndex: number, ctrlKey = false, shiftKey = fal
586587
ctrl: ctrlKey,
587588
shift: shiftKey,
588589
args: [],
590+
queryText: searchText.value,
589591
})
590592
}
591593

0 commit comments

Comments
 (0)