mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 11:23:34 +02:00
Plugin execution context (#119)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { EventCallback, EventName, Options } from '@tauri-apps/api/event';
|
||||
import type { EventCallback, EventName } from '@tauri-apps/api/event';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import type { DependencyList } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
@@ -9,14 +10,18 @@ import { useEffect } from 'react';
|
||||
export function useListenToTauriEvent<T>(
|
||||
event: EventName,
|
||||
fn: EventCallback<T>,
|
||||
options: Options | undefined = undefined,
|
||||
deps: DependencyList = [],
|
||||
) {
|
||||
useEffect(() => {
|
||||
let unMounted = false;
|
||||
let unsubFn: (() => void) | undefined = undefined;
|
||||
|
||||
listen(event, fn, options).then((unsub) => {
|
||||
listen(
|
||||
event,
|
||||
fn,
|
||||
// Listen to `emit_all()` events or events specific to the current window
|
||||
{ target: { label: getCurrentWebviewWindow().label, kind: 'Window' } },
|
||||
).then((unsub) => {
|
||||
if (unMounted) unsub();
|
||||
else unsubFn = unsub;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user