Merge pull request #425 from federico-terzi/dev

Version 0.7.1
This commit is contained in:
Federico Terzi 2020-08-26 20:03:11 +02:00 committed by GitHub
commit e2606938f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 58 additions and 20 deletions

2
Cargo.lock generated
View File

@ -371,7 +371,7 @@ dependencies = [
[[package]]
name = "espanso"
version = "0.7.0"
version = "0.7.1"
dependencies = [
"backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package]
name = "espanso"
version = "0.7.0"
version = "0.7.1"
authors = ["Federico Terzi <federicoterzi96@gmail.com>"]
license = "GPL-3.0"
description = "Cross-platform Text Expander written in Rust"

View File

@ -1,5 +1,5 @@
name: espanso
version: 0.7.0
version: 0.7.1
summary: A Cross-platform Text Expander written in Rust
description: |
espanso is a Cross-platform, Text Expander written in Rust.

View File

@ -24,11 +24,11 @@ use crate::event::{ActionType, Event, KeyEvent, KeyModifier};
use log::{debug, error, info};
use std::ffi::c_void;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::Acquire;
use std::sync::mpsc::Sender;
use std::sync::Arc;
use std::path::{Path, PathBuf};
use widestring::{U16CStr, U16CString};
const BMP_BINARY: &[u8] = include_bytes!("../res/win/espanso.bmp");

View File

@ -25,7 +25,10 @@ use crate::keyboard::KeyboardManager;
use crate::matcher::{Match, MatchReceiver};
use crate::protocol::{send_command_or_warn, IPCCommand, Service};
use crate::render::{RenderResult, Renderer};
use crate::ui::{MenuItem, MenuItemType, UIManager};
use crate::{
guard::InjectGuard,
ui::{MenuItem, MenuItemType, UIManager},
};
use log::{debug, error, info, warn};
use regex::Regex;
use std::cell::RefCell;
@ -209,7 +212,7 @@ impl<
}
// Block espanso from reinterpreting its own actions
self.is_injecting.store(true, Release);
let _inject_guard = InjectGuard::new(self.is_injecting.clone(), &config);
let char_count = if trailing_separator.is_none() {
m.triggers[trigger_offset].chars().count() as i32
@ -307,18 +310,6 @@ impl<
.set_clipboard(&previous_clipboard_content);
}
// On macOS, because the keyinjection is async, we need to wait a bit before
// giving back the control. Otherwise, the injected actions will be handled back
// by espanso itself.
if cfg!(target_os = "macos") {
std::thread::sleep(std::time::Duration::from_millis(
config.mac_post_inject_delay,
));
}
// Re-allow espanso to interpret actions
self.is_injecting.store(false, Release);
expansion_data
}
}
@ -349,6 +340,9 @@ impl<
return;
}
// Block espanso from reinterpreting its own actions
let _inject_guard = InjectGuard::new(self.is_injecting.clone(), &config);
let last_expansion_data = self.last_expansion_data.borrow();
if let Some(ref last_expansion_data) = *last_expansion_data {
let (trigger_string, injected_text_len) = last_expansion_data;

View File

@ -61,7 +61,10 @@ impl super::Extension for FormExtension {
}
if let Some(icon_path) = crate::context::get_icon_path() {
form_config.insert(Value::from("icon"), Value::from(icon_path.to_string_lossy().to_string()));
form_config.insert(
Value::from("icon"),
Value::from(icon_path.to_string_lossy().to_string()),
);
}
let serialized_config: String =

39
src/guard.rs Normal file
View File

@ -0,0 +1,39 @@
use crate::config::Configs;
use log::debug;
use std::sync::atomic::Ordering::Release;
use std::sync::{atomic::AtomicBool, Arc};
pub struct InjectGuard {
is_injecting: Arc<AtomicBool>,
mac_post_inject_delay: u64,
}
impl InjectGuard {
pub fn new(is_injecting: Arc<AtomicBool>, config: &Configs) -> Self {
debug!("enabling inject guard");
// Enable the injecting block
is_injecting.store(true, Release);
Self {
is_injecting,
mac_post_inject_delay: config.mac_post_inject_delay,
}
}
}
impl Drop for InjectGuard {
fn drop(&mut self) {
debug!("releasing inject guard");
// On macOS, because the keyinjection is async, we need to wait a bit before
// giving back the control. Otherwise, the injected actions will be handled back
// by espanso itself.
if cfg!(target_os = "macos") {
std::thread::sleep(std::time::Duration::from_millis(self.mac_post_inject_delay));
}
// Re-allow espanso to interpret actions
self.is_injecting.store(false, Release);
}
}

View File

@ -63,6 +63,7 @@ mod edit;
mod engine;
mod event;
mod extension;
mod guard;
mod keyboard;
mod matcher;
mod package;

View File

@ -71,7 +71,8 @@ impl ModuloManager {
if let Some(ref modulo_path) = self.modulo_path {
let mut command = Command::new(modulo_path);
command.args(args)
command
.args(args)
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped());