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 azookey_binding::Candidate;
|
||||||
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
use ipc_channel::ipc::{IpcReceiver, IpcSender};
|
||||||
|
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::SELF_EXE_PATH;
|
|
||||||
|
|
||||||
use super::IpcMessage;
|
use super::IpcMessage;
|
||||||
|
|
||||||
pub struct AzookeyConversionClient {
|
pub struct AzookeyConversionClient {
|
||||||
@ -41,16 +37,8 @@ impl AzookeyConversionClient {
|
|||||||
|
|
||||||
pub fn request_candidates(&mut self, context: &str) -> Vec<Candidate> {
|
pub fn request_candidates(&mut self, context: &str) -> Vec<Candidate> {
|
||||||
info!("Requesting candidates for context: {}", context);
|
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
|
self.sender
|
||||||
.send(IpcMessage::RequestCandidates(
|
.send(IpcMessage::RequestCandidates(context.to_string()))
|
||||||
context.to_string(),
|
|
||||||
weight_path.to_string_lossy().to_string(),
|
|
||||||
))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
loop {
|
loop {
|
||||||
match self.receiver.recv() {
|
match self.receiver.recv() {
|
||||||
|
@ -12,7 +12,7 @@ pub enum IpcMessage {
|
|||||||
Sender(IpcSender<IpcMessage>),
|
Sender(IpcSender<IpcMessage>),
|
||||||
ResetComposingText,
|
ResetComposingText,
|
||||||
InsertAtCursorPosition(String),
|
InsertAtCursorPosition(String),
|
||||||
RequestCandidates(String, String),
|
RequestCandidates(String),
|
||||||
Candidates(Vec<Candidate>),
|
Candidates(Vec<Candidate>),
|
||||||
End,
|
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 azookey_binding::{Candidate, ComposingText, KanaKanjiConverter};
|
||||||
use ipc_channel::ipc::IpcOneShotServer;
|
use ipc_channel::ipc::IpcOneShotServer;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use platform_dirs::AppDirs;
|
use platform_dirs::AppDirs;
|
||||||
|
|
||||||
|
use crate::SELF_EXE_PATH;
|
||||||
|
|
||||||
use super::IpcMessage;
|
use super::IpcMessage;
|
||||||
|
|
||||||
static SIGNMAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
|
static SIGNMAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
|
||||||
@ -116,6 +118,20 @@ impl AzookeyConversionServer {
|
|||||||
let (a, _) = self.server.accept().unwrap();
|
let (a, _) = self.server.accept().unwrap();
|
||||||
let mut sender = None;
|
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 {
|
loop {
|
||||||
match a.recv() {
|
match a.recv() {
|
||||||
Ok(IpcMessage::Sender(s)) => {
|
Ok(IpcMessage::Sender(s)) => {
|
||||||
@ -128,12 +144,7 @@ impl AzookeyConversionServer {
|
|||||||
let text = Self::pre_process_text(&text);
|
let text = Self::pre_process_text(&text);
|
||||||
self.composing_text.insert_at_cursor_position(&text);
|
self.composing_text.insert_at_cursor_position(&text);
|
||||||
}
|
}
|
||||||
Ok(IpcMessage::RequestCandidates(context, weight_path)) => {
|
Ok(IpcMessage::RequestCandidates(context)) => {
|
||||||
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 candidates = self.azookey_converter.request_candidates(
|
let candidates = self.azookey_converter.request_candidates(
|
||||||
&self.composing_text,
|
&self.composing_text,
|
||||||
&context,
|
&context,
|
||||||
|
@ -186,15 +186,14 @@ pub static SELF_EXE_PATH: Lazy<RwLock<String>> = Lazy::new(|| RwLock::new(String
|
|||||||
async fn main() {
|
async fn main() {
|
||||||
let args = std::env::args().collect::<Vec<_>>();
|
let args = std::env::args().collect::<Vec<_>>();
|
||||||
|
|
||||||
|
SELF_EXE_PATH.write().unwrap().push_str(&args[0]);
|
||||||
|
|
||||||
if args.contains(&"server".to_string()) {
|
if args.contains(&"server".to_string()) {
|
||||||
let server = AzookeyConversionServer::new();
|
let server = AzookeyConversionServer::new();
|
||||||
let server_name = &server.server_name;
|
let server_name = &server.server_name;
|
||||||
println!("${}$", server_name);
|
println!("${}$", server_name);
|
||||||
server.server_loop();
|
server.server_loop();
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
println!("Args: {:?}", args);
|
|
||||||
SELF_EXE_PATH.write().unwrap().push_str(&args[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let server_name = start_server_process();
|
let server_name = start_server_process();
|
||||||
|
Reference in New Issue
Block a user