-
heyo main window async login() {
[...] (generating the url)
const auth_window = new WebviewWindow("oauth_twitch", {
url: link.toString(),
width: 600,
height: 600,
title: "Twitch",
devtools: true,
});
auth_window.once("tauri://created", () => {});
auth_window.once("tauri://error", (err) => toast.error(`Error creating window: ${err.payload}`));
const thisRef = this;
const handleEvent = (event: Event<string>) => {
toast(`got event with key ${event.payload}`);
thisRef.#state.data.token = event.payload;
thisRef.connect();
};
const unlisten = await auth_window.listen<string>('twitch_auth', handleEvent);
unlisten();
}
const parsedHash = new URLSearchParams(window.location.hash.substring(1));
const access_token = parsedHash.get('access_token');
const tauriWindow = window.__TAURI__.window.getCurrentWindow();
tauriWindow.emit("twitch_auth", access_token).then(() => console.log("token sent")); i get "token sent" in this other window, and nothing in the main window also tried to emitTo to the main window, didn't work either |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
ok i was being a moron i don't know if you're supposed to do it that way, cause there might be some obscure case i'm not thinking about where the function can exit without unlistening but not a huge issue i guess |
Beta Was this translation helpful? Give feedback.
ok i was being a moron
basically i thought the listen would await until getting a response, and then it would unlisten, but the await is to setup the listener?
anyway i passed the unlistener to my object and accessed it with thisRef inside handleEvent
i don't know if you're supposed to do it that way, cause there might be some obscure case i'm not thinking about where the function can exit without unlistening but not a huge issue i guess