mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-08 08:10:29 +03:00
Pass client config for togglePusher
This commit is contained in:
parent
39fa3c49b1
commit
91d6a5d2e9
1 changed files with 6 additions and 5 deletions
|
|
@ -38,6 +38,7 @@ import { useSyncState } from '../../hooks/useSyncState';
|
||||||
import { stopPropagation } from '../../utils/keyboard';
|
import { stopPropagation } from '../../utils/keyboard';
|
||||||
import { SyncStatus } from './SyncStatus';
|
import { SyncStatus } from './SyncStatus';
|
||||||
import { togglePusher } from '../../features/settings/notifications/PushNotifications';
|
import { togglePusher } from '../../features/settings/notifications/PushNotifications';
|
||||||
|
import { ClientConfig, useClientConfig } from '../../hooks/useClientConfig';
|
||||||
|
|
||||||
function ClientRootLoading() {
|
function ClientRootLoading() {
|
||||||
return (
|
return (
|
||||||
|
|
@ -125,12 +126,11 @@ function ClientRootOptions({ mx }: { mx?: MatrixClient }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pushNotificationListener = (mx: MatrixClient) => {
|
const pushNotificationListener = (mx: MatrixClient, clientConfig: ClientConfig) => {
|
||||||
navigator.serviceWorker.ready.then((registration) => {
|
navigator.serviceWorker.ready.then((registration) => {
|
||||||
registration.pushManager.getSubscription().then((subscription) => {
|
registration.pushManager.getSubscription().then((subscription) => {
|
||||||
document.addEventListener('visibilitychange', () => {
|
document.addEventListener('visibilitychange', () => {
|
||||||
console.log('Check check baby');
|
togglePusher(mx, subscription, clientConfig, document.visibilityState === 'visible');
|
||||||
togglePusher(mx, subscription, document.visibilityState === 'visible');
|
|
||||||
});
|
});
|
||||||
togglePusher(mx, subscription, true);
|
togglePusher(mx, subscription, true);
|
||||||
});
|
});
|
||||||
|
|
@ -159,6 +159,7 @@ type ClientRootProps = {
|
||||||
export function ClientRoot({ children }: ClientRootProps) {
|
export function ClientRoot({ children }: ClientRootProps) {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const { baseUrl } = getSecret();
|
const { baseUrl } = getSecret();
|
||||||
|
const clientConfig = useClientConfig();
|
||||||
|
|
||||||
const [loadState, loadMatrix] = useAsyncCallback<MatrixClient, Error, []>(
|
const [loadState, loadMatrix] = useAsyncCallback<MatrixClient, Error, []>(
|
||||||
useCallback(() => initClient(getSecret() as any), [])
|
useCallback(() => initClient(getSecret() as any), [])
|
||||||
|
|
@ -188,10 +189,10 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||||
(state) => {
|
(state) => {
|
||||||
if (state === 'PREPARED') {
|
if (state === 'PREPARED') {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
pushNotificationListener(mx);
|
pushNotificationListener(mx, clientConfig);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[mx]
|
[clientConfig, mx]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue