Works on iphone and android
This commit is contained in:
+6
-7
@@ -3,6 +3,10 @@
|
||||
* Воркер необходим, так как createSyncAccessHandle() доступен только в Worker'ах.
|
||||
*/
|
||||
|
||||
import { Factory } from 'wa-sqlite/src/sqlite-api.js';
|
||||
import { OriginPrivateFileSystemVFS } from 'wa-sqlite/src/examples/OriginPrivateFileSystemVFS.js';
|
||||
import ModuleConstructor from 'wa-sqlite/dist/wa-sqlite-async.mjs';
|
||||
|
||||
let sqlite: any = null;
|
||||
let db: number | null = null;
|
||||
let vfs: any = null;
|
||||
@@ -16,19 +20,13 @@ const OPEN_FLAGS = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
async function init() {
|
||||
if (initialized) return;
|
||||
|
||||
const { Factory } = await import('wa-sqlite/src/sqlite-api.js');
|
||||
const { OriginPrivateFileSystemVFS } = await import(
|
||||
'wa-sqlite/src/examples/OriginPrivateFileSystemVFS.js'
|
||||
);
|
||||
const ModuleConstructor = (await import('wa-sqlite/dist/wa-sqlite-async.mjs')).default;
|
||||
|
||||
const module = await ModuleConstructor();
|
||||
const api = Factory(module);
|
||||
sqlite = api;
|
||||
|
||||
const opfsVfs = new OriginPrivateFileSystemVFS();
|
||||
vfs = opfsVfs;
|
||||
|
||||
vfs = opfsVfs;
|
||||
const rc = api.vfs_register(opfsVfs, true);
|
||||
if (rc) {
|
||||
throw new Error(`Не удалось зарегистрировать OPFS VFS, код ${rc}`);
|
||||
@@ -39,6 +37,7 @@ async function init() {
|
||||
|
||||
initialized = true;
|
||||
self.postMessage({ type: 'ready', ok: true });
|
||||
|
||||
}
|
||||
|
||||
async function execSchema() {
|
||||
|
||||
@@ -31,7 +31,10 @@ function initWorker(): Promise<void> {
|
||||
if (initPromise) return initPromise;
|
||||
|
||||
initPromise = new Promise((resolve, reject) => {
|
||||
worker = new DbWorker();
|
||||
worker = new Worker(
|
||||
new URL('./db-worker.ts', import.meta.url),
|
||||
{ type: 'module' } // <--- ЭТО КЛЮЧЕВОЙ ПАРАМЕТР, КОТОРЫЙ ЛЕЧИТ SAFAFI/iOS
|
||||
);
|
||||
|
||||
worker.onmessage = (e: MessageEvent) => {
|
||||
const msg = e.data;
|
||||
@@ -49,7 +52,7 @@ function initWorker(): Promise<void> {
|
||||
if (msg.ok) {
|
||||
pendingReq.resolve(msg.data);
|
||||
} else {
|
||||
console.log(msg);
|
||||
console.log(msg)
|
||||
pendingReq.reject(new Error(msg.error || 'Неизвестная ошибка Worker'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user