Skip to content

Commit f5858bf

Browse files
committed
fix(process): unify system encoding handling to compectiable with rust 1.77.2
1 parent 2cf3cb5 commit f5858bf

File tree

1 file changed

+3
-14
lines changed
  • plugins/shell/src/process

1 file changed

+3
-14
lines changed

plugins/shell/src/process/mod.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ use tauri::async_runtime::{block_on as block_on_task, channel, Receiver, Sender}
2424

2525
pub use encoding_rs::Encoding;
2626
#[cfg(not(windows))]
27-
use encoding_rs::UTF_8;
27+
use encoding_rs::UTF_8 as SYSTEM_ENCODING;
2828
#[cfg(windows)]
29-
use encoding_rs::WINDOWS_1252;
29+
use encoding_rs::WINDOWS_1252 as SYSTEM_ENCODING;
3030
use os_pipe::{pipe, PipeReader, PipeWriter};
3131
use serde::Serialize;
3232
use shared_child::SharedChild;
@@ -432,15 +432,14 @@ fn read_line<F: Fn(Vec<u8>) -> CommandEvent + Send + Copy + 'static>(
432432
tx: Sender<CommandEvent>,
433433
wrapper: F,
434434
) {
435-
let encoder = get_system_encoding();
436435
loop {
437436
let mut buf = Vec::new();
438437
match tauri::utils::io::read_line(&mut reader, &mut buf) {
439438
Ok(n) => {
440439
if n == 0 {
441440
break;
442441
}
443-
let (cow, _, _) = encoder.decode(&buf);
442+
let (cow, _, _) = SYSTEM_ENCODING.decode(&buf);
444443
let decode_bytes = cow.into_owned().into_bytes();
445444
let tx_ = tx.clone();
446445
let _ = block_on_task(async move { tx_.send(wrapper(decode_bytes)).await });
@@ -475,16 +474,6 @@ fn spawn_pipe_reader<F: Fn(Vec<u8>) -> CommandEvent + Send + Copy + 'static>(
475474
});
476475
}
477476

478-
#[cfg(windows)]
479-
const fn get_system_encoding() -> &'static Encoding {
480-
WINDOWS_1252
481-
}
482-
483-
#[cfg(not(windows))]
484-
const fn get_system_encoding() -> &'static Encoding {
485-
UTF_8
486-
}
487-
488477
// tests for the commands functions.
489478
#[cfg(test)]
490479
mod tests {

0 commit comments

Comments
 (0)