mirror of
https://github.com/mii443/vrclipboard-ime-gui.git
synced 2025-08-22 16:15:32 +00:00
performance improvement
This commit is contained in:
@ -1,12 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use azookey_binding::Candidate;
|
||||
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||
|
||||
use tracing::info;
|
||||
|
||||
use crate::SELF_EXE_PATH;
|
||||
|
||||
use super::IpcMessage;
|
||||
|
||||
pub struct AzookeyConversionClient {
|
||||
@ -41,16 +37,8 @@ impl AzookeyConversionClient {
|
||||
|
||||
pub fn request_candidates(&mut self, context: &str) -> Vec<Candidate> {
|
||||
info!("Requesting candidates for context: {}", context);
|
||||
let self_exe_path = PathBuf::from(SELF_EXE_PATH.read().unwrap().as_str());
|
||||
let weight_path = self_exe_path
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("ggml-model-Q5_K_M.gguf");
|
||||
self.sender
|
||||
.send(IpcMessage::RequestCandidates(
|
||||
context.to_string(),
|
||||
weight_path.to_string_lossy().to_string(),
|
||||
))
|
||||
.send(IpcMessage::RequestCandidates(context.to_string()))
|
||||
.unwrap();
|
||||
loop {
|
||||
match self.receiver.recv() {
|
||||
|
@ -12,7 +12,7 @@ pub enum IpcMessage {
|
||||
Sender(IpcSender<IpcMessage>),
|
||||
ResetComposingText,
|
||||
InsertAtCursorPosition(String),
|
||||
RequestCandidates(String, String),
|
||||
RequestCandidates(String),
|
||||
Candidates(Vec<Candidate>),
|
||||
End,
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
use std::{collections::HashMap, sync::LazyLock};
|
||||
use std::{collections::HashMap, path::PathBuf, sync::LazyLock};
|
||||
|
||||
use azookey_binding::{Candidate, ComposingText, KanaKanjiConverter};
|
||||
use ipc_channel::ipc::IpcOneShotServer;
|
||||
use itertools::Itertools;
|
||||
use platform_dirs::AppDirs;
|
||||
|
||||
use crate::SELF_EXE_PATH;
|
||||
|
||||
use super::IpcMessage;
|
||||
|
||||
static SIGNMAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
|
||||
@ -116,6 +118,20 @@ impl AzookeyConversionServer {
|
||||
let (a, _) = self.server.accept().unwrap();
|
||||
let mut sender = None;
|
||||
|
||||
let app_dirs = AppDirs::new(Some("vrclipboard-ime"), false).unwrap();
|
||||
let path = app_dirs
|
||||
.config_dir
|
||||
.join("AzooKeyDictionary\\AzooKeyDictionary\\Dictionary");
|
||||
let extract_path = path.to_str().unwrap();
|
||||
|
||||
let self_exe_path = PathBuf::from(SELF_EXE_PATH.read().unwrap().as_str());
|
||||
let weight_path = self_exe_path
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("ggml-model-Q5_K_M.gguf")
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
loop {
|
||||
match a.recv() {
|
||||
Ok(IpcMessage::Sender(s)) => {
|
||||
@ -128,12 +144,7 @@ impl AzookeyConversionServer {
|
||||
let text = Self::pre_process_text(&text);
|
||||
self.composing_text.insert_at_cursor_position(&text);
|
||||
}
|
||||
Ok(IpcMessage::RequestCandidates(context, weight_path)) => {
|
||||
let app_dirs = AppDirs::new(Some("vrclipboard-ime"), false).unwrap();
|
||||
let path = app_dirs
|
||||
.config_dir
|
||||
.join("AzooKeyDictionary\\AzooKeyDictionary\\Dictionary");
|
||||
let extract_path = path.to_str().unwrap();
|
||||
Ok(IpcMessage::RequestCandidates(context)) => {
|
||||
let candidates = self.azookey_converter.request_candidates(
|
||||
&self.composing_text,
|
||||
&context,
|
||||
|
@ -186,15 +186,14 @@ pub static SELF_EXE_PATH: Lazy<RwLock<String>> = Lazy::new(|| RwLock::new(String
|
||||
async fn main() {
|
||||
let args = std::env::args().collect::<Vec<_>>();
|
||||
|
||||
SELF_EXE_PATH.write().unwrap().push_str(&args[0]);
|
||||
|
||||
if args.contains(&"server".to_string()) {
|
||||
let server = AzookeyConversionServer::new();
|
||||
let server_name = &server.server_name;
|
||||
println!("${}$", server_name);
|
||||
server.server_loop();
|
||||
return;
|
||||
} else {
|
||||
println!("Args: {:?}", args);
|
||||
SELF_EXE_PATH.write().unwrap().push_str(&args[0]);
|
||||
}
|
||||
|
||||
let server_name = start_server_process();
|
||||
|
Reference in New Issue
Block a user