From 8e6c53667355dbb6f5a3613dd2a631bcdd99c1ff Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Mon, 16 Sep 2019 11:47:25 +0200 Subject: [PATCH] Remove warnings and add espanso version to logs --- src/clipboard/windows.rs | 2 -- src/context/windows.rs | 13 +++---------- src/engine.rs | 3 --- src/keyboard/windows.rs | 2 -- src/main.rs | 11 ++++++----- src/protocol/windows.rs | 7 ++----- src/ui/windows.rs | 14 ++++---------- 7 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/clipboard/windows.rs b/src/clipboard/windows.rs index 76f9e45..caa8e0e 100644 --- a/src/clipboard/windows.rs +++ b/src/clipboard/windows.rs @@ -17,8 +17,6 @@ * along with espanso. If not, see . */ -use std::process::{Command, Stdio}; -use std::io::{Write}; use widestring::U16CString; use crate::bridge::windows::{set_clipboard, get_clipboard}; diff --git a/src/context/windows.rs b/src/context/windows.rs index 10ba531..bb11f96 100644 --- a/src/context/windows.rs +++ b/src/context/windows.rs @@ -22,27 +22,22 @@ use crate::bridge::windows::*; use crate::event::{Event, KeyEvent, KeyModifier, ActionType}; use crate::event::KeyModifier::*; use std::ffi::c_void; -use std::fs::create_dir_all; -use std::{fs, thread, time}; -use std::sync::{Arc, Mutex}; +use std::{fs}; use widestring::U16CString; -use log::{info, debug, error}; +use log::{info}; const BMP_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.bmp"); const ICO_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.ico"); pub struct WindowsContext { send_channel: Sender, - id: Arc> } impl WindowsContext { pub fn new(send_channel: Sender) -> Box { // Initialize image resources - let data_dir = dirs::data_dir().expect("Can't obtain data_dir(), terminating."); - let espanso_dir = data_dir.join("espanso"); - let res = create_dir_all(&espanso_dir); + let espanso_dir = super::get_data_dir(); info!("Initializing Espanso resources in {}", espanso_dir.as_path().display()); @@ -69,12 +64,10 @@ impl WindowsContext { let bmp_icon = espanso_bmp_image.to_str().unwrap_or_default(); let ico_icon = espanso_ico_image.to_str().unwrap_or_default(); - let id = Arc::new(Mutex::new(0)); let send_channel = send_channel; let context = Box::new(WindowsContext{ send_channel, - id }); unsafe { diff --git a/src/engine.rs b/src/engine.rs index 63118a3..1f47d94 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -48,9 +48,6 @@ impl <'a, S: KeyboardManager, C: ClipboardManager, M: ConfigManager<'a>, U: UIMa pub fn new(keyboard_manager: &'a S, clipboard_manager: &'a C, config_manager: &'a M, ui_manager: &'a U, extensions: Vec>) -> Engine<'a, S, C, M, U> { - clipboard_manager.set_clipboard("nicetomeetyou"); - println!("{}", clipboard_manager.get_clipboard().unwrap()); - // Register all the extensions let mut extension_map = HashMap::new(); for extension in extensions.into_iter() { diff --git a/src/keyboard/windows.rs b/src/keyboard/windows.rs index 33f749e..df3564d 100644 --- a/src/keyboard/windows.rs +++ b/src/keyboard/windows.rs @@ -17,8 +17,6 @@ * along with espanso. If not, see . */ -use std::sync::mpsc; -use std::os::raw::{c_void}; use widestring::{U16CString}; use crate::bridge::windows::*; diff --git a/src/main.rs b/src/main.rs index 6d7f4a5..9a6814e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ use std::time::Duration; use clap::{App, Arg, SubCommand, ArgMatches}; use fs2::FileExt; -use log::{error, info, warn, LevelFilter}; +use log::{info, warn, LevelFilter}; use simplelog::{CombinedLogger, SharedLogger, TerminalMode, TermLogger, WriteLogger}; use crate::config::ConfigSet; @@ -226,6 +226,7 @@ fn daemon_main(config_set: ConfigSet) { // Activate logging for panics log_panics::init(); + info!("espanso version {}", VERSION); info!("starting daemon..."); let (send_channel, receive_channel) = mpsc::channel(); @@ -289,11 +290,11 @@ fn start_main(config_set: ConfigSet) { precheck_guard(); - detach_daemon(); + detach_daemon(config_set); } #[cfg(target_os = "windows")] -fn detach_daemon() { +fn detach_daemon(_: ConfigSet) { unsafe { let res = bridge::windows::start_daemon_process(); if res < 0 { @@ -303,11 +304,11 @@ fn detach_daemon() { } #[cfg(not(target_os = "windows"))] -fn detach_daemon() { +fn detach_daemon(config_set: ConfigSet) { unsafe { let pid = libc::fork(); if pid < 0 { - error!("Unable to fork."); + println!("Unable to fork."); exit(4); } if pid > 0 { // Parent process exit diff --git a/src/protocol/windows.rs b/src/protocol/windows.rs index 8ae826a..8cabd30 100644 --- a/src/protocol/windows.rs +++ b/src/protocol/windows.rs @@ -17,14 +17,11 @@ * along with espanso. If not, see . */ -use std::io::{BufReader, Read}; -use std::io::Write; -use log::{info, error, warn}; +use log::{info}; use std::sync::mpsc::Sender; -use std::net::{TcpListener, TcpStream, SocketAddr}; +use std::net::{TcpListener, TcpStream}; use super::IPCCommand; -use crate::context; use crate::event::*; use crate::protocol::{process_event, send_command}; use crate::config::ConfigSet; diff --git a/src/ui/windows.rs b/src/ui/windows.rs index ea882a4..367e1f5 100644 --- a/src/ui/windows.rs +++ b/src/ui/windows.rs @@ -17,20 +17,14 @@ * along with espanso. If not, see . */ -use std::process::Command; use crate::bridge::windows::{show_notification, close_notification, WindowsMenuItem, show_context_menu}; use widestring::U16CString; -use std::{fs, thread, time}; -use log::{info, debug}; +use std::{thread, time}; +use log::{debug}; use std::sync::Mutex; use std::sync::Arc; -use std::fs::create_dir_all; -use std::os::raw::c_void; use crate::ui::{MenuItem, MenuItemType}; -const BMP_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.bmp"); -const ICO_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.ico"); - pub struct WindowsUIManager { id: Arc> } @@ -45,8 +39,8 @@ impl super::UIManager for WindowsUIManager { // Setup a timeout to close the notification let id = Arc::clone(&self.id); - thread::Builder::new().name("notification_thread".to_string()).spawn(move || { - for i in 1..10 { + let _ = thread::Builder::new().name("notification_thread".to_string()).spawn(move || { + for _ in 1..10 { let duration = time::Duration::from_millis(200); thread::sleep(duration);