init_rust_components/
lib.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 */
5
6#[cfg(not(feature = "keydb"))]
7use nss::ensure_initialized as ensure_nss_initialized;
8#[cfg(feature = "keydb")]
9use nss::ensure_initialized_with_profile_dir as ensure_nss_initialized_with_profile_dir;
10#[cfg(feature = "ohttp")]
11use viaduct::ohttp::configure_default_ohttp_channels;
12uniffi::setup_scaffolding!();
13
14/// Global initialization routines for Rust components. Must be called before any other calls to
15/// Rust components.
16///
17/// For adding additional initialization code: Note that this function is called very early in the
18/// app lifetime and therefore affects the startup time. Only the most necessary things should be
19/// done here.
20#[cfg(not(feature = "keydb"))]
21#[uniffi::export]
22pub fn initialize() {
23    ensure_nss_initialized();
24
25    #[cfg(feature = "ohttp")]
26    {
27        configure_default_ohttp_channels()
28            .expect("We pass down hard coded Strings for the relays, if this fails, we have a typo in the config we pass down.");
29    }
30}
31
32/// Global initialization routines for Rust components, when `logins/keydb` feature is activated. Must be
33/// called before any other calls to Rust components.
34///
35/// Receives the path to the profile directory.
36///
37/// For adding additional initialization code: Note that this function is called very early in the
38/// app lifetime and therefore affects the startup time. Only the most necessary things should be
39/// done here.
40#[cfg(feature = "keydb")]
41#[uniffi::export]
42pub fn initialize(profile_path: String) {
43    ensure_nss_initialized_with_profile_dir(profile_path);
44
45    #[cfg(feature = "ohttp")]
46    {
47        configure_default_ohttp_channels()
48            .expect("We pass down hard coded Strings for the relays, if this fails, we have a typo in the config we pass down.");
49    }
50}