Skip to main content

zu_icons_util/
lib.rs

1// Copyright (c) 2024 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Apache-2.0 License
3// that can be found in the LICENSE file.
4
5pub mod icon_list;
6pub mod module;
7pub mod svg;
8
9use std::{fs, io};
10
11pub const UPDATE_ZU_ICONS: &str = "UPDATE_ZU_ICONS";
12pub const UPDATE_ICONS_PAGE: &str = "UPDATE_ICONS_PAGE";
13
14/// Check whether icon crate shall be refreshed.
15///
16/// Set `UPDATE_ZU_ICONS=1` environment to force update all icons.
17#[inline]
18#[must_use]
19pub fn need_update() -> bool {
20    std::env::var_os(UPDATE_ZU_ICONS).is_some_and(|val| val != "0" && val != "false")
21}
22
23#[inline]
24#[must_use]
25pub fn need_update_icons_page() -> bool {
26    std::env::var_os(UPDATE_ICONS_PAGE).is_some_and(|val| val != "0" && val != "false")
27}
28
29/// Remove all files in `src/` directory of crate
30///
31/// # Errors
32///
33/// Returns `Err` if the `src/` directory cannot be removed or recreated.
34pub fn reset_crate_source() -> Result<(), io::Error> {
35    fs::remove_dir_all("src")?;
36    fs::create_dir("src")?;
37    fs::write("src/lib.rs", "")
38}