#tauri invoke+react.js

27 messages · Page 1 of 1 (latest)

blazing grove
#

sup guys, i have one problem:

async function isInstalled(clientName: string): Promise<boolean> {
    return await invoke("is_installed", { client: clientName });
}

(async() => {
    console.log(await isInstalled("fold_name"));
})(); // prints false

function isInstalled() {
  const [installed, setInstalled] = useState<boolean | null>(null);

  useEffect(() => {
    const checkInstallation = async () => {
      console.log("i'am here");
      const result = await isInstalled("fold_name");
      setInstalled(result);
      console.log("result:", result);
    };
  
    checkInstallation();
  }, []);
  
  return (
    <>
      <p>{installed ? "yep" : "no"}</p>
    <>
  )
} // prints only i'am here
compact geyser
#

can you share your rust command too? Also, can you log the result above the setInstalled line just to be sure that doesn't block.

blazing grove
# compact geyser can you share your rust command too? Also, can you log the result above the setI...

main.rs

mod client;

fn main() {
  ... some tauri code
  .invoke_handler(tauri::generate_handler![client::is_installed])
}

client.rs

#[allow(unused_variables)]
#[tauri::command]
pub fn is_installed(client: &str) -> bool {
  print("#1");
  let exists =Path::new(&get_client_path(client)).exists();
  print("#2");

  exists
}

in ts:

function isInstalled() {
  const [installed, setInstalled] = useState<boolean | null>(null);

  useEffect(() => {
    const checkInstallation = async () => {
      console.log("i'am here");
      const result = await isInstalled("fold_name");
      console.log("0_o");
      setInstalled(result);
      console.log("result:", result);
    };
  
    checkInstallation();
  }, []);
  
  return (
    <>
      <p>{installed ? "yep" : "no"}</p>
    <>
  )
} // still prints only i'am here
#

well, only invoke is blocking the stream

compact geyser
#

alright. can you make the command async like this ```rs
#[allow(unused_variables)]
#[tauri::command]
pub async fn is_installed(client: &str) -> bool {
print("#1");
let exists =Path::new(&get_client_path(client)).exists();
print("#2");

exists
}


On that note, does #1 / #2 print?
#

If that also doesn't help, i'm afraid i also need the get_client_path code

blazing grove
#

and about make is_installed function async:

#[tauri::command] -> `__tauri_message__` does not live long enough
borrowed value does not live long enough
compact geyser
#

oh right

#

does client: String instead of client: &str work?

blazing grove
#

yep

#

wait a minute, i'll test it

#

no, it doesn't work

compact geyser
#

what about the terminal where you run tauri dev do the numbers get printed?

blazing grove
compact geyser
#

that's so weird

blazing grove
#

well, yep

blazing grove
#

any ideas?

compact geyser
#

Is your repo public?

#

Or can you create a minimal reproduction for me to try?

#

I don't see anything wrong in your screenshots...

blazing grove
#

well, seems like i found answer to this shit, probably invoke doesn't working because i'am using it in iframe

#

yep, its it

#

its weird, but invoke doesn't work in iframe

#

although I can guess why.