Debian Codegraph @

podcasts-gtk/src/main.rs

raw symbols SCIP
1 // main.rs
2 //
3 // Copyright 2017 Jordan Petridis <[email protected]>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // SPDX-License-Identifier: GPL-3.0-or-later
19
20 use gtk::{gio, glib};
21
22 #[macro_use]
23 extern crate log;
24
25 #[macro_use]
26 extern crate html5ever;
27
28 // Exports the macros defined in utils to the namespace of the crate so they can be used
29 // easily without import
30 #[macro_use]
31 mod utils;
32
33 // Auto generated by meson.build
34 #[rustfmt::skip]
35 mod config;
36
37 mod app;
38 mod chapter_parser;
39 mod download_covers;
40 mod episode_description_parser;
41 mod feed_manager;
42 mod i18n;
43 mod manager;
44 mod settings;
45 mod thumbnail_generator;
46 mod widgets;
47 mod window;
48
49 use crate::app::PdApplication;
50 pub use crate::thumbnail_generator::ThumbSize::*;
51
52 use std::sync::LazyLock;
53
54 // tokio should be used when doing http fetches, since reqwest depens on it.
55 pub static RUNTIME: LazyLock<tokio::runtime::Runtime> =
56 LazyLock::new(|| tokio::runtime::Runtime::new().unwrap());
57
58 pub static MAINCONTEXT: LazyLock<glib::MainContext> = LazyLock::new(glib::MainContext::default);
59 pub static CHRONO_LOCALE: LazyLock<chrono::Locale> = LazyLock::new(|| {
60 use std::str::FromStr;
61 let system_locale = locale_config::Locale::current();
62 let time_locale = system_locale.tags_for("time").next();
63 let time_locale_str = time_locale.as_ref().map(|l| l.as_ref()).unwrap_or("C");
64 let unix_formatted = time_locale_str.replace('-', "_");
65 chrono::Locale::from_str(&unix_formatted).unwrap_or(chrono::Locale::POSIX)
66 });
67
68 #[cfg(test)]
69 fn init_gtk_tests() -> anyhow::Result<()> {
70 gst::init()?;
71 gtk::init()?;
72 adw::init()?;
73 register_resources()?;
74 Ok(())
75 }
76
77 fn main() -> glib::ExitCode {
78 pretty_env_logger::init();
79 gst::init().expect("Error initializing gstreamer");
80 gtk::init().expect("Error initializing gtk.");
81 register_resources().expect("Error registering resources");
82
83 PdApplication::run()
84 }
85
86 fn register_resources() -> anyhow::Result<()> {
87 // Create Resource it will live as long the value lives.
88 let gbytes = glib::Bytes::from_static(crate::config::RESOURCEFILE);
89 let resource = gio::Resource::from_data(&gbytes)?;
90
91 // Register the resource so it won't be dropped and will continue to live in
92 // memory.
93 gio::resources_register(&resource);
94
95 Ok(())
96 }
97
98 #[test]
99 // Even while running the tests with -j 1 and --test-threads=1,
100 // cargo seems to create new threads and gtk refuses to initialize again.
101 // So we run every gtk related test here.
102 fn test_stuff() -> anyhow::Result<()> {
103 use crate::widgets::*;
104
105 init_gtk_tests()?;
106
107 // If a widget does not exist in the `GtkBuilder`(.ui) file this should panic and fail.
108 BaseView::default();
109 ShowWidget::default();
110 HomeEpisode::default();
111 EpisodeWidget::default();
112
113 show_menu::ShowMenu::default();
114 episode_menu::EpisodeMenu::default();
115
116 Ok(())
117 }