Skip to content

Commit

Permalink
A few bugfixes to support Vanilla Pack Viewer on Native
Browse files Browse the repository at this point in the history
  • Loading branch information
outercloudstudio committed Jul 12, 2024
1 parent 82dc4f7 commit 832f166
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/components/Extensions/Scripts/Modules/fs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { App } from '/@/App'
import { FileSystem } from '/@/components/FileSystem/FileSystem'
import { IModuleConfig } from '../types'
import {
AnyDirectoryHandle,
AnyFileHandle,
} from '/@/components/FileSystem/Types'
import { VirtualFileHandle } from '/@/components/FileSystem/Virtual/FileHandle'
import { VirtualDirectoryHandle } from '/@/components/FileSystem/Virtual/DirectoryHandle'
import {
ISerializedDirectoryHandle,
ISerializedFileHandle,
} from '/@/components/FileSystem/Virtual/Comlink'

export const FSModule = ({ disposables }: IModuleConfig) => {
return new Promise<FileSystem>((resolve) => {
Expand All @@ -9,6 +19,33 @@ export const FSModule = ({ disposables }: IModuleConfig) => {
onBridgeFolderSetup: (cb: () => Promise<void> | void) => {
disposables.push(app.bridgeFolderSetup.once(cb, true))
},
serializeHandle(handle: AnyFileHandle | AnyDirectoryHandle) {
if (
handle instanceof VirtualFileHandle ||
handle instanceof VirtualDirectoryHandle
) {
return handle.serialize()
}

return handle
},
deserializeHandle(
serializedHandle:
| FileSystemHandle
| ISerializedFileHandle
| ISerializedDirectoryHandle
) {
if (serializedHandle instanceof FileSystemHandle)
return serializedHandle

if (serializedHandle.kind === 'directory') {
return VirtualDirectoryHandle.deserialize(
serializedHandle
)
} else {
return VirtualFileHandle.deserialize(serializedHandle)
}
},
}

// Extensions will destructure the fileSystem instance
Expand Down
2 changes: 1 addition & 1 deletion src/components/FileSystem/Virtual/IDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class IDBWrapper {
return clearRaw(this.store)
}
async has(key: IDBValidKey) {
return (await get(key)) !== undefined
return (await rawGet(key, this.store)) !== undefined
}
keys() {
return rawKeys(this.store)
Expand Down
3 changes: 3 additions & 0 deletions src/components/FileSystem/Virtual/Stores/Memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ export class MemoryDb extends IDBWrapper {
}

export class MemoryStore extends IndexedDbStore {
//@ts-ignore
public readonly type = 'memoryStore'
protected idb: MemoryDb

constructor(storeName?: string, mapData?: [IDBValidKey, any][]) {
super(storeName)
this.idb = new MemoryDb(storeName, mapData)
}

//@ts-ignore
serialize() {
return <const>{
type: this.type,
Expand Down

0 comments on commit 832f166

Please sign in to comment.