BlueGit

ict rusty-teams

Files

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

dialog.rs

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