blooemu 0.0.2

the best library for OS API's manipulation
Documentation
mod popups;
mod hiderun;

use crate::popups::{alert_message, error_message};
use std::env;
use std::process::Command;


pub fn open(path: &str) {
    let os = env::consts::OS;

    let mut command = match os {
        "windows" => {
            let mut command = Command::new("cmd");
            command.args(["/C", path]);
            command
        }
        "linux" | "macos" => {
            let mut command = Command::new("xdg-open");
            command.arg(path);
            command
        }
        _ => {
            eprintln!("Unsupported operating system: {}", os);
            return;
        }
    };

    match command.spawn() {
        Ok(_) => {}
        Err(err) => eprintln!("Failed to open {}: {}", path, err),
    }
}


#[macro_export]
macro_rules! alert {
    ($msg:expr) => {
        $crate::alert_message($msg, "Alert", None, None, None);
    };
    ($msg:expr, $title:expr) => {
        $crate::alert_message($msg, $title, None, None, None);
    };
    ($msg:expr, $title:expr, $buttons:expr) => {
        $crate::alert_message($msg, $title, Some($buttons), None, None);
    };
    ($msg:expr, $title:expr, $buttons:expr, $yes_callback:expr) => {
        $crate::alert_message($msg, $title, Some($buttons), Some($yes_callback), None);
    };
    ($msg:expr, $title:expr, $buttons:expr, $yes_callback:expr, $no_callback:expr) => {
        $crate::alert_message(
            $msg,
            $title,
            Some($buttons),
            Some($yes_callback),
            Some($no_callback),
        );
    };
}

#[macro_export]
macro_rules! error {
    ($msg:expr) => {
        $crate::error_message($msg, "Error", None);
    };
    ($msg:expr, $title:expr) => {
        $crate::error_message($msg, $title, None);
    };
    ($msg:expr, $title:expr, $callback:expr) => {
        $crate::error_message($msg, $title, Some($callback));
    };
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_error_message() {
        let message = "Test error message";
        error_message(message, "Test Error Title", None);
    }

    #[test]
    fn test_open() {
        let path = "C:/Users/Happy PC/Desktop/test.txt";
        open(path);
    }

    #[test]
    fn test_alert_macro() {
        alert!(
            "Test with yes and no callbacks",
            "Custom Title",
            "yesno",
            || {
                error!("you choose yes");
            },
            || {
                error!("you choose no");
            }
        );
    }

    #[test]
    fn test_error_macro() {
        error!("Test error macro");
        error!("Test error with title", "Critical Error");
        error!("Test error with callback", "Critical Error", || {
            println!("Error callback executed");
        });
    }
}