-
Notifications
You must be signed in to change notification settings - Fork 0
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
b64e4ac
commit 446bc73
Showing
3 changed files
with
157 additions
and
104 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
22 changes: 22 additions & 0 deletions
22
libs/permissions/permissionLogic/src/lib/permission.actions.ts
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
PermissionMachineActions, | ||
PermissionStatuses, | ||
Permissions, | ||
} from './permission.types'; | ||
|
||
export const unimplementedPermissionMachineActions: PermissionMachineActions = { | ||
checkAllPermissions: () => { | ||
return new Promise((resolve) => | ||
resolve({ | ||
[Permissions.bluetooth]: PermissionStatuses.denied, | ||
[Permissions.microphone]: PermissionStatuses.denied, | ||
}) | ||
); | ||
}, | ||
requestBluetoothPermission: () => { | ||
return new Promise((resolve) => resolve(PermissionStatuses.granted)); | ||
}, | ||
requestMicrophonePermission: () => { | ||
return new Promise((resolve) => resolve(PermissionStatuses.granted)); | ||
}, | ||
} as const; |
72 changes: 72 additions & 0 deletions
72
libs/permissions/permissionLogic/src/lib/permission.types.ts
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
export const Permissions = { | ||
bluetooth: 'bluetooth', | ||
microphone: 'microphone', | ||
} as const; | ||
export type Permission = (typeof Permissions)[keyof typeof Permissions]; | ||
export const PermissionStatuses = { | ||
unasked: 'unasked', | ||
granted: 'granted', | ||
denied: 'denied', | ||
revoked: 'revoked', | ||
blocked: 'blocked', | ||
} as const; | ||
export type PermissionStatus = | ||
(typeof PermissionStatuses)[keyof typeof PermissionStatuses]; | ||
|
||
const ApplicationLifecycleEvents = { | ||
applicationForegrounded: 'applicationForegrounded', | ||
applicationBackgrounded: 'applicationBackgrounded', | ||
} as const; | ||
|
||
export type ApplicationLifecycleEvent = | ||
(typeof ApplicationLifecycleEvents)[keyof typeof ApplicationLifecycleEvents]; | ||
|
||
export interface PermissionMachineActions { | ||
checkAllPermissions: () => Promise<PermissionStatusMapType>; | ||
requestBluetoothPermission: () => Promise<PermissionStatus>; | ||
requestMicrophonePermission: () => Promise<PermissionStatus>; | ||
} | ||
|
||
export type PermissionStatusMapType = Record<Permission, PermissionStatus>; | ||
export const InitialPermissionStatusMap: PermissionStatusMapType = { | ||
[Permissions.bluetooth]: PermissionStatuses.unasked, | ||
[Permissions.microphone]: PermissionStatuses.unasked, | ||
} as const; | ||
|
||
export const ApplicationLifecycleStates = { | ||
applicationInForeground: 'application is in foreground', | ||
applicationInBackground: 'application is in background', | ||
} as const; | ||
|
||
export const PermissionCheckingStates = { | ||
idle: 'idle', | ||
checking: 'checking', | ||
} as const; | ||
|
||
export type PermissionMonitoringMachineContext = { | ||
permissionStatuses: PermissionStatusMapType; | ||
}; | ||
export type PermissionMonitoringMachineEvents = | ||
| { type: 'checkPermissions' } | ||
| { | ||
type: 'permissionChecked'; | ||
permission: Permission; | ||
status: PermissionStatus; | ||
} | ||
| { | ||
type: 'triggerPermissionCheck'; | ||
permission: Permission; | ||
} | ||
| { | ||
type: 'triggerPermissionRequest'; | ||
permission: Permission; | ||
} | ||
| { type: 'applicationForegrounded' } | ||
| { type: 'applicationBackgrounded' }; | ||
|
||
export type PermissionMachineEvents = | ||
| { type: 'triggerPermissionCheck' } | ||
| { | ||
type: 'triggerPermissionRequest'; | ||
permission: Permission; | ||
}; |