-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathSystemProvider.tsx
38 lines (32 loc) · 1.17 KB
/
SystemProvider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { PowerSyncContext } from '@powersync/react';
import { PowerSyncDatabase, createBaseLogger, LogLevel } from '@powersync/web';
import { CircularProgress } from '@mui/material';
import React, { Suspense } from 'react';
import { AppSchema } from '../../library/powersync/AppSchema.js';
import { BackendConnector } from '../../library/powersync/BackendConnector.js';
import { Capacitor } from '@capacitor/core';
const logger = createBaseLogger();
logger.useDefaults();
logger.setLevel(LogLevel.DEBUG);
const platform = Capacitor.getPlatform();
const isIOs = platform === 'ios';
// Web worker implementation does not work on iOS
const useWebWorker = !isIOs;
const powerSync = new PowerSyncDatabase({
database: { dbFilename: 'powersync2.db' },
schema: AppSchema,
flags: {
enableMultiTabs: false,
useWebWorker
}
});
const connector = new BackendConnector();
powerSync.connect(connector);
export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
return (
<Suspense fallback={<CircularProgress />}>
<PowerSyncContext.Provider value={powerSync}>{children}</PowerSyncContext.Provider>
</Suspense>
);
};
export default SystemProvider;