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