mmmm everything
This commit is contained in:
@@ -2,20 +2,20 @@ import Store from 'store'
|
||||
|
||||
const noWorkingDirWarning = "Please open a directory to allow file saving."
|
||||
|
||||
export let cwd
|
||||
export let root
|
||||
export let store
|
||||
|
||||
export async function Start() {
|
||||
store = await Store.Open('device', 'handles')
|
||||
cwd = await store.Get('directory')
|
||||
root = await store.Get('directory')
|
||||
}
|
||||
|
||||
export async function cd() {
|
||||
cwd = await window.showDirectoryPicker()
|
||||
await store.Set('directory', cwd)
|
||||
root = await window.showDirectoryPicker()
|
||||
await store.Set('directory', root)
|
||||
}
|
||||
|
||||
export async function Entries(handle = cwd) {
|
||||
export async function Entries(handle = root) {
|
||||
let pool = new Map()
|
||||
|
||||
for await (let [ , e ] of handle.entries()) {
|
||||
@@ -26,11 +26,11 @@ export async function Entries(handle = cwd) {
|
||||
}
|
||||
|
||||
export async function Create(sPath) {
|
||||
return cwd.getFileHandle(sPath, { create: true })
|
||||
return root.getFileHandle(sPath, { create: true })
|
||||
}
|
||||
|
||||
export async function Open(hFile) {
|
||||
if(!cwd) {
|
||||
if(!root) {
|
||||
return new Blob([ noWorkingDirWarning ], { type: "text/plain" })
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function Open(hFile) {
|
||||
}
|
||||
|
||||
export async function Write(hFile, sContent) {
|
||||
if(!cwd) {
|
||||
if(!root) {
|
||||
throw new Error("Unable to save file: no working directory")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export const sdcard = navigator.getDeviceStorage('sdcard')
|
||||
export let root
|
||||
|
||||
export function promisify(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -26,7 +27,7 @@ function handle(sPath, sName) {
|
||||
|
||||
function resolveHandle(handle) {
|
||||
let cs = handle.path.split('/')
|
||||
let f = filesystemIndex
|
||||
let f = root
|
||||
|
||||
for(let c of cs) {
|
||||
f = f.entries[c]
|
||||
@@ -38,8 +39,6 @@ function resolveHandle(handle) {
|
||||
return f
|
||||
}
|
||||
|
||||
export let filesystemIndex
|
||||
|
||||
export function Start() {
|
||||
|
||||
}
|
||||
@@ -50,17 +49,17 @@ export const createIndex = () => {
|
||||
|
||||
const filesystemIndexHandler = (resolve, reject) => {
|
||||
let cursor = sdcard.enumerate();
|
||||
filesystemIndex = {}
|
||||
root = {}
|
||||
|
||||
cursor.onerror = function() {
|
||||
reject(cursor.error)
|
||||
}
|
||||
cursor.onsuccess = function() {
|
||||
if(!this.result) {
|
||||
return resolve(filesystemIndex)
|
||||
return resolve(root)
|
||||
}
|
||||
let cs = this.result.name.split('/').slice(1)
|
||||
let f = filesystemIndex
|
||||
let f = root
|
||||
let c
|
||||
for(let i = 0; i < cs.length; i++) {
|
||||
c = cs[i]
|
||||
@@ -78,10 +77,10 @@ const filesystemIndexHandler = (resolve, reject) => {
|
||||
}
|
||||
|
||||
export async function Entries(handle) {
|
||||
if(!filesystemIndex)
|
||||
if(!root)
|
||||
await createIndex()
|
||||
let pool = new Map()
|
||||
let t = handle == null ? filesystemIndex : handle
|
||||
let t = handle == null ? root : handle
|
||||
for(let n in t.entries ?? {}) {
|
||||
let h = t.entries[n]
|
||||
pool.set(h.name, h)
|
||||
|
||||
Reference in New Issue
Block a user