changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / rust/ui/alik/examples/installer.rs

changeset 698: 96958d3eb5b0
parent: bea77d97c6b2
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 //! installer.rs --- Alik Installer Example
2 
3 //
4 
5 //! Code:
6 use std::future::Future;
7 
8 #[cfg(not(target_arch = "wasm32"))]
9 fn execute<F: Future<Output = ()> + Send + 'static>(f: F) {
10  // this is stupid... use any executor of your choice instead
11  std::thread::spawn(move || futures::executor::block_on(f));
12 }
13 #[cfg(target_arch = "wasm32")]
14 fn execute<F: Future<Output = ()> + 'static>(f: F) {
15  wasm_bindgen_futures::spawn_local(f);
16 }
17 
18 fn main() -> Result<(), Box<dyn std::error::Error>> {
19  // sync
20  let res = rfd::MessageDialog::new()
21  .set_title("Msg!")
22  .set_description("Description!")
23  .set_buttons(rfd::MessageButtons::OkCancel)
24  .show();
25  println!("{}", res);
26  // async
27  let task = rfd::AsyncFileDialog::new().pick_file();
28 
29  // Await somewhere else
30  execute(async {
31  let file = task.await;
32 
33  if let Some(file) = file {
34  // If you are on native platform you can just get the path
35  #[cfg(not(target_arch = "wasm32"))]
36  println!("{:?}", file.path());
37  // on wasm just file.read().await;
38  }
39  });
40  eframe::run_native(
41  "alik_installer_example",
42  eframe::NativeOptions::default(),
43  Box::new(|cc| Box::new(alik_ui::AlikApp::new(cc))),
44  )
45  .unwrap();
46  Ok(())
47 }