-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c071bf
commit e543bee
Showing
11 changed files
with
85 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,28 @@ | ||
import { invoke } from '@tauri-apps/api/tauri' | ||
import { createMemo, createResource, createSignal } from 'solid-js' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const scan = async (source, { value, refetching }) => { | ||
const { serviceType, scanTime } = source | ||
import { setMdnsStatus, setMdnsData, MdnsStatus } from '@store/mdns/mdns' | ||
|
||
export const useMDNSScanner = (serviceType: string, scanTime: number) => { | ||
if (serviceType === '' || scanTime === 0) { | ||
return [] | ||
} | ||
|
||
console.log('scanning for', serviceType, scanTime) | ||
console.log('[MDNS Scanner]: scanning for', serviceType, scanTime) | ||
|
||
const res = await invoke('run_mdns_query', { | ||
setMdnsStatus(MdnsStatus.LOADING) | ||
invoke('run_mdns_query', { | ||
serviceType, | ||
scanTime, | ||
}) | ||
|
||
if (typeof res === 'string') { | ||
const parsedResponse = JSON.parse(res) | ||
console.log('parsedResponse', parsedResponse) | ||
return parsedResponse | ||
} | ||
return [] | ||
} | ||
|
||
export const useMDNSScanner = () => { | ||
const [service, setService] = createSignal<string>('') | ||
const [scanTime, setScanTime] = createSignal<number>(0) | ||
|
||
const mdnsInitState = createMemo(() => ({ | ||
serviceType: service(), | ||
scanTime: scanTime(), | ||
})) | ||
const [data, { mutate, refetch }] = createResource(mdnsInitState, scan) | ||
return { data, mutate, refetch, setService, setScanTime } | ||
.then((res) => { | ||
if (typeof res === 'string') { | ||
const parsedResponse = JSON.parse(res) | ||
console.log('[MDNS Scanner]: parsedResponse', parsedResponse) | ||
setMdnsStatus(MdnsStatus.ACTIVE) | ||
setMdnsData(parsedResponse) | ||
} | ||
}) | ||
.catch((e) => { | ||
console.error('[MDNS Scanner]: error', e) | ||
setMdnsStatus(MdnsStatus.FAILED) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters