1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4#![cfg_attr(feature = "mcu-board-support", no_std)]
5
6#[cfg(feature = "mcu-board-support")]
7extern crate alloc;
8
9#[cfg(target_arch = "wasm32")]
10use wasm_bindgen::prelude::*;
11
12pub mod ui {
13 slint::include_modules!();
14}
15
16use slint::*;
17use ui::*;
18
19#[cfg(not(feature = "mcu-board-support"))]
20mod controllers {
21 #[cfg(feature = "chrono")]
22 pub mod header;
23 #[cfg(feature = "network")]
24 pub mod weather;
25}
26#[cfg(not(feature = "mcu-board-support"))]
27use controllers::*;
28
29#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
30pub fn main() {
31 // This provides better error messages in debug mode.
32 // It's disabled in release mode so it doesn't bloat up the file size.
33 #[cfg(all(debug_assertions, target_arch = "wasm32"))]
34 console_error_panic_hook::set_once();
35
36 let window: MainWindow = MainWindow::new().unwrap();
37
38 // let _ to keep the timer alive.
39 #[cfg(all(not(feature = "mcu-board-support"), feature = "chrono"))]
40 let _timer: Timer = header::setup(&window);
41
42 #[cfg(all(not(feature = "mcu-board-support"), feature = "network"))]
43 let weather_join: JoinHandle<()> = weather::setup(&window);
44
45 let _kiosk_mode_timer: Timer = kiosk_timer(&window);
46
47 window.run().unwrap();
48
49 #[cfg(all(not(feature = "mcu-board-support"), feature = "network"))]
50 weather_join.join().unwrap();
51}
52
53fn kiosk_timer(window: &MainWindow) -> Timer {
54 let kiosk_mode_timer: Timer = Timer::default();
55 kiosk_mode_timer.start(mode:TimerMode::Repeated, interval:core::time::Duration::from_secs(4), {
56 let window_weak: Weak = window.as_weak();
57 move || {
58 if !SettingsAdapter::get(&window_weak.unwrap()).get_kiosk_mode_checked() {
59 return;
60 }
61
62 let current_page: i32 = MenuOverviewAdapter::get(&window_weak.unwrap()).get_current_page();
63 let count: i32 = MenuOverviewAdapter::get(&window_weak.unwrap()).get_count();
64
65 if current_page >= count - 1 {
66 MenuOverviewAdapter::get(&window_weak.unwrap()).set_current_page(0);
67 } else {
68 MenuOverviewAdapter::get(&window_weak.unwrap()).set_current_page(current_page + 1);
69 }
70 }
71 });
72
73 kiosk_mode_timer
74}
75
76#[cfg(target_os = "android")]
77#[no_mangle]
78fn android_main(app: slint::android::AndroidApp) {
79 slint::android::init(app).unwrap();
80 main();
81}
82