Remove warnings and add espanso version to logs

This commit is contained in:
Federico Terzi 2019-09-16 11:47:25 +02:00
parent 14268b1bc7
commit 8e6c536673
7 changed files with 15 additions and 37 deletions

View File

@ -17,8 +17,6 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::process::{Command, Stdio};
use std::io::{Write};
use widestring::U16CString; use widestring::U16CString;
use crate::bridge::windows::{set_clipboard, get_clipboard}; use crate::bridge::windows::{set_clipboard, get_clipboard};

View File

@ -22,27 +22,22 @@ use crate::bridge::windows::*;
use crate::event::{Event, KeyEvent, KeyModifier, ActionType}; use crate::event::{Event, KeyEvent, KeyModifier, ActionType};
use crate::event::KeyModifier::*; use crate::event::KeyModifier::*;
use std::ffi::c_void; use std::ffi::c_void;
use std::fs::create_dir_all; use std::{fs};
use std::{fs, thread, time};
use std::sync::{Arc, Mutex};
use widestring::U16CString; use widestring::U16CString;
use log::{info, debug, error}; use log::{info};
const BMP_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.bmp"); const BMP_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.bmp");
const ICO_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.ico"); const ICO_BINARY : &'static [u8] = include_bytes!("../res/win/espanso.ico");
pub struct WindowsContext { pub struct WindowsContext {
send_channel: Sender<Event>, send_channel: Sender<Event>,
id: Arc<Mutex<i32>>
} }
impl WindowsContext { impl WindowsContext {
pub fn new(send_channel: Sender<Event>) -> Box<WindowsContext> { pub fn new(send_channel: Sender<Event>) -> Box<WindowsContext> {
// Initialize image resources // Initialize image resources
let data_dir = dirs::data_dir().expect("Can't obtain data_dir(), terminating."); let espanso_dir = super::get_data_dir();
let espanso_dir = data_dir.join("espanso");
let res = create_dir_all(&espanso_dir);
info!("Initializing Espanso resources in {}", espanso_dir.as_path().display()); 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 bmp_icon = espanso_bmp_image.to_str().unwrap_or_default();
let ico_icon = espanso_ico_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 send_channel = send_channel;
let context = Box::new(WindowsContext{ let context = Box::new(WindowsContext{
send_channel, send_channel,
id
}); });
unsafe { unsafe {

View File

@ -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, pub fn new(keyboard_manager: &'a S, clipboard_manager: &'a C,
config_manager: &'a M, ui_manager: &'a U, config_manager: &'a M, ui_manager: &'a U,
extensions: Vec<Box<dyn Extension>>) -> Engine<'a, S, C, M, U> { extensions: Vec<Box<dyn Extension>>) -> Engine<'a, S, C, M, U> {
clipboard_manager.set_clipboard("nicetomeetyou");
println!("{}", clipboard_manager.get_clipboard().unwrap());
// Register all the extensions // Register all the extensions
let mut extension_map = HashMap::new(); let mut extension_map = HashMap::new();
for extension in extensions.into_iter() { for extension in extensions.into_iter() {

View File

@ -17,8 +17,6 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::sync::mpsc;
use std::os::raw::{c_void};
use widestring::{U16CString}; use widestring::{U16CString};
use crate::bridge::windows::*; use crate::bridge::windows::*;

View File

@ -30,7 +30,7 @@ use std::time::Duration;
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{App, Arg, SubCommand, ArgMatches};
use fs2::FileExt; use fs2::FileExt;
use log::{error, info, warn, LevelFilter}; use log::{info, warn, LevelFilter};
use simplelog::{CombinedLogger, SharedLogger, TerminalMode, TermLogger, WriteLogger}; use simplelog::{CombinedLogger, SharedLogger, TerminalMode, TermLogger, WriteLogger};
use crate::config::ConfigSet; use crate::config::ConfigSet;
@ -226,6 +226,7 @@ fn daemon_main(config_set: ConfigSet) {
// Activate logging for panics // Activate logging for panics
log_panics::init(); log_panics::init();
info!("espanso version {}", VERSION);
info!("starting daemon..."); info!("starting daemon...");
let (send_channel, receive_channel) = mpsc::channel(); let (send_channel, receive_channel) = mpsc::channel();
@ -289,11 +290,11 @@ fn start_main(config_set: ConfigSet) {
precheck_guard(); precheck_guard();
detach_daemon(); detach_daemon(config_set);
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn detach_daemon() { fn detach_daemon(_: ConfigSet) {
unsafe { unsafe {
let res = bridge::windows::start_daemon_process(); let res = bridge::windows::start_daemon_process();
if res < 0 { if res < 0 {
@ -303,11 +304,11 @@ fn detach_daemon() {
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
fn detach_daemon() { fn detach_daemon(config_set: ConfigSet) {
unsafe { unsafe {
let pid = libc::fork(); let pid = libc::fork();
if pid < 0 { if pid < 0 {
error!("Unable to fork."); println!("Unable to fork.");
exit(4); exit(4);
} }
if pid > 0 { // Parent process exit if pid > 0 { // Parent process exit

View File

@ -17,14 +17,11 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::io::{BufReader, Read}; use log::{info};
use std::io::Write;
use log::{info, error, warn};
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::net::{TcpListener, TcpStream, SocketAddr}; use std::net::{TcpListener, TcpStream};
use super::IPCCommand; use super::IPCCommand;
use crate::context;
use crate::event::*; use crate::event::*;
use crate::protocol::{process_event, send_command}; use crate::protocol::{process_event, send_command};
use crate::config::ConfigSet; use crate::config::ConfigSet;

View File

@ -17,20 +17,14 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::process::Command;
use crate::bridge::windows::{show_notification, close_notification, WindowsMenuItem, show_context_menu}; use crate::bridge::windows::{show_notification, close_notification, WindowsMenuItem, show_context_menu};
use widestring::U16CString; use widestring::U16CString;
use std::{fs, thread, time}; use std::{thread, time};
use log::{info, debug}; use log::{debug};
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::Arc; use std::sync::Arc;
use std::fs::create_dir_all;
use std::os::raw::c_void;
use crate::ui::{MenuItem, MenuItemType}; 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 { pub struct WindowsUIManager {
id: Arc<Mutex<i32>> id: Arc<Mutex<i32>>
} }
@ -45,8 +39,8 @@ impl super::UIManager for WindowsUIManager {
// Setup a timeout to close the notification // Setup a timeout to close the notification
let id = Arc::clone(&self.id); let id = Arc::clone(&self.id);
thread::Builder::new().name("notification_thread".to_string()).spawn(move || { let _ = thread::Builder::new().name("notification_thread".to_string()).spawn(move || {
for i in 1..10 { for _ in 1..10 {
let duration = time::Duration::from_millis(200); let duration = time::Duration::from_millis(200);
thread::sleep(duration); thread::sleep(duration);