BlueGit

ict rusty-teams

Files

rusty-teams / crates / webview / src / dialog.rs

dialog.rs

dialog.rs 1.5 KiB Download Raw
1use std::sync::{Arc, mpsc};
2
3use crate::transport::UiRequest;
4
5/// `Hosted` serves `page_html` at `page_url` for an app dialog; `Call` loads Teams on the web itself.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum DialogMode {
8 Hosted,
9 Call,
10}
11
12#[derive(Debug, Clone)]
13pub struct DialogSpec {
14 pub mode: DialogMode,
15 pub title: String,
16 pub width: u32,
17 pub height: u32,
18 pub background: u32,
19 pub owner: Option<isize>,
20 pub page_url: String,
21 pub page_html: String,
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub enum DialogEvent {
26 Message(String),
27 Closed,
28}
29
30#[derive(Debug)]
31pub(crate) enum DialogCommand {
32 Post(String),
33 Resize {
34 width: Option<u32>,
35 height: Option<u32>,
36 },
37 Close,
38}
39
40#[derive(Clone)]
41pub struct DialogHandle {
42 pub(crate) id: u64,
43 pub(crate) requests: mpsc::Sender<UiRequest>,
44 pub(crate) waker: Arc<dyn Fn() + Send + Sync>,
45}
46
47impl DialogHandle {
48 pub fn post(&self, json: String) {
49 self.send(DialogCommand::Post(json));
50 }
51
52 pub fn resize(&self, width: Option<u32>, height: Option<u32>) {
53 self.send(DialogCommand::Resize { width, height });
54 }
55
56 pub fn close(&self) {
57 self.send(DialogCommand::Close);
58 }
59
60 fn send(&self, command: DialogCommand) {
61 let request = UiRequest::Dialog {
62 id: self.id,
63 command,
64 };
65 if self.requests.send(request).is_ok() {
66 (self.waker)();
67 }
68 }
69}