In the middle of replacing fs and project functions
This commit is contained in:
@ -1,7 +1,4 @@
|
||||
import { readFile, exists as tauriExists } from '@tauri-apps/plugin-fs'
|
||||
import { isTauri } from 'lib/isTauri'
|
||||
import { join } from '@tauri-apps/api/path'
|
||||
import { readDirRecursive } from 'lib/tauri'
|
||||
import { isDesktop } from 'lib/isDesktop'
|
||||
|
||||
/// FileSystemManager is a class that provides a way to read files from the local file system.
|
||||
/// It assumes that you are in a project since it is solely used by the std lib
|
||||
@ -17,54 +14,58 @@ class FileSystemManager {
|
||||
this._dir = dir
|
||||
}
|
||||
|
||||
async join(dir: string, path: string): Promise<string> {
|
||||
return window.electron.ipcRenderer.invoke('join', [dir, path]);
|
||||
}
|
||||
|
||||
async readFile(path: string): Promise<Uint8Array | void> {
|
||||
// Using local file system only works from Tauri.
|
||||
if (!isTauri()) {
|
||||
// Using local file system only works from desktop.
|
||||
if (!isDesktop()) {
|
||||
return Promise.reject(
|
||||
new Error('This function can only be called from a Tauri application')
|
||||
new Error('This function can only be called from the desktop application')
|
||||
)
|
||||
}
|
||||
|
||||
return join(this.dir, path)
|
||||
return this.join(this.dir, path)
|
||||
.catch((error) => {
|
||||
return Promise.reject(new Error(`Error reading file: ${error}`))
|
||||
})
|
||||
.then((file) => {
|
||||
return readFile(file)
|
||||
return window.electron.ipcRenderer.invoke('readFile', [filepath])
|
||||
})
|
||||
}
|
||||
|
||||
async exists(path: string): Promise<boolean | void> {
|
||||
// Using local file system only works from Tauri.
|
||||
if (!isTauri()) {
|
||||
// Using local file system only works from desktop.
|
||||
if (!isDesktop()) {
|
||||
return Promise.reject(
|
||||
new Error('This function can only be called from a Tauri application')
|
||||
new Error('This function can only be called from the desktop application')
|
||||
)
|
||||
}
|
||||
|
||||
return join(this.dir, path)
|
||||
return this.join(this.dir, path)
|
||||
.catch((error) => {
|
||||
return Promise.reject(new Error(`Error checking file exists: ${error}`))
|
||||
})
|
||||
.then((file) => {
|
||||
return tauriExists(file)
|
||||
return window.electron.ipcRenderer.invoke('exists', [file])
|
||||
})
|
||||
}
|
||||
|
||||
async getAllFiles(path: string): Promise<string[] | void> {
|
||||
// Using local file system only works from Tauri.
|
||||
if (!isTauri()) {
|
||||
// Using local file system only works from desktop.
|
||||
if (!isDesktop()) {
|
||||
return Promise.reject(
|
||||
new Error('This function can only be called from a Tauri application')
|
||||
new Error('This function can only be called from the desktop application')
|
||||
)
|
||||
}
|
||||
|
||||
return join(this.dir, path)
|
||||
return this.join(this.dir, path)
|
||||
.catch((error) => {
|
||||
return Promise.reject(new Error(`Error joining dir: ${error}`))
|
||||
})
|
||||
.then((p) => {
|
||||
readDirRecursive(p)
|
||||
.then((filepath) => {
|
||||
return window.electron.ipcRenderer.invoke('readdir', [filepath])
|
||||
.catch((error) => {
|
||||
return Promise.reject(new Error(`Error reading dir: ${error}`))
|
||||
})
|
||||
|
Reference in New Issue
Block a user