Skip to content

Commit

Permalink
fix: hard-coding rime data dir #32
Browse files Browse the repository at this point in the history
  • Loading branch information
wlh320 committed Aug 27, 2024
1 parent bd728ee commit cc24758
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "rime_ls"
version = "0.3.0"
edition = "2021"
authors = ["ZilcH40 <[email protected]>"]
rust-version = "1.63"
rust-version = "1.64"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Default for Config {
always_incomplete: default_always_incomplete(),
preselect_first: default_preselect_first(),
long_filter_text: default_long_filter_text(),
show_filter_text_in_label: default_show_filter_text_in_label()
show_filter_text_in_label: default_show_filter_text_in_label(),
}
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ fn default_paging_characters() -> Vec<String> {
}

fn default_shared_data_dir() -> PathBuf {
PathBuf::from("/usr/share/rime-data")
PathBuf::from(crate::utils::rime_default_shared_data_dir())
}

fn default_user_data_dir() -> PathBuf {
Expand Down
12 changes: 5 additions & 7 deletions src/rime.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::consts::{APP_NAME, KEY_BACKSPACE, KEY_ESCAPE, RAW_RE};
use librime_sys as librime;
use once_cell::sync::OnceCell;
use std::ffi::{CStr, CString, NulError, c_char};
use std::ffi::{c_char, CStr, CString, NulError};
use std::sync::Mutex;
use thiserror::Error;

Expand Down Expand Up @@ -298,14 +298,12 @@ impl Rime {

#[test]
fn test_get_candidates() {
let shared_data_dir = "/usr/share/rime-data/";
let base_dir = directories::BaseDirs::new().unwrap();
let data_dir = base_dir.data_dir().join("rime-ls-test");
let user_data_dir = data_dir.to_str().unwrap();
let log_dir = "/tmp";
let shared_data_dir = crate::utils::rime_default_shared_data_dir();
let temp_dir = std::env::temp_dir();
let temp_dir = temp_dir.to_str().unwrap();

// init
Rime::init(shared_data_dir, user_data_dir, log_dir).unwrap();
Rime::init(shared_data_dir, temp_dir, temp_dir).unwrap();
let rime = Rime::global();
// simulate typing
let keys = vec![b'w', b'l', b'h'];
Expand Down
14 changes: 14 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ pub fn expand_tilde(path: impl AsRef<Path>) -> PathBuf {
home_dir.join(path.as_ref().strip_prefix("~").unwrap())
}

/// rime's default shared data dir
pub fn rime_default_shared_data_dir() -> &'static str {
// read environment variable first
if let Some(var) = option_env!("RIME_DEFAULT_DATA_DIR") {
var
} else if cfg!(target_os = "macos") {
"/Library/Input Methods/Squirrel.app/Contents/SharedSupport"
} else {
// cannot determine shared data dir on windows
// Ref: https://github.com/rime/home/wiki/SharedData
"/usr/share/rime-data"
}
}

#[inline]
fn char_is_word(ch: char) -> bool {
ch.is_alphanumeric() || ch == '_'
Expand Down

0 comments on commit cc24758

Please sign in to comment.