|
@@ -1,11 +1,12 @@
|
|
-import { tryOnBeforeMount, tryOnUnmounted } from '@vueuse/core';
|
|
|
|
|
|
+import { tryOnBeforeMount, tryOnUnmounted, useDebounceFn } from '@vueuse/core';
|
|
import type { BridgeEventMap } from '../../../@types/bridge';
|
|
import type { BridgeEventMap } from '../../../@types/bridge';
|
|
|
|
|
|
export type ScanData = NonNullable<BridgeEventMap['scan']['detail']['data']>;
|
|
export type ScanData = NonNullable<BridgeEventMap['scan']['detail']['data']>;
|
|
|
|
|
|
-export function useScan(callback: (data: ScanData) => void) {
|
|
|
|
|
|
+export function useScan(fn: (data: ScanData) => void) {
|
|
|
|
+ const callback = useDebounceFn(fn, 300)
|
|
let onCleanup = () => {};
|
|
let onCleanup = () => {};
|
|
- tryOnBeforeMount(() => {
|
|
|
|
|
|
+ tryOnBeforeMount(async () => {
|
|
if (window.bridge) {
|
|
if (window.bridge) {
|
|
onCleanup = window.bridge.addEventListener('scan', (event) => {
|
|
onCleanup = window.bridge.addEventListener('scan', (event) => {
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|