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
6
//!    GPU problem — must not depend on the GPU working, so every window this
7
//!    module creates forces `HwAcceleration::Disabled`.
8
//! 2. **Consent is structural.** Nothing sends, installs or overwrites
9
//!    without the user pressing the button that says so. Background threads
10
//!    only CHECK and STAGE.
11
//!
12
//! The dialogs read app-level configuration (support mailbox, manifest URL,
13
//! changelog URL, app name/version) from [`crate::appenv`], which `App::run`
14
//! fills from `AppConfig`. Entry point: `CallbackInfo::invoke_system_dialog`.
15

            
16
// fn-item -> fn-pointer casts: required for the Into<Callback> generics;
17
// the annotated-temporary alternative buries the callback wiring.
18
#![allow(trivial_casts)]
19
pub mod gpu_check;
20
/// Shared report machinery: screenshot REDACTION + the report bundle both
21
/// the problem-report dialog and the crash reporter build.
22
#[cfg(feature = "cpurender")]
23
pub mod report;
24
pub mod markdown;
25
pub mod report_problem;
26
#[cfg(feature = "updater")]
27
pub mod update_version;
28
#[cfg(feature = "telemetry")]
29
pub mod crash_reporter;
30
#[cfg(feature = "telemetry")]
31
pub mod telemetry_consent;
32

            
33
use azul_core::{
34
    geom::LogicalSize,
35
    refany::{OptionRefAny, RefAny},
36
    window::HwAcceleration,
37
};
38
use azul_css::dynamic_selector::{
39
    CssPropertyWithConditions, CssPropertyWithConditionsVec, DynamicSelectorVec,
40
};
41
use azul_css::props::property::CssProperty;
42

            
43
use azul_core::callbacks::LayoutCallbackType;
44
use crate::window_state::WindowCreateOptions;
45

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

            
69
/// Unconditional inline properties (no dynamic-selector conditions).
70
pub(crate) fn style(props: Vec<CssProperty>) -> CssPropertyWithConditionsVec {
71
    props
72
        .into_iter()
73
        .map(|property| CssPropertyWithConditions {
74
            property,
75
            apply_if: DynamicSelectorVec::from_const_slice(&[]),
76
        })
77
        .collect::<Vec<_>>()
78
        .into()
79
}
80

            
81
#[cfg(test)]
82
mod tests {
83
    use azul_core::window::HwAcceleration;
84

            
85
    use super::*;
86
    use azul_core::callbacks::{LayoutCallbackInfo, LayoutCallbackType};
87

            
88
    extern "C" fn dummy_layout(
89
        _: RefAny,
90
        _: LayoutCallbackInfo,
91
    ) -> azul_core::dom::Dom {
92
        azul_core::dom::Dom::create_body()
93
    }
94

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