Skip to content

Commit

Permalink
Fix web version
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 6, 2024
1 parent b9a9701 commit dcbbc64
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 9d485ba512c065282f99cac5a9b8de613a1c4d95

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
38 changes: 22 additions & 16 deletions node_modules/@capacitor/filesystem/dist/esm/web.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@wordpress/format-library": "^4.23.0",
"@wordpress/i18n": "^4.46.0",
"@wordpress/icons": "^9.37.0",
"idb-keyval": "^6.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
24 changes: 23 additions & 1 deletion src/js/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Filesystem, Encoding } from '@capacitor/filesystem'
import { App as NativeApp } from '@capacitor/app'
import { Preferences } from '@capacitor/preferences'
import { set, get } from 'idb-keyval'
import { getPaths } from './get-data.js'
import React, { useState, useEffect, useRef } from 'react'
import { createRoot } from 'react-dom/client'
Expand All @@ -23,13 +24,34 @@ import '@wordpress/block-library/build-style/style.css'
import '@wordpress/components/build-style/style.css'

export async function getSelectedFolderURL () {
const directoryHandle = await getDirectoryHandle()
if (directoryHandle) return directoryHandle
const selectedFolderURL = await Preferences.get({ key: 'selectedFolderURL' })
return selectedFolderURL?.value
}

async function saveDirectoryHandle (directoryHandle) {
await set('directoryHandle', directoryHandle)
}

async function getDirectoryHandle () {
const directoryHandle = await get('directoryHandle')
if (directoryHandle) {
const permissionStatus = await directoryHandle.queryPermission()
if (permissionStatus === 'granted') {
return directoryHandle
}
}
return null
}

window.pick = async function () {
const { url } = await Filesystem.pickDirectory()
await Preferences.set({ key: 'selectedFolderURL', value: url })
if (typeof url === 'string') {
await Preferences.set({ key: 'selectedFolderURL', value: url })
} else {
await saveDirectoryHandle(url)
}
window.location.reload()
load()
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"start_url": "index.html",
"display": "standalone",
"icons": [{
"src": "assets/imgs/logo.png",
"src": "./assets/imgs/logo.png",
"sizes": "512x512",
"type": "image/png"
}],
Expand Down

0 comments on commit dcbbc64

Please sign in to comment.