Skip to content

Commit e67bbbf

Browse files
committed
Destroy windows only for now
1 parent a125c46 commit e67bbbf

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ pub fn prepare(identifier: &str) {
7676
platform_impl::prepare(identifier)
7777
}
7878

79+
/// TODO: Windows-only for now
80+
#[cfg(target_os = "windows")]
81+
pub fn destroy() {
82+
platform_impl::destroy()
83+
}
84+
7985
/// Helper to get current exe path
8086
pub(crate) fn current_exe() -> std::io::Result<PathBuf> {
8187
let path = std::env::current_exe()?;

src/windows.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ pub fn prepare(identifier: &str) {
5151
ID.set(identifier.to_string())
5252
.expect("prepare() called more than once with different identifiers.");
5353
}
54+
55+
pub fn destroy() {
56+
windows_single::destroy();
57+
}

src/windows_single.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,25 @@ pub fn init(f: Box<SingleInstanceCallback>) {
7676
}
7777
}
7878

79-
// pub fn destroy() {
80-
// if let Some(hmutex) = MUTEX_HANDLE.get() {
81-
// unsafe {
82-
// ReleaseMutex(hmutex.0 as _);
83-
// CloseHandle(hmutex.0 as _);
84-
// }
85-
// }
86-
// if let Some(hwnd) = TARGET_WINDOW_HANDLE.get() {
87-
// unsafe { DestroyWindow(hwnd.0 as _) };
88-
// }
89-
// }
79+
pub fn destroy() {
80+
if let Some(hmutex) = MUTEX_HANDLE.get() {
81+
unsafe {
82+
ReleaseMutex(hmutex.0 as _);
83+
CloseHandle(hmutex.0 as _);
84+
}
85+
}
86+
if let Some(hwnd) = TARGET_WINDOW_HANDLE.get() {
87+
unsafe { DestroyWindow(hwnd.0 as _) };
88+
}
89+
}
9090

9191
unsafe extern "system" fn single_instance_window_proc(
9292
hwnd: HWND,
9393
msg: u32,
9494
wparam: WPARAM,
9595
lparam: LPARAM,
9696
) -> LRESULT {
97-
let data_ptr = GetWindowLongPtrW(hwnd, GWL_USERDATA) as *mut (Box<SingleInstanceCallback>);
97+
let data_ptr = GetWindowLongPtrW(hwnd, GWL_USERDATA) as *mut Box<SingleInstanceCallback>;
9898
let callback = &mut *data_ptr;
9999

100100
match msg {

0 commit comments

Comments
 (0)