1
//! Built-in SYSTEM DIALOGS (`SysDialogType`), rendered by azul itself.
2
//!
3
//! Two rules every dialog here obeys:
4
//!
5
//! 1. **Always CPU-rendered.** A dialog that reports a problem — possibly a GPU problem — must not
6
//!    depend on the GPU working, so every window this module creates forces
7
//!    `HwAcceleration::Disabled`.
8
//! 2. **Consent is structural.** Nothing sends, installs or overwrites without the user pressing
9
//!    the button that says so. Background threads only CHECK and STAGE.
10
//!
11
//! The dialogs read app-level configuration (support mailbox, manifest URL,
12
//! changelog URL, app name/version) from [`crate::appenv`], which `App::run`
13
//! fills from `AppConfig`. Entry point: `CallbackInfo::invoke_system_dialog`.
14

            
15
// fn-item -> fn-pointer casts: required for the Into<Callback> generics;
16
// the annotated-temporary alternative buries the callback wiring.
17
#![allow(trivial_casts)]
18
#[cfg(feature = "telemetry")]
19
pub mod crash_reporter;
20
pub mod gpu_check;
21
pub mod markdown;
22
/// Shared report machinery: screenshot REDACTION + the report bundle both
23
/// the problem-report dialog and the crash reporter build.
24
#[cfg(feature = "cpurender")]
25
pub mod report;
26
/// The problem-report dialog. Gated with `cpurender` because it is built ON
27
/// `dialogs::report` (which is) and decodes its screenshot through
28
/// `crate::cpurender::AzulPixmap` — without the gate a `widgets` build with no
29
/// CPU renderer referenced two modules that had been configured out.
30
#[cfg(feature = "cpurender")]
31
pub mod report_problem;
32
#[cfg(feature = "telemetry")]
33
pub mod telemetry_consent;
34
#[cfg(feature = "updater")]
35
pub mod update_version;
36

            
37
use azul_core::{
38
    callbacks::LayoutCallbackType,
39
    geom::LogicalSize,
40
    refany::{OptionRefAny, RefAny},
41
    window::HwAcceleration,
42
};
43
use azul_css::{
44
    dynamic_selector::{
45
        CssPropertyWithConditions, CssPropertyWithConditionsVec, DynamicSelectorVec,
46
    },
47
    props::property::CssProperty,
48
};
49

            
50
use crate::window_state::WindowCreateOptions;
51

            
52
/// A dialog window shell: titled, sized, state in `layout_callback.ctx`,
53
/// and — the invariant of this module — CPU-rendered, whatever the app or
54
/// the environment asked for.
55
#[must_use]
56
1
pub(crate) fn cpu_dialog_window(
57
1
    title: &str,
58
1
    size: (f32, f32),
59
1
    layout: LayoutCallbackType,
60
1
    state: RefAny,
61
1
) -> WindowCreateOptions {
62
1
    let mut options = WindowCreateOptions::create(layout);
63
    // The dialog's state rides the layout callback's ctx slot (the same slot
64
    // FFI hosts use); the layout fn reads it via `info.get_ctx()`. The DATA
65
    // argument stays the app's RefAny, which these engine dialogs never
66
    // downcast.
67
1
    options.window_state.layout_callback.ctx = OptionRefAny::Some(state);
68
1
    options.window_state.title = title.into();
69
1
    options.window_state.size.dimensions = LogicalSize::new(size.0, size.1);
70
    // ALWAYS CPU: never let a diagnostic surface depend on the GPU.
71
1
    options.window_state.renderer_options.hw_accel = HwAcceleration::Disabled;
72
1
    options
73
1
}
74

            
75
/// Unconditional inline properties (no dynamic-selector conditions).
76
pub(crate) fn style(props: Vec<CssProperty>) -> CssPropertyWithConditionsVec {
77
    props
78
        .into_iter()
79
        .map(|property| CssPropertyWithConditions {
80
            property,
81
            apply_if: DynamicSelectorVec::from_const_slice(&[]),
82
        })
83
        .collect::<Vec<_>>()
84
        .into()
85
}
86

            
87
#[cfg(test)]
88
mod tests {
89
    use azul_core::{
90
        callbacks::{LayoutCallbackInfo, LayoutCallbackType},
91
        window::HwAcceleration,
92
    };
93

            
94
    use super::*;
95

            
96
    extern "C" fn dummy_layout(_: RefAny, _: LayoutCallbackInfo) -> azul_core::dom::Dom {
97
        azul_core::dom::Dom::create_body()
98
    }
99

            
100
    #[test]
101
1
    fn dialog_windows_force_cpu_rendering() {
102
        // THE module invariant: whatever the environment/app defaults are,
103
        // a system dialog must come out with hw_accel == Disabled.
104
1
        let w = cpu_dialog_window(
105
1
            "t",
106
1
            (100.0, 100.0),
107
1
            dummy_layout as LayoutCallbackType,
108
1
            RefAny::new(0u8),
109
        );
110
1
        assert_eq!(
111
            w.window_state.renderer_options.hw_accel,
112
            HwAcceleration::Disabled
113
        );
114
1
        assert_eq!(w.window_state.title.as_str(), "t");
115
1
        assert!(w.window_state.layout_callback.ctx.is_some());
116
1
    }
117
}