| 1 | #![allow(unused)] |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/; |
| 4 | |
| 5 | pub fn setuprust-analyzer cargo notify-rust 4.18.0 common/setup().(example_file: &str) -> bool { |
| 6 | cfg_ifrust-analyzer cargo cfg-if 1.0.4 crate/::cfg_ifrust-analyzer cargo cfg-if 1.0.4 cfg_if!! { |
| 7 | if #[cfg(all(target_os = "macos", not(feature = "preview-macos-un")))] { |
| 8 | env_loggerrust-analyzer cargo env_logger 0.11.11 crate/::initrust-analyzer cargo env_logger 0.11.11 logger/init().(); |
| 9 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("setup env_logger"); |
| 10 | |
| 11 | // for NSUserNotifications we need to set the application bundle identifier to the default of safari |
| 12 | let bundle_id = notify_rustrust-analyzer cargo notify-rust 4.18.0 crate/::get_bundle_identifier_or_default("safari"); |
| 13 | notify_rustrust-analyzer cargo notify-rust 4.18.0 crate/::set_application(&bundle_id).unwrap(); |
| 14 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("set_application: {bundle_id}"); |
| 15 | true |
| 16 | } else if #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] { |
| 17 | // for UNUserNotifications we need to log to the system log |
| 18 | // and request authorization |
| 19 | oslog::OsLogger::new("notify-rust") |
| 20 | .level_filter(logrust-analyzer cargo log 0.4.34 crate/::LevelFilterrust-analyzer cargo log 0.4.34 LevelFilter#::Tracerust-analyzer cargo log 0.4.34 LevelFilter#Trace#) |
| 21 | .init() |
| 22 | .unwrap(); |
| 23 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("setup oslog"); |
| 24 | notify_rustrust-analyzer cargo notify-rust 4.18.0 crate/::request_auth_blocking(); |
| 25 | |
| 26 | true |
| 27 | } else { |
| 28 | env_loggerrust-analyzer cargo env_logger 0.11.11 crate/::initrust-analyzer cargo env_logger 0.11.11 logger/init().(); |
| 29 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("setup env_logger"); |
| 30 | true |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | pub fn run_main_loop_whilerust-analyzer cargo notify-rust 4.18.0 common/run_main_loop_while().<T>(thread: threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::JoinHandlerust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/join_handle/JoinHandle#<T>) -> threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/Result#<T> { |
| 36 | #[cfg(target_os = "macos")] |
| 37 | { |
| 38 | use objc2_foundation::{NSDate, NSDefaultRunLoopMode, NSRunLoop}; |
| 39 | let run_loop = NSRunLoop::mainRunLoop(); |
| 40 | while !threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/.is_finished() { |
| 41 | let until = NSDate::dateWithTimeIntervalSinceNow(0.05); |
| 42 | unsafe { run_loop.runMode_beforeDate(NSDefaultRunLoopMode, &until) }; |
| 43 | } |
| 44 | threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/.join() |
| 45 | } |
| 46 | |
| 47 | #[cfg(not(target_os = "macos"))] |
| 48 | thread.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/join_handle/impl#[`JoinHandle<T>`]join().() |
| 49 | } |
| 50 | |
| 51 | /// Blocks until the user presses a key or timeout is reached (in bundle context). |
| 52 | pub fn wait_for_keypressrust-analyzer cargo notify-rust 4.18.0 common/wait_for_keypress().(msg: &str) { |
| 53 | #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] |
| 54 | { |
| 55 | if mac_usernotifications::check_bundle().is_ok() { |
| 56 | // Running in a bundle - use timeout instead |
| 57 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::mpscrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/mpsc/, threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/, timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#}; |
| 58 | logrust-analyzer cargo log 0.4.34 crate/::inforust-analyzer cargo log 0.4.34 macros/info!!("{msg}, will timeout in 4 seconds"); |
| 59 | |
| 60 | let (sender, receiver) = mpsc::channel(); |
| 61 | let timeout_sender = sender.clone(); |
| 62 | |
| 63 | threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/spawn().(move || { |
| 64 | threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::sleeprust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/sleep().(Duration::from_secs(4)); |
| 65 | let _ = timeout_sender.send(()); |
| 66 | }); |
| 67 | |
| 68 | let _ = receiver.recv(); |
| 69 | return; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Not in bundle (or not macOS) - wait for keypress |
| 74 | logrust-analyzer cargo log 0.4.34 crate/::inforust-analyzer cargo log 0.4.34 macros/info!!("{}", msg); |
| 75 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]read_line().(&mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 76 | } |