ferrix_app/utils.rs
1/* styles.rs
2 *
3 * Copyright 2025 Michail Krasnov <mskrasnov07@ya.ru>
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 <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21//! Utilities and helper functions
22
23use anyhow::Result;
24use iced::Color;
25use std::{
26 env,
27 path::{Path, PathBuf},
28 process::Command,
29};
30
31pub fn xdg_open<O: ToString>(object: O) -> Result<()> {
32 Command::new("/usr/bin/xdg-open")
33 .arg(object.to_string())
34 .spawn()?;
35 Ok(())
36}
37
38pub fn get_home() -> PathBuf {
39 let home_env = env::var("HOME").unwrap_or("/tmp".to_string());
40
41 Path::new(&home_env).to_path_buf()
42}
43
44pub trait ToColor {
45 fn to_color(&self) -> Color;
46}
47
48impl ToColor for (u8, u8, u8) {
49 fn to_color(&self) -> Color {
50 Color::from_rgb8(self.0, self.1, self.2)
51 }
52}