Implement start subcommand on Windows. Fix #34

This commit is contained in:
Federico Terzi 2019-09-16 10:56:14 +02:00
parent fa64125fa0
commit 478d30189f
5 changed files with 40 additions and 3 deletions

View File

@ -29,7 +29,6 @@ lazy_static = "1.4.0"
[target.'cfg(unix)'.dependencies]
libc = "0.2.62"
[dev-dependencies]
tempfile = "3.1.0"

View File

@ -27,7 +27,7 @@
#define UNICODE
#include <Windows.h>
#include <windows.h>
#include <strsafe.h>
#include <shellapi.h>
@ -530,4 +530,32 @@ int32_t show_context_menu(MenuItem * items, int32_t count) {
}
return -1;
}
int32_t start_daemon_process() {
wchar_t cmd[MAX_PATH];
swprintf(cmd, MAX_PATH, L"espanso.exe daemon");
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
// Documentation: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw
BOOL res = CreateProcess(
L"./espanso.exe",
cmd,
NULL,
NULL,
FALSE,
DETACHED_PROCESS,
NULL,
NULL,
&si,
&pi
);
if (!res) {
return -1;
}
return 1;
}

View File

@ -23,6 +23,10 @@
#include <stdio.h>
#include <stdint.h>
// SYSTEM
extern "C" int32_t start_daemon_process();
extern void * manager_instance;
/*

View File

@ -29,6 +29,7 @@ pub struct WindowsMenuItem {
#[allow(improper_ctypes)]
#[link(name="winbridge", kind="static")]
extern {
pub fn start_daemon_process() -> i32;
pub fn initialize(s: *const c_void, ico_path: *const u16, bmp_path: *const u16) -> i32;
// SYSTEM

View File

@ -294,7 +294,12 @@ fn start_main(config_set: ConfigSet) {
#[cfg(target_os = "windows")]
fn detach_daemon() {
// TODO
unsafe {
let res = bridge::windows::start_daemon_process();
if res < 0 {
println!("Error starting daemon process");
}
}
}
#[cfg(not(target_os = "windows"))]