/
management.clj
429 lines (320 loc) · 18.8 KB
/
management.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
(ns chromex.app.management
"The chrome.management API provides ways to manage the list of extensions/apps that are installed and running. It is
particularly useful for extensions that override the built-in New Tab page.
* available since Chrome 36
* https://developer.chrome.com/apps/management"
(: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-all
"Returns a list of information about installed extensions and apps.
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 [result] where:
|result| - https://developer.chrome.com/apps/management#property-callback-result.
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/management#method-getAll."
([] (gen-call :function ::get-all &form)))
(defmacro get
"Returns information about the installed extension, app, or theme that has the given ID.
|id| - The ID from an item of 'management.ExtensionInfo'.
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 [result] where:
|result| - https://developer.chrome.com/apps/management#property-callback-result.
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/management#method-get."
([id] (gen-call :function ::get &form id)))
(defmacro get-self
"Returns information about the calling extension, app, or theme. Note: This function can be used without requesting the
'management' permission in the manifest.
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 [result] where:
|result| - https://developer.chrome.com/apps/management#property-callback-result.
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/management#method-getSelf."
([] (gen-call :function ::get-self &form)))
(defmacro get-permission-warnings-by-id
"Returns a list of permission warnings for the given extension id.
|id| - The ID of an already installed extension.
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 [permission-warnings] where:
|permission-warnings| - https://developer.chrome.com/apps/management#property-callback-permissionWarnings.
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/management#method-getPermissionWarningsById."
([id] (gen-call :function ::get-permission-warnings-by-id &form id)))
(defmacro get-permission-warnings-by-manifest
"Returns a list of permission warnings for the given extension manifest string. Note: This function can be used without
requesting the 'management' permission in the manifest.
|manifest-str| - Extension manifest JSON string.
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 [permission-warnings] where:
|permission-warnings| - https://developer.chrome.com/apps/management#property-callback-permissionWarnings.
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/management#method-getPermissionWarningsByManifest."
([manifest-str] (gen-call :function ::get-permission-warnings-by-manifest &form manifest-str)))
(defmacro set-enabled
"Enables or disables an app or extension. In most cases this function must be called in the context of a user gesture (e.g.
an onclick handler for a button), and may present the user with a native confirmation UI as a way of preventing abuse.
|id| - This should be the id from an item of 'management.ExtensionInfo'.
|enabled| - Whether this item should be enabled or disabled.
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 [].
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/management#method-setEnabled."
([id enabled] (gen-call :function ::set-enabled &form id enabled)))
(defmacro uninstall
"Uninstalls a currently installed app or extension.
|id| - This should be the id from an item of 'management.ExtensionInfo'.
|options| - https://developer.chrome.com/apps/management#property-uninstall-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 [].
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/management#method-uninstall."
([id options] (gen-call :function ::uninstall &form id options))
([id] `(uninstall ~id :omit)))
(defmacro uninstall-self
"Uninstalls the calling extension. Note: This function can be used without requesting the 'management' permission in the
manifest.
|options| - https://developer.chrome.com/apps/management#property-uninstallSelf-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 [].
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/management#method-uninstallSelf."
([options] (gen-call :function ::uninstall-self &form options))
([] `(uninstall-self :omit)))
(defmacro launch-app
"Launches an application.
|id| - The extension id of the application.
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 [].
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/management#method-launchApp."
([id] (gen-call :function ::launch-app &form id)))
(defmacro create-app-shortcut
"Display options to create shortcuts for an app. On Mac, only packaged app shortcuts can be created.
|id| - This should be the id from an app item of 'management.ExtensionInfo'.
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 [].
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/management#method-createAppShortcut."
([id] (gen-call :function ::create-app-shortcut &form id)))
(defmacro set-launch-type
"Set the launch type of an app.
|id| - This should be the id from an app item of 'management.ExtensionInfo'.
|launch-type| - The target launch type. Always check and make sure this launch type is in
'ExtensionInfo.availableLaunchTypes', because the available launch types vary on different platforms
and configurations.
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 [].
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/management#method-setLaunchType."
([id launch-type] (gen-call :function ::set-launch-type &form id launch-type)))
(defmacro generate-app-for-link
"Generate an app for a URL. Returns the generated bookmark app.
|url| - The URL of a web page. The scheme of the URL can only be 'http' or 'https'.
|title| - The title of the generated app.
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 [result] where:
|result| - https://developer.chrome.com/apps/management#property-callback-result.
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/management#method-generateAppForLink."
([url title] (gen-call :function ::generate-app-for-link &form url title)))
(defmacro can-install-replacement-android-app
"Checks if the replacement android app can be installed. Errors generated by this API are reported by setting
'runtime.lastError' and executing the function's regular callback.
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 [result] where:
|result| - https://developer.chrome.com/apps/management#property-callback-result.
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/management#method-canInstallReplacementAndroidApp."
([] (gen-call :function ::can-install-replacement-android-app &form)))
(defmacro install-replacement-android-app
"Prompts the user to install the replacement Android app from the manifest. Errors generated by this API are reported by
setting 'runtime.lastError' and executing the function's regular callback.
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 [].
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/management#method-installReplacementAndroidApp."
([] (gen-call :function ::install-replacement-android-app &form)))
(defmacro install-replacement-web-app
"Launches the replacement_web_app specified in the manifest. Prompts the user to install if not already installed.
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 [].
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/management#method-installReplacementWebApp."
([] (gen-call :function ::install-replacement-web-app &form)))
; -- events -----------------------------------------------------------------------------------------------------------------
;
; docs: https://github.com/binaryage/chromex/#tapping-events
(defmacro tap-on-installed-events
"Fired when an app or extension has been installed.
Events will be put on the |channel| with signature [::on-installed [info]] where:
|info| - https://developer.chrome.com/apps/management#property-onInstalled-info.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/management#event-onInstalled."
([channel & args] (apply gen-call :event ::on-installed &form channel args)))
(defmacro tap-on-uninstalled-events
"Fired when an app or extension has been uninstalled.
Events will be put on the |channel| with signature [::on-uninstalled [id]] where:
|id| - The id of the extension, app, or theme that was uninstalled.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/management#event-onUninstalled."
([channel & args] (apply gen-call :event ::on-uninstalled &form channel args)))
(defmacro tap-on-enabled-events
"Fired when an app or extension has been enabled.
Events will be put on the |channel| with signature [::on-enabled [info]] where:
|info| - https://developer.chrome.com/apps/management#property-onEnabled-info.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/management#event-onEnabled."
([channel & args] (apply gen-call :event ::on-enabled &form channel args)))
(defmacro tap-on-disabled-events
"Fired when an app or extension has been disabled.
Events will be put on the |channel| with signature [::on-disabled [info]] where:
|info| - https://developer.chrome.com/apps/management#property-onDisabled-info.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/management#event-onDisabled."
([channel & args] (apply gen-call :event ::on-disabled &form channel args)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.app.management namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.management",
:since "36",
:functions
[{:id ::get-all,
:name "getAll",
:callback? true,
:params
[{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "result", :type "[array-of-management.ExtensionInfos]"}]}}]}
{:id ::get,
:name "get",
:callback? true,
:params
[{:name "id", :type "string"}
{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "result", :type "management.ExtensionInfo"}]}}]}
{:id ::get-self,
:name "getSelf",
:since "39",
:callback? true,
:params
[{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "result", :type "management.ExtensionInfo"}]}}]}
{:id ::get-permission-warnings-by-id,
:name "getPermissionWarningsById",
:callback? true,
:params
[{:name "id", :type "string"}
{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "permission-warnings", :type "[array-of-strings]"}]}}]}
{:id ::get-permission-warnings-by-manifest,
:name "getPermissionWarningsByManifest",
:callback? true,
:params
[{:name "manifest-str", :type "string"}
{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "permission-warnings", :type "[array-of-strings]"}]}}]}
{:id ::set-enabled,
:name "setEnabled",
:callback? true,
:params
[{:name "id", :type "string"}
{:name "enabled", :type "boolean"}
{:name "callback", :optional? true, :type :callback}]}
{:id ::uninstall,
:name "uninstall",
:callback? true,
:params
[{:name "id", :type "string"}
{:name "options", :optional? true, :type "object"}
{:name "callback", :optional? true, :type :callback}]}
{:id ::uninstall-self,
:name "uninstallSelf",
:callback? true,
:params [{:name "options", :optional? true, :type "object"} {:name "callback", :optional? true, :type :callback}]}
{:id ::launch-app,
:name "launchApp",
:callback? true,
:params [{:name "id", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::create-app-shortcut,
:name "createAppShortcut",
:callback? true,
:params [{:name "id", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::set-launch-type,
:name "setLaunchType",
:since "37",
:callback? true,
:params
[{:name "id", :type "string"}
{:name "launch-type", :type "management.LaunchType"}
{:name "callback", :optional? true, :type :callback}]}
{:id ::generate-app-for-link,
:name "generateAppForLink",
:since "37",
:callback? true,
:params
[{:name "url", :type "string"}
{:name "title", :type "string"}
{:name "callback",
:optional? true,
:type :callback,
:callback {:params [{:name "result", :type "management.ExtensionInfo"}]}}]}
{:id ::can-install-replacement-android-app,
:name "canInstallReplacementAndroidApp",
:since "78",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "result", :type "boolean"}]}}]}
{:id ::install-replacement-android-app,
:name "installReplacementAndroidApp",
:since "78",
:callback? true,
:params [{:name "callback", :optional? true, :type :callback}]}
{:id ::install-replacement-web-app,
:name "installReplacementWebApp",
:since "75",
:callback? true,
:params [{:name "callback", :optional? true, :type :callback}]}],
:events
[{:id ::on-installed, :name "onInstalled", :params [{:name "info", :type "management.ExtensionInfo"}]}
{:id ::on-uninstalled, :name "onUninstalled", :params [{:name "id", :type "string"}]}
{:id ::on-enabled, :name "onEnabled", :params [{:name "info", :type "management.ExtensionInfo"}]}
{:id ::on-disabled, :name "onDisabled", :params [{:name "info", :type "management.ExtensionInfo"}]}]})
; -- 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))