-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add shutdown methods stop scan stop advertise and status #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
morrieinmaas
merged 16 commits into
animo:main
from
morrieinmaas:feat/shutdown-and-attrs
Jun 7, 2023
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b05aa88
feat: add shutdown methods stop scan stop advertise and status
190afaa
fix: android build
7f7cfcf
chore: remove redundant stop methods
95a050b
fix: ios build
f40b366
chore: remove redundant decorator
5c52208
chore: slight fix for exception handling in shutdown
3daa4b1
chore: code review feedback
b5b4da1
chore: more feedback
22984ce
chore: more review feedback
9330e3c
chore: more feedback
edbd7f0
chore: code review feedback
6a0f469
chore: code review feedback
f1a8f12
chore: code review feedback
4c7b15d
chore: add providers to use hooks
06da6d2
chore: format
2c11f45
chore: code review feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { Central } from './central' | ||
| import type { PropsWithChildren } from 'react' | ||
|
|
||
| import { useContext, useEffect, useState } from 'react' | ||
| import * as React from 'react' | ||
|
|
||
| interface CentralContextInterface { | ||
| loading: boolean | ||
| central?: Central | undefined | ||
| } | ||
|
|
||
| interface CentralProps { | ||
| central: Central | undefined | ||
| } | ||
|
|
||
| export const CentralContext = React.createContext< | ||
| CentralContextInterface | undefined | ||
| >(undefined) | ||
|
|
||
| export const useCentral = () => { | ||
| const peripheralContext = useContext(CentralContext) | ||
| if (!peripheralContext) { | ||
| throw new Error('useAgent must be used within a AgentContextProvider') | ||
morrieinmaas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return peripheralContext | ||
| } | ||
|
|
||
| const PeripheralProvider: React.FC<PropsWithChildren<CentralProps>> = ({ | ||
| central, | ||
| children, | ||
| }) => { | ||
| const [centralState, setCentralState] = useState<CentralContextInterface>({ | ||
| loading: true, | ||
| central: central, | ||
| }) | ||
|
|
||
| const setInitialState = async () => { | ||
| if (central) { | ||
| setCentralState({ central: central, loading: false }) | ||
| } | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| setInitialState() | ||
| }, [centralState]) | ||
morrieinmaas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <CentralContext.Provider value={centralState}> | ||
| {children} | ||
| </CentralContext.Provider> | ||
| ) | ||
| } | ||
|
|
||
| export default PeripheralProvider | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import type { PropsWithChildren } from 'react' | ||
| import type { Peripheral } from './peripheral' | ||
|
|
||
| import { useContext, useEffect, useState } from 'react' | ||
| import * as React from 'react' | ||
|
|
||
| interface PeripheralContextInterface { | ||
| loading: boolean | ||
| peripheral?: Peripheral | undefined | ||
| } | ||
|
|
||
| interface PeripheralProps { | ||
| peripheral: Peripheral | undefined | ||
| } | ||
|
|
||
| export const PeripheralContext = React.createContext< | ||
| PeripheralContextInterface | undefined | ||
| >(undefined) | ||
|
|
||
| export const usePeripheral = () => { | ||
| const peripheralContext = useContext(PeripheralContext) | ||
| if (!peripheralContext) { | ||
| throw new Error('useAgent must be used within a AgentContextProvider') | ||
morrieinmaas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return peripheralContext | ||
| } | ||
|
|
||
| const PeripheralProvider: React.FC<PropsWithChildren<PeripheralProps>> = ({ | ||
| peripheral, | ||
| children, | ||
| }) => { | ||
| const [peripheralState, setPeripheralState] = useState< | ||
| PeripheralContextInterface | ||
| >({ | ||
| loading: true, | ||
| peripheral: peripheral, | ||
| }) | ||
|
|
||
| const setInitialState = async () => { | ||
| if (peripheral) { | ||
| setPeripheralState({ peripheral: peripheral, loading: false }) | ||
| } | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| setInitialState() | ||
| }, [peripheralState]) | ||
|
|
||
| return ( | ||
| <PeripheralContext.Provider value={peripheralState}> | ||
| {children} | ||
| </PeripheralContext.Provider> | ||
| ) | ||
| } | ||
|
|
||
| export default PeripheralProvider | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.