-
Notifications
You must be signed in to change notification settings - Fork 21
/
file_system.clj
268 lines (201 loc) · 12.5 KB
/
file_system.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
(ns chromex.app.file-system
"Use the chrome.fileSystem API to create, read, navigate,
and write to the user's local file system. With this API, Chrome Apps can
read and write to a user-selected location. For example, a text editor app
can use the API to read and write local documents. All failures are notified
via chrome.runtime.lastError.
* available since Chrome 36
* https://developer.chrome.com/apps/fileSystem"
(:refer-clojure :only [defmacro defn apply declare meta let partial])
(:require [chromex.wrapgen :refer [gen-wrap-helper]]
[chromex.callgen :refer [gen-call-helper gen-tap-all-events-call]]))
(declare api-table)
(declare gen-call)
; -- functions --------------------------------------------------------------------------------------------------------------
(defmacro get-display-path
"Get the display path of an Entry object. The display path is based on the full path of the file or directory on the local
file system, but may be made more readable for display purposes.
|entry| - https://developer.chrome.com/apps/fileSystem#property-getDisplayPath-entry.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [display-path] where:
|display-path| - https://developer.chrome.com/apps/fileSystem#property-callback-displayPath.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-getDisplayPath."
([entry] (gen-call :function ::get-display-path &form entry)))
(defmacro get-writable-entry
"Get a writable Entry from another Entry. This call will fail with a runtime error if the application does not have the
'write' permission under 'fileSystem'. If entry is a DirectoryEntry, this call will fail if the application does not have
the 'directory' permission under 'fileSystem'.
|entry| - https://developer.chrome.com/apps/fileSystem#property-getWritableEntry-entry.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [entry] where:
|entry| - https://developer.chrome.com/apps/fileSystem#property-callback-entry.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-getWritableEntry."
([entry] (gen-call :function ::get-writable-entry &form entry)))
(defmacro is-writable-entry
"Gets whether this Entry is writable or not.
|entry| - https://developer.chrome.com/apps/fileSystem#property-isWritableEntry-entry.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [is-writable] where:
|is-writable| - https://developer.chrome.com/apps/fileSystem#property-callback-isWritable.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-isWritableEntry."
([entry] (gen-call :function ::is-writable-entry &form entry)))
(defmacro choose-entry
"Ask the user to choose a file or directory.
|options| - https://developer.chrome.com/apps/fileSystem#property-chooseEntry-options.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [entry file-entries] where:
|entry| - https://developer.chrome.com/apps/fileSystem#property-callback-entry.
|file-entries| - https://developer.chrome.com/apps/fileSystem#property-callback-fileEntries.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-chooseEntry."
([options] (gen-call :function ::choose-entry &form options))
([] `(choose-entry :omit)))
(defmacro restore-entry
"Returns the file entry with the given id if it can be restored. This call will fail with a runtime error otherwise.
|id| - https://developer.chrome.com/apps/fileSystem#property-restoreEntry-id.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [entry] where:
|entry| - https://developer.chrome.com/apps/fileSystem#property-callback-entry.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-restoreEntry."
([id] (gen-call :function ::restore-entry &form id)))
(defmacro is-restorable
"Returns whether the app has permission to restore the entry with the given id.
|id| - https://developer.chrome.com/apps/fileSystem#property-isRestorable-id.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [is-restorable] where:
|is-restorable| - https://developer.chrome.com/apps/fileSystem#property-callback-isRestorable.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-isRestorable."
([id] (gen-call :function ::is-restorable &form id)))
(defmacro retain-entry
"Returns an id that can be passed to restoreEntry to regain access to a given file entry. Only the 500 most recently used
entries are retained, where calls to retainEntry and restoreEntry count as use. If the app has the 'retainEntries'
permission under 'fileSystem', entries are retained indefinitely. Otherwise, entries are retained only while the app is
running and across restarts.
|entry| - https://developer.chrome.com/apps/fileSystem#property-retainEntry-entry.
https://developer.chrome.com/apps/fileSystem#method-retainEntry."
([entry] (gen-call :function ::retain-entry &form entry)))
(defmacro request-file-system
"Requests access to a file system for a volume represented by options.volumeId. If options.writable is set to true, then
the file system will be writable. Otherwise, it will be read-only. The writable option requires the 'fileSystem':
{'write'} permission in the manifest. Available to kiosk apps running in kiosk session only. For manual-launch kiosk mode,
a confirmation dialog will be shown on top of the active app window. In case of an error, fileSystem will be undefined, and
chrome.runtime.lastError will be set.
|options| - https://developer.chrome.com/apps/fileSystem#property-requestFileSystem-options.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [file-system] where:
|file-system| - https://developer.chrome.com/apps/fileSystem#property-callback-fileSystem.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-requestFileSystem."
([options] (gen-call :function ::request-file-system &form options)))
(defmacro get-volume-list
"Returns a list of volumes available for requestFileSystem(). The 'fileSystem': {'requestFileSystem'} manifest permission is
required. Available to kiosk apps running in the kiosk session only. In case of an error, volumes will be undefined, and
chrome.runtime.lastError will be set.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [volumes] where:
|volumes| - https://developer.chrome.com/apps/fileSystem#property-callback-volumes.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/fileSystem#method-getVolumeList."
([] (gen-call :function ::get-volume-list &form)))
; -- events -----------------------------------------------------------------------------------------------------------------
;
; docs: https://github.com/binaryage/chromex/#tapping-events
(defmacro tap-on-volume-list-changed-events
"Called when a list of available volumes is changed.
Events will be put on the |channel| with signature [::on-volume-list-changed [event]] where:
|event| - https://developer.chrome.com/apps/fileSystem#property-onVolumeListChanged-event.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/fileSystem#event-onVolumeListChanged."
([channel & args] (apply gen-call :event ::on-volume-list-changed &form channel args)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.app.file-system namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.fileSystem",
:since "36",
:functions
[{:id ::get-display-path,
:name "getDisplayPath",
:callback? true,
:params
[{:name "entry", :type "Entry"}
{:name "callback", :type :callback, :callback {:params [{:name "display-path", :type "string"}]}}]}
{:id ::get-writable-entry,
:name "getWritableEntry",
:callback? true,
:params
[{:name "entry", :type "Entry"}
{:name "callback", :type :callback, :callback {:params [{:name "entry", :type "Entry"}]}}]}
{:id ::is-writable-entry,
:name "isWritableEntry",
:callback? true,
:params
[{:name "entry", :type "Entry"}
{:name "callback", :type :callback, :callback {:params [{:name "is-writable", :type "boolean"}]}}]}
{:id ::choose-entry,
:name "chooseEntry",
:callback? true,
:params
[{:name "options", :optional? true, :type "object"}
{:name "callback",
:type :callback,
:callback
{:params
[{:name "entry", :optional? true, :type "Entry"}
{:name "file-entries", :optional? true, :type "[array-of-FileEntrys]"}]}}]}
{:id ::restore-entry,
:name "restoreEntry",
:callback? true,
:params
[{:name "id", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "entry", :type "Entry"}]}}]}
{:id ::is-restorable,
:name "isRestorable",
:callback? true,
:params
[{:name "id", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "is-restorable", :type "boolean"}]}}]}
{:id ::retain-entry, :name "retainEntry", :return-type "string", :params [{:name "entry", :type "Entry"}]}
{:id ::request-file-system,
:name "requestFileSystem",
:since "44",
:callback? true,
:params
[{:name "options", :type "object"}
{:name "callback",
:type :callback,
:callback {:params [{:name "file-system", :optional? true, :type "FileSystem"}]}}]}
{:id ::get-volume-list,
:name "getVolumeList",
:since "44",
:callback? true,
:params
[{:name "callback",
:type :callback,
:callback {:params [{:name "volumes", :optional? true, :type "[array-of-fileSystem.Volumes]"}]}}]}],
:events
[{:id ::on-volume-list-changed, :name "onVolumeListChanged", :since "44", :params [{:name "event", :type "object"}]}]})
; -- helpers ----------------------------------------------------------------------------------------------------------------
; code generation for native API wrapper
(defmacro gen-wrap [kind item-id config & args]
(apply gen-wrap-helper api-table kind item-id config args))
; code generation for API call-site
(def gen-call (partial gen-call-helper api-table))