Skip to content

Commit 1b98991

Browse files
committed
Fix Linux desktop test compilation
1 parent 372ecaa commit 1b98991

2 files changed

Lines changed: 40 additions & 11 deletions

File tree

apps/desktop/src-tauri/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ mod windows;
1212

1313
use std::path::{Path, PathBuf};
1414
use std::{env, ffi::OsStr};
15-
use tauri::{AppHandle, Emitter, Manager, RunEvent};
15+
#[cfg(target_os = "macos")]
16+
use tauri::RunEvent;
17+
use tauri::{AppHandle, Emitter, Manager};
1618

1719
use commands::{
1820
cancel_app_quit, check_external_modification, close_document, create_document,
1921
create_editor_window, desktop_platform, destroy_current_window, export_pdf,
2022
export_pdf_from_hwp_bytes, mark_document_dirty, mutate_document, open_document,
21-
open_document_with_bytes, print_webview, query_document, render_page_svg,
22-
reveal_in_folder, save_document, save_document_as, save_hwp_bytes, take_pending_open_paths,
23+
open_document_with_bytes, print_webview, query_document, render_page_svg, reveal_in_folder,
24+
save_document, save_document_as, save_hwp_bytes, take_pending_open_paths,
2325
};
2426
use state::AppState;
2527
use updates::{get_update_state, restart_to_apply_update, start_update_install};
@@ -84,9 +86,12 @@ pub fn run() {
8486
.build(tauri::generate_context!())
8587
.expect("failed to build HOP desktop app");
8688

87-
app.run(|app, event| {
89+
app.run(|_app, _event| {
8890
#[cfg(target_os = "macos")]
8991
{
92+
let app = _app;
93+
let event = _event;
94+
9095
if let RunEvent::Opened { urls } = &event {
9196
let paths = urls
9297
.clone()

apps/desktop/src-tauri/src/linux_runtime.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ fn requested_gtk_im_module() -> Option<String> {
4545
.ok()
4646
.and_then(|value| normalize_im_module(value.trim()))
4747
.or_else(|| {
48-
env::var("XMODIFIERS")
49-
.ok()
50-
.and_then(|value| value.split("@im=").nth(1))
51-
.and_then(normalize_im_module)
48+
env::var("XMODIFIERS").ok().and_then(|value| {
49+
value
50+
.split_once("@im=")
51+
.and_then(|(_, module)| normalize_im_module(module))
52+
})
5253
})
5354
}
5455

@@ -110,13 +111,17 @@ mod tests {
110111

111112
struct EnvRestore {
112113
gtk_im_module_file: Option<std::ffi::OsString>,
114+
gtk_im_module: Option<std::ffi::OsString>,
115+
xmodifiers: Option<std::ffi::OsString>,
113116
appdir: Option<std::ffi::OsString>,
114117
}
115118

116119
impl EnvRestore {
117120
fn capture() -> Self {
118121
Self {
119122
gtk_im_module_file: env::var_os("GTK_IM_MODULE_FILE"),
123+
gtk_im_module: env::var_os("GTK_IM_MODULE"),
124+
xmodifiers: env::var_os("XMODIFIERS"),
120125
appdir: env::var_os("APPDIR"),
121126
}
122127
}
@@ -129,6 +134,14 @@ mod tests {
129134
Some(value) => env::set_var("GTK_IM_MODULE_FILE", value),
130135
None => env::remove_var("GTK_IM_MODULE_FILE"),
131136
}
137+
match &self.gtk_im_module {
138+
Some(value) => env::set_var("GTK_IM_MODULE", value),
139+
None => env::remove_var("GTK_IM_MODULE"),
140+
}
141+
match &self.xmodifiers {
142+
Some(value) => env::set_var("XMODIFIERS", value),
143+
None => env::remove_var("XMODIFIERS"),
144+
}
132145
match &self.appdir {
133146
Some(value) => env::set_var("APPDIR", value),
134147
None => env::remove_var("APPDIR"),
@@ -170,9 +183,7 @@ mod tests {
170183
let _lock = ENV_LOCK.lock().unwrap();
171184
let _restore = EnvRestore::capture();
172185
let dir = tempfile::tempdir().unwrap();
173-
let cache_path = dir
174-
.path()
175-
.join("usr/lib/gtk-3.0/3.0.0/immodules.cache");
186+
let cache_path = dir.path().join("usr/lib/gtk-3.0/3.0.0/immodules.cache");
176187
fs::create_dir_all(cache_path.parent().unwrap()).unwrap();
177188
fs::write(&cache_path, "\"xim\"\n").unwrap();
178189

@@ -192,6 +203,19 @@ mod tests {
192203
assert_eq!(normalize_im_module(" "), None);
193204
}
194205

206+
#[test]
207+
fn requested_im_module_falls_back_to_xmodifiers() {
208+
let _lock = ENV_LOCK.lock().unwrap();
209+
let _restore = EnvRestore::capture();
210+
211+
unsafe {
212+
env::remove_var("GTK_IM_MODULE");
213+
env::set_var("XMODIFIERS", "@im=fcitx5");
214+
}
215+
216+
assert_eq!(requested_gtk_im_module(), Some("fcitx".to_string()));
217+
}
218+
195219
#[test]
196220
fn active_cache_supports_requested_module() {
197221
let _lock = ENV_LOCK.lock().unwrap();

0 commit comments

Comments
 (0)