Skip to content

Commit f5a16ab

Browse files
committed
(new) fullsceen property, (fix) '/' dir behaviour
1 parent d65e8a4 commit f5a16ab

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

file-browser.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ FileBrowser Class
4848
class FileBrowser {
4949

5050
//---------------------------------------------
51-
constructor(path, {canBrowseParent=false, precheckAccess=true}={}) {
51+
constructor(path="/", {canBrowseParent=false, precheckAccess=true, fullscreen=true}={}) {
52+
path = path ? path : '/'
5253
let pwd = path
54+
canBrowseParent = path == '/' ? false : canBrowseParent
5355
let manager = path.includes('iCloud') ? FileManager.iCloud() : FileManager.local()
54-
Object.assign(this, {path, manager, pwd, canBrowseParent, precheckAccess})
56+
Object.assign(this, {path, manager, pwd, canBrowseParent, precheckAccess, fullscreen})
5557
}
5658

5759
//---------------------------------------------
@@ -97,13 +99,16 @@ class FileBrowser {
9799
table.addRow(row)
98100
}
99101

100-
await table.present(true)
102+
await table.present(this.fullscreen)
101103
return selected
102104

103105
}
104106
//---------------------------------------------
105107
async present() {
106-
108+
109+
//log(`pwd = ${this.pwd}`)
110+
this.pwd = this.pwd ? this.pwd : '/'
111+
107112
const browser = new UITable()
108113
browser.showSeparators = true
109114

@@ -135,7 +140,7 @@ class FileBrowser {
135140
try {
136141
dirContents = this.manager.listContents(this.pwd)
137142
// add the .. if not the root folder
138-
if (this.path != this.pwd || this.canBrowseParent) {
143+
if (this.pwd != '/' & ( this.path != this.pwd || this.canBrowseParent )) {
139144
objects.push( {name:'..', type:'dir', path:'..', isDir:true, displayName:'..', canAccess: true, icon: ICONS.dir} )
140145
}
141146

@@ -212,7 +217,7 @@ class FileBrowser {
212217
}
213218

214219
const fileBrowser = this
215-
let resp = await browser.present(true)
220+
let resp = await browser.present(this.fullscreen)
216221

217222
if (!selected) return null
218223

@@ -286,6 +291,7 @@ function identify(actualPath, manager, precheckAccess) {
286291
manager.listContents(path)
287292
canAccess = true
288293
} catch(e) {
294+
//log(`${name} : ${e.message}`)
289295
canAccess = false
290296
titleColor = COLORS.ERROR
291297
}

readme.md

+43-3
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ new FileBrowser(path, options)
4242
`path` : the directory to browse
4343

4444
`options` : a JSON value indicating the additional options to change the behaviour of the browser
45-
- `canBrowseParent: Boolean`: allow browsing above the initial path. Useful for exploring outside the known directories.
46-
- `precheckAccess: Boolean`: while listing directory contents, check each sub-directory is accessible or not. Inaccessible directories will be colored in red.
45+
- `canBrowseParent: Boolean`: allow browsing above the initial path. Useful for exploring outside the known directories. Default *false*.
46+
- `precheckAccess: Boolean`: while listing directory contents, check each sub-directory is accessible or not. Inaccessible directories will be colored in red. Default *true*.
47+
- `fullscreen: Boolean`: open the file browser in fullscreen. Default *true*.
4748

4849
---
4950

@@ -86,6 +87,15 @@ Allow browsing above the inital path. Useful for exploring outside the known dir
8687
```javascript
8788
canBrowseParent: Boolean
8889
```
90+
---
91+
92+
### fullscreen
93+
94+
Open the file browser in full screen.
95+
96+
```javascript
97+
fullscreen: Boolean
98+
```
8999

90100
---
91101

@@ -117,4 +127,34 @@ The current directory being displayed.
117127
pwd: String
118128
```
119129

120-
![tracking pixel](https://lynks.cc/ghfilebrowser/track)
130+
## Examples
131+
132+
### Browse a bookmarked path
133+
134+
```javascript
135+
const path = FileManager.bookmarkedPath('Shortcuts')
136+
const browser = new FileBrowser(path)
137+
const file = await browser.present()
138+
```
139+
140+
### Open a specific folder
141+
142+
```javascript
143+
const {FileBrowser} = importModule('file-browser')
144+
const path = '/Developer'
145+
const browser = new FileBrowser(path)
146+
const file = await browser.present()
147+
```
148+
149+
### Disable access precheck
150+
151+
```javascript
152+
const {FileBrowser} = importModule('file-browser')
153+
const path = '/Developer'
154+
const browser = new FileBrowser(path, {precheckAccess:false})
155+
const file = await browser.present()
156+
```
157+
158+
![tracking pixel](https://lynks.cc/ghfilebrowser/track)
159+
160+

0 commit comments

Comments
 (0)