summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/client/app/src/ui/windows/quit_token.rs
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/crashreporter/client/app/src/ui/windows/quit_token.rs')
-rw-r--r--toolkit/crashreporter/client/app/src/ui/windows/quit_token.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/toolkit/crashreporter/client/app/src/ui/windows/quit_token.rs b/toolkit/crashreporter/client/app/src/ui/windows/quit_token.rs
new file mode 100644
index 0000000000..f952db3db4
--- /dev/null
+++ b/toolkit/crashreporter/client/app/src/ui/windows/quit_token.rs
@@ -0,0 +1,33 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use std::rc::Rc;
+use windows_sys::Win32::UI::WindowsAndMessaging::PostQuitMessage;
+
+/// A Cloneable token which will post a quit message (with code 0) to the main loop when the last
+/// instance is dropped.
+#[derive(Clone, Default)]
+pub struct QuitToken(#[allow(dead_code)] Rc<QuitTokenInternal>);
+
+impl QuitToken {
+ pub fn new() -> Self {
+ Self::default()
+ }
+}
+
+impl std::fmt::Debug for QuitToken {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ f.debug_struct(std::any::type_name::<Self>())
+ .finish_non_exhaustive()
+ }
+}
+
+#[derive(Default)]
+struct QuitTokenInternal;
+
+impl Drop for QuitTokenInternal {
+ fn drop(&mut self) {
+ unsafe { PostQuitMessage(0) };
+ }
+}