install_framework_gui/lib.rs
1// Copyright 2021 Yuri6037
2
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"),
5// to deal in the Software without restriction, including without limitation
6// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7// and/or sell copies of the Software, and to permit persons to whom the
8// Software is furnished to do so, subject to the following conditions:
9
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
21use install_framework_core::interface::ConstructibleInterface;
22use install_framework_core::builder::InstallerBuilder;
23use async_channel::unbounded;
24
25mod messages;
26mod error;
27mod interpreter;
28mod renderer;
29mod interface;
30mod ext;
31
32pub use interface::GuiInterface;
33use messages::RenderMessage;
34use messages::ThreadMessage;
35
36impl ConstructibleInterface<'_> for GuiInterface
37{
38 fn run(builder: InstallerBuilder) -> i32
39 {
40 let code = crossbeam::scope(move |s|
41 {
42 let (sender, receiver) = unbounded::<RenderMessage>();
43 let (sender1, receiver1) = unbounded::<ThreadMessage>();
44 let handle = s.spawn(|_|
45 {
46 let link = interface::ThreadLinker::new(sender, receiver1);
47 let mut interface = interface::GuiInterface::new(link);
48 let mut b = builder;
49 return b.run(&mut interface);
50 });
51 if let Err(e) = renderer::rendering_loop(sender1, receiver)
52 {
53 eprintln!("GUI engine failure {}", e);
54 return 5;
55 }
56 match handle.join()
57 {
58 Ok(v) => return v,
59 Err(e) =>
60 {
61 eprintln!("Internal application error: thread panic: {:?}", e);
62 return 7;
63 }
64 };
65 }).unwrap();
66 return code;
67 }
68}