/
language_settings_private.clj
253 lines (187 loc) · 11.1 KB
/
language_settings_private.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
(ns chromex.ext.language-settings-private
"Use the chrome.languageSettingsPrivate API to get or change
language and input method settings.
* available since Chrome master"
(: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-language-list
"Gets languages available for translate, spell checking, input and locale.
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 [languages] where:
|languages| - ?
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."
([] (gen-call :function ::get-language-list &form)))
(defmacro enable-language
"Enables a language, adding it to the Accept-Language list (used to decide which languages to translate, generate the
Accept-Language header, etc.).
|language-code| - ?"
([language-code] (gen-call :function ::enable-language &form language-code)))
(defmacro disable-language
"Disables a language, removing it from the Accept-Language list.
|language-code| - ?"
([language-code] (gen-call :function ::disable-language &form language-code)))
(defmacro set-enable-translation-for-language
"Enables or disables translation for a given language.
|language-code| - ?
|enable| - ?"
([language-code enable] (gen-call :function ::set-enable-translation-for-language &form language-code enable)))
(defmacro move-language
"Moves a language inside the language list.
|language-code| - ?
|move-type| - ?"
([language-code move-type] (gen-call :function ::move-language &form language-code move-type)))
(defmacro get-spellcheck-dictionary-statuses
"Gets the current status of the chosen spell check dictionaries.
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 [status] where:
|status| - ?
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."
([] (gen-call :function ::get-spellcheck-dictionary-statuses &form)))
(defmacro get-spellcheck-words
"Gets the custom spell check words, in sorted order.
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 [words] where:
|words| - ?
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."
([] (gen-call :function ::get-spellcheck-words &form)))
(defmacro add-spellcheck-word
"Adds a word to the custom dictionary.
|word| - ?"
([word] (gen-call :function ::add-spellcheck-word &form word)))
(defmacro remove-spellcheck-word
"Removes a word from the custom dictionary.
|word| - ?"
([word] (gen-call :function ::remove-spellcheck-word &form word)))
(defmacro get-translate-target-language
"Gets the translate target language (in most cases, the display locale).
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 [language-code] where:
|language-code| - ?
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."
([] (gen-call :function ::get-translate-target-language &form)))
(defmacro get-input-method-lists
"Gets all supported input methods, including third-party IMEs. Chrome OS only.
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 [lists] where:
|lists| - ?
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."
([] (gen-call :function ::get-input-method-lists &form)))
(defmacro add-input-method
"Adds the input method to the current user's list of enabled input methods, enabling the input method for the current user.
Chrome OS only.
|input-method-id| - ?"
([input-method-id] (gen-call :function ::add-input-method &form input-method-id)))
(defmacro remove-input-method
"Removes the input method from the current user's list of enabled input methods, disabling the input method for the current
user. Chrome OS only.
|input-method-id| - ?"
([input-method-id] (gen-call :function ::remove-input-method &form input-method-id)))
(defmacro retry-download-dictionary
"Tries to download the dictionary after a failed download.
|language-code| - ?"
([language-code] (gen-call :function ::retry-download-dictionary &form language-code)))
; -- events -----------------------------------------------------------------------------------------------------------------
;
; docs: https://github.com/binaryage/chromex/#tapping-events
(defmacro tap-on-spellcheck-dictionaries-changed-events
"Called when the pref for the dictionaries used for spell checking changes or the status of one of the spell check
dictionaries changes.
Events will be put on the |channel| with signature [::on-spellcheck-dictionaries-changed [statuses]] where:
|statuses| - ?
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-spellcheck-dictionaries-changed &form channel args)))
(defmacro tap-on-custom-dictionary-changed-events
"Called when words are added to and/or removed from the custom spell check dictionary.
Events will be put on the |channel| with signature [::on-custom-dictionary-changed [words-added words-removed]] where:
|words-added| - ?
|words-removed| - ?
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-custom-dictionary-changed &form channel args)))
(defmacro tap-on-input-method-added-events
"Called when an input method is added.
Events will be put on the |channel| with signature [::on-input-method-added [input-method-id]] where:
|input-method-id| - ?
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-input-method-added &form channel args)))
(defmacro tap-on-input-method-removed-events
"Called when an input method is removed.
Events will be put on the |channel| with signature [::on-input-method-removed [input-method-id]] where:
|input-method-id| - ?
Note: |args| will be passed as additional parameters into Chrome event's .addListener call."
([channel & args] (apply gen-call :event ::on-input-method-removed &form channel args)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.ext.language-settings-private namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.languageSettingsPrivate",
:since "master",
:functions
[{:id ::get-language-list,
:name "getLanguageList",
:callback? true,
:params
[{:name "callback", :type :callback, :callback {:params [{:name "languages", :type "[array-of-objects]"}]}}]}
{:id ::enable-language, :name "enableLanguage", :params [{:name "language-code", :type "string"}]}
{:id ::disable-language, :name "disableLanguage", :params [{:name "language-code", :type "string"}]}
{:id ::set-enable-translation-for-language,
:name "setEnableTranslationForLanguage",
:params [{:name "language-code", :type "string"} {:name "enable", :type "boolean"}]}
{:id ::move-language,
:name "moveLanguage",
:params [{:name "language-code", :type "string"} {:name "move-type", :type "unknown-type"}]}
{:id ::get-spellcheck-dictionary-statuses,
:name "getSpellcheckDictionaryStatuses",
:callback? true,
:params
[{:name "callback",
:type :callback,
:callback
{:params [{:name "status", :type "[array-of-languageSettingsPrivate.SpellcheckDictionaryStatuss]"}]}}]}
{:id ::get-spellcheck-words,
:name "getSpellcheckWords",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "words", :type "[array-of-strings]"}]}}]}
{:id ::add-spellcheck-word, :name "addSpellcheckWord", :params [{:name "word", :type "string"}]}
{:id ::remove-spellcheck-word, :name "removeSpellcheckWord", :params [{:name "word", :type "string"}]}
{:id ::get-translate-target-language,
:name "getTranslateTargetLanguage",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "language-code", :type "string"}]}}]}
{:id ::get-input-method-lists,
:name "getInputMethodLists",
:callback? true,
:params [{:name "callback", :type :callback, :callback {:params [{:name "lists", :type "object"}]}}]}
{:id ::add-input-method, :name "addInputMethod", :params [{:name "input-method-id", :type "string"}]}
{:id ::remove-input-method, :name "removeInputMethod", :params [{:name "input-method-id", :type "string"}]}
{:id ::retry-download-dictionary,
:name "retryDownloadDictionary",
:params [{:name "language-code", :type "string"}]}],
:events
[{:id ::on-spellcheck-dictionaries-changed,
:name "onSpellcheckDictionariesChanged",
:params [{:name "statuses", :type "[array-of-languageSettingsPrivate.SpellcheckDictionaryStatuss]"}]}
{:id ::on-custom-dictionary-changed,
:name "onCustomDictionaryChanged",
:params [{:name "words-added", :type "[array-of-strings]"} {:name "words-removed", :type "[array-of-strings]"}]}
{:id ::on-input-method-added, :name "onInputMethodAdded", :params [{:name "input-method-id", :type "string"}]}
{:id ::on-input-method-removed, :name "onInputMethodRemoved", :params [{:name "input-method-id", :type "string"}]}]})
; -- 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))