1#[macro_use]
12extern crate bitflags;
13
14#[cfg(windows)]
20extern crate winapi;
21
22#[cfg(windows)]
23extern crate windows;
24
25#[cfg(windows)]
26pub(crate) mod bindings{
27 ::windows::include_bindings!();
28}
29
30#[cfg(target_os = "macos")]
34#[macro_use]
35extern crate objc;
36
37#[cfg(target_os = "macos")]
38extern crate cocoa;
39
40#[doc(hidden)]
50pub mod core;
51
52#[doc(hidden)]
56pub mod internal;
57
58pub mod processes;
62pub mod metadata;
66pub mod dialogues;
70
71pub mod notifications;
75
76#[cfg(windows)]
84pub fn obtain_error() -> u32 {
85 use winapi::um::errhandlingapi::GetLastError;
86 unsafe {
87 return GetLastError();
88 }
89}
90#[cfg(test)]
96#[cfg(windows)]
97mod tests {
98 use std::fs::File;
99 use std::ops::Add;
100 use std::path::{Path, PathBuf};
101
102 use crate::metadata::time::{FileTime, set_creation_date};
103 use crate::metadata::attribute::{set_attribute, Attributes, has_attribute, get_attributes};
104 use crate::processes::processes::find_process_id;
105 use crate::dialogues::filebox::{Filter};
106 use crate::obtain_error;
107 use crate::dialogues::messagebox::{MessageBox, WindowType, IconType};
108 use crate::dialogues::filebox::FileBox;
109 use crate::notifications::notification::SimpleNotification;
110
111 #[test]
112 fn it_works() {
113 let notif = SimpleNotification::new("Rust Notification".to_string())
137 .set_app_id("{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe".to_string())
138 .add_text("This notification was sent via rust!".to_string())
139 .add_text("This uses the Windows Notification Center.".to_string())
140 .set_hero_image("http://picsum.photos/48?image=883".to_string())
141 .display();
142 }
143}
144
145#[cfg(test)]
151#[cfg(unix)]
152mod tests {
153 use std::fs::File;
154 use std::path::Path;
155
156 use crate::metadata::time::{FileTime, set_creation_date, set_accessed_date, set_changed_date, filetime_to_systime};
157 use crate::metadata::attribute::{set_attribute, Attributes, get_attributes};
158 use crate::processes::processes::{find_process_id, is_process_running};
159 use std::io::Write;
160 use crate::dialogues::filebox::FileBox;
161 use crate::dialogues::messagebox::{MessageBox, IconType, WindowType};
162
163 #[test]
164 fn it_works() {
165 let val = find_process_id(get_test_process()).expect("An error occurred!");
166 println!("{:?}", val);
167 let pid : u32 = 1818;
169 println!("{:?}", is_process_running(&pid));
170
171 let time = FileTime {
172 day: 13,
173 month: 3,
174 year: 2022,
175 hour: 2,
176 minute: 46,
177 second: 46,
178 milliseconds: 0
179 };
180 let systime = filetime_to_systime(&time);
181 assert_eq!(systime,"202203130246.46");
182 set_creation_date(Path::new("./test.txt"), &time);
183 set_changed_date( Path::new("./test.txt"), &time);
184 set_accessed_date( Path::new("./test.txt"), &time);
185 }
186 #[test]
187 fn dialog_open_box() {
188 let option = FileBox::new().filter("Text", "*.txt")
189 .directory(Path::new("/home/")).open();
190 println!("{}", option.unwrap().to_str().unwrap());
191 }
192 #[test]
193 fn dialog_save_box() {
194 let option = FileBox::new().filter("Text", "*.txt")
195 .directory(Path::new("/home/")).save("test.txt");
196 println!("{}", option.unwrap().to_str().unwrap());
197 }
198 #[test]
199 fn message_box() {
200 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
201 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::OK_CANCEL)
202 .show();
203 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
204 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::OK)
205 .show();
206 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
207 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::RETRY_CANCEL)
208 .show();
209 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
210 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::HELP)
211 .show();
212 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
213 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::YES_NO_CANCEL)
214 .show();
215 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
216 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::YES_NO)
217 .show();
218 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
219 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::CANCEL_TRY_CONTINUE)
220 .show();
221 let mut r = MessageBox::new("This is a test!", "Wow I figured out GTK!")
222 .set_icon_type(IconType::ICON_WARNING).set_window_type(WindowType::ABORT_RETRY_IGNORE)
223 .show();
224 }
225 fn get_test_process() -> &'static str {
226 if cfg!(target_os = "macos") {
227 "launchd"
228 } else if cfg!(target_os = "linux") {
229 "NetworkManager"
230 } else { "" }
231 }
232
233
234
235 }