Implement start subcommand on Windows. Fix #34
This commit is contained in:
		
							parent
							
								
									fa64125fa0
								
							
						
					
					
						commit
						478d30189f
					
				|  | @ -29,7 +29,6 @@ lazy_static = "1.4.0" | ||||||
| [target.'cfg(unix)'.dependencies] | [target.'cfg(unix)'.dependencies] | ||||||
| libc = "0.2.62" | libc = "0.2.62" | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| [dev-dependencies] | [dev-dependencies] | ||||||
| tempfile = "3.1.0" | tempfile = "3.1.0" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ | ||||||
| 
 | 
 | ||||||
| #define UNICODE | #define UNICODE | ||||||
| 
 | 
 | ||||||
| #include <Windows.h> | #include <windows.h> | ||||||
| #include <strsafe.h> | #include <strsafe.h> | ||||||
| #include <shellapi.h> | #include <shellapi.h> | ||||||
| 
 | 
 | ||||||
|  | @ -530,4 +530,32 @@ int32_t show_context_menu(MenuItem * items, int32_t count) { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return -1; |     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; | ||||||
| } | } | ||||||
|  | @ -23,6 +23,10 @@ | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| 
 | 
 | ||||||
|  | // SYSTEM
 | ||||||
|  | 
 | ||||||
|  | extern "C" int32_t start_daemon_process(); | ||||||
|  | 
 | ||||||
| extern void * manager_instance; | extern void * manager_instance; | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  |  | ||||||
|  | @ -29,6 +29,7 @@ pub struct WindowsMenuItem { | ||||||
| #[allow(improper_ctypes)] | #[allow(improper_ctypes)] | ||||||
| #[link(name="winbridge", kind="static")] | #[link(name="winbridge", kind="static")] | ||||||
| extern { | extern { | ||||||
|  |     pub fn start_daemon_process() -> i32; | ||||||
|     pub fn initialize(s: *const c_void, ico_path: *const u16, bmp_path: *const u16) -> i32; |     pub fn initialize(s: *const c_void, ico_path: *const u16, bmp_path: *const u16) -> i32; | ||||||
| 
 | 
 | ||||||
|     // SYSTEM
 |     // SYSTEM
 | ||||||
|  |  | ||||||
|  | @ -294,7 +294,12 @@ fn start_main(config_set: ConfigSet) { | ||||||
| 
 | 
 | ||||||
| #[cfg(target_os = "windows")] | #[cfg(target_os = "windows")] | ||||||
| fn detach_daemon() { | 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"))] | #[cfg(not(target_os = "windows"))] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user