@react-native-ohos/clipboard 1.16.3-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +13 -0
  4. package/RNCClipboard.podspec +37 -0
  5. package/dist/Clipboard.d.ts +159 -0
  6. package/dist/Clipboard.js +232 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.js +7 -0
  9. package/harmony/clipboard/LICENSE +21 -0
  10. package/harmony/clipboard/NOTICE +33 -0
  11. package/harmony/clipboard/OAT.xml +38 -0
  12. package/harmony/clipboard/README.OpenSource +11 -0
  13. package/harmony/clipboard/README.md +307 -0
  14. package/harmony/clipboard/build-profile.json5 +8 -0
  15. package/harmony/clipboard/hvigorfile.ts +1 -0
  16. package/harmony/clipboard/index.ets +25 -0
  17. package/harmony/clipboard/oh-package.json5 +12 -0
  18. package/harmony/clipboard/src/main/cpp/CMakeLists.txt +7 -0
  19. package/harmony/clipboard/src/main/cpp/ClipboardPackage.h +58 -0
  20. package/harmony/clipboard/src/main/cpp/RNCClipboardTurboModule.cpp +198 -0
  21. package/harmony/clipboard/src/main/cpp/RNCClipboardTurboModule.h +39 -0
  22. package/harmony/clipboard/src/main/ets/ClipboardPackage.ts +46 -0
  23. package/harmony/clipboard/src/main/ets/Logger.ts +64 -0
  24. package/harmony/clipboard/src/main/ets/RNCClipboardTurboModule.ts +482 -0
  25. package/harmony/clipboard/src/main/module.json5 +7 -0
  26. package/harmony/clipboard/src/main/resources/base/element/string.json +8 -0
  27. package/harmony/clipboard/src/main/resources/en_US/element/string.json +8 -0
  28. package/harmony/clipboard/src/main/resources/zh_CN/element/string.json +8 -0
  29. package/harmony/clipboard/ts.ts +26 -0
  30. package/harmony/clipboard.har +0 -0
  31. package/package.json +90 -0
  32. package/src/Clipboard.ts +211 -0
  33. package/src/index.ts +3 -0
@@ -0,0 +1,46 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
26
+ import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
27
+ import { RNCClipboardTurboModule } from './RNCClipboardTurboModule';
28
+
29
+ class ClipboardTurboModulesFactory extends TurboModulesFactory {
30
+ createTurboModule(name: string): TurboModule | null {
31
+ if (name === 'RNCClipboard') {
32
+ return new RNCClipboardTurboModule(this.ctx);
33
+ }
34
+ return null;
35
+ }
36
+
37
+ hasTurboModule(name: string): boolean {
38
+ return name === 'RNCClipboard';
39
+ }
40
+ }
41
+
42
+ export class ClipboardPackage extends RNPackage {
43
+ createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
44
+ return new ClipboardTurboModulesFactory(ctx);
45
+ }
46
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import hilog from '@ohos.hilog';
26
+
27
+ class Logger {
28
+ private domain: number;
29
+ private prefix: string;
30
+ private format: string = '%{public}s,%{public}s';
31
+ private isDebug: boolean;
32
+
33
+ /**
34
+ * constructor.
35
+ *
36
+ * @param Prefix Identifies the log tag.
37
+ * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
38
+ */
39
+ constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
40
+ this.prefix = prefix;
41
+ this.domain = domain;
42
+ this.isDebug = isDebug;
43
+ }
44
+
45
+ debug(...args: string[]): void {
46
+ if (this.isDebug) {
47
+ hilog.debug(this.domain, this.prefix, this.format, args);
48
+ }
49
+ }
50
+
51
+ info(...args: string[]): void {
52
+ hilog.info(this.domain, this.prefix, this.format, args);
53
+ }
54
+
55
+ warn(...args: string[]): void {
56
+ hilog.warn(this.domain, this.prefix, this.format, args);
57
+ }
58
+
59
+ error(...args: string[]): void {
60
+ hilog.error(this.domain, this.prefix, this.format, args);
61
+ }
62
+ }
63
+
64
+ export default new Logger('Clipboard', 0xFF00, false)
@@ -0,0 +1,482 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
26
+ import { pasteboard, BusinessError } from '@kit.BasicServicesKit';
27
+ import util from '@ohos.util';
28
+ import image from '@ohos.multimedia.image';
29
+ import logger from './Logger';
30
+ import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
31
+ import url from '@ohos.url';
32
+
33
+ const TAG = "RNCClipboardTurboModule"
34
+ const prefixPNG = "data:image/png;base64,"
35
+ const prefixJPG = "data:image/jpg;base64,"
36
+ const PERMISSIONS: Array<Permissions> = [
37
+ 'ohos.permission.READ_PASTEBOARD'
38
+ ]
39
+
40
+ export class RNCClipboardTurboModule extends TurboModule {
41
+ constructor(protected ctx: TurboModuleContext) {
42
+ super(ctx);
43
+ logger.debug(TAG, "RNCClipboardTurboModule constructor");
44
+ }
45
+
46
+ getConstants() {
47
+ logger.debug(TAG, "RNCClipboardTurboModule call getConstants");
48
+ return {};
49
+ }
50
+
51
+ getString(): Promise<string> {
52
+ return new Promise<string>((resolve, reject) => {
53
+ this.requestPermission().then(res => {
54
+ if (res) {
55
+ let systemPasteboard = pasteboard.getSystemPasteboard();
56
+ systemPasteboard.getData().then((pasteData) => {
57
+ let text = pasteData.getPrimaryText();
58
+ logger.debug(TAG, `getString,text out:${text}`);
59
+ resolve(text);
60
+ }).catch((err) => {
61
+ logger.error(TAG, `getString,Failed to get PasteData. Cause:${err.message}`);
62
+ reject(err);
63
+ })
64
+ } else {
65
+ reject({
66
+ code: 0,
67
+ message: "User refuses authorization"
68
+ })
69
+ }
70
+ })
71
+ });
72
+ }
73
+
74
+ getStrings(): Promise<string[]> {
75
+ return new Promise<string[]>((resolve, reject) => {
76
+ this.requestPermission().then(res => {
77
+ if (res) {
78
+ logger.debug(TAG, "call getStrings fun");
79
+ let systemPasteboard = pasteboard.getSystemPasteboard();
80
+ systemPasteboard.getData().then((pasteData) => {
81
+ let count = pasteData.getRecordCount();
82
+ let resultSet = []
83
+ logger.debug(TAG, `getStrings fun,getRecordCount :${count}`);
84
+ for (let index = 0; index < count; index++) {
85
+ let record = pasteData.getRecord(index)
86
+ if (record.mimeType == pasteboard.MIMETYPE_TEXT_PLAIN) {
87
+ resultSet.push(record.plainText)
88
+ }
89
+ }
90
+ resolve(resultSet)
91
+ }).catch((err) => {
92
+ logger.error(TAG, `getString fun,Failed to get PasteData. Cause:${err.message}`);
93
+ reject(err)
94
+ })
95
+ } else {
96
+ reject({
97
+ code: 0,
98
+ message: "User refuses authorization"
99
+ })
100
+ }
101
+ })
102
+ });
103
+ }
104
+
105
+ setString(content: string) {
106
+ logger.debug(TAG, "setString fun");
107
+ let systemPasteboard = pasteboard.getSystemPasteboard();
108
+ let dataText = content;
109
+ let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, dataText);
110
+ systemPasteboard.setData(pasteData).then((data) => {
111
+ logger.debug(TAG, "setString fun,Succeeded PasteData");
112
+ }).catch((err) => {
113
+ logger.error(TAG, `setString fun,Failed to set PasteData.setString, Cause:${err.message}`);
114
+ });
115
+ return;
116
+ }
117
+
118
+ hasString(): Promise<boolean> {
119
+ return new Promise<boolean>((resolve, reject) => {
120
+ this.requestPermission().then(res => {
121
+ if (res) {
122
+ logger.debug(TAG, "RNCClipboardTurboModule call hasString fun");
123
+ let systemPasteboard = pasteboard.getSystemPasteboard();
124
+ systemPasteboard.getData().then((pasteData) => {
125
+ let count = pasteData.getRecordCount();
126
+ resolve(count > 0)
127
+ }).catch((err) => {
128
+ logger.error(TAG, `RNCClipboardTurboModule hasString,Failed to get PasteData. Cause:${err.message}`);
129
+ reject(err)
130
+ })
131
+ } else {
132
+ reject({
133
+ code: 0,
134
+ message: "User refuses authorization"
135
+ })
136
+ }
137
+ })
138
+ });
139
+ }
140
+
141
+ hasNumber(): Promise<boolean> {
142
+ return new Promise<boolean>((resolve, reject) => {
143
+ this.requestPermission().then(res => {
144
+ if (res) {
145
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call hasNumber");
146
+ let systemPasteboard = pasteboard.getSystemPasteboard();
147
+ let reg = /^[\d]*$/;
148
+ systemPasteboard.getData().then((pasteData) => {
149
+ let count = pasteData.getRecordCount();
150
+ let result = false
151
+ for (let index = 0; index < count; index++) {
152
+ let record = pasteData.getRecord(index);
153
+ if (record.mimeType == pasteboard.MIMETYPE_TEXT_PLAIN && reg.test(record.plainText)) {
154
+ result = true
155
+ logger.debug(TAG, `[RNOH]:RNCClipboardTurboModule hasNumber,result out:${result}`);
156
+ break
157
+ }
158
+ }
159
+ resolve(result)
160
+ }).catch((err) => {
161
+ logger.error(TAG, `[RNOH]: hasNumber,Failed to get PasteData. Cause:${err.message}`);
162
+ reject(err)
163
+ })
164
+ } else {
165
+ reject({
166
+ code: 0,
167
+ message: "User refuses authorization"
168
+ })
169
+ }
170
+ })
171
+ });
172
+ }
173
+
174
+ // ios
175
+ getImagePNG(): Promise<string> {
176
+ return new Promise<string>((resolve, reject) => {
177
+ this.requestPermission().then(res => {
178
+ if (res) {
179
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call getImagePNG");
180
+ let systemPasteboard = pasteboard.getSystemPasteboard();
181
+
182
+ systemPasteboard.getData().then((pasteData) => {
183
+ let pixMap = pasteData.getPrimaryPixelMap();
184
+ //packer方式
185
+ const imagePackerApi = image.createImagePacker();
186
+ let packOpt: image.PackingOption = {
187
+ format: "image/png",
188
+ quality: 96
189
+ }
190
+ imagePackerApi.packing(pixMap, packOpt).then(data => {
191
+ let uint8Array = new Uint8Array(data);
192
+ let base64Helper = new util.Base64Helper();
193
+ let base64Str = base64Helper.encodeToStringSync(uint8Array, util.Type.BASIC)
194
+ let finalStr = prefixPNG + base64Str
195
+ resolve(finalStr)
196
+ }).catch((err) => {
197
+ logger.error(TAG, "[RNOH]:RNCClipboardTurboModule call getImagePNG,failed to packing");
198
+ reject(err)
199
+ })
200
+ imagePackerApi.release().then(() => {
201
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call getImagePNG, releasing image packaging");
202
+ }).catch((error: BusinessError) => {
203
+ logger.error(TAG, "[RNOH]:RNCClipboardTurboModule call getImagePNG, releasing image packaging error");
204
+ })
205
+
206
+ }).catch((err) => {
207
+ logger.error(TAG, "[RNOH]:RNCClipboardTurboModule call getImagePNG,failed to getData");
208
+ reject(err)
209
+ })
210
+ } else {
211
+ reject({
212
+ code: 0,
213
+ message: "User refuses authorization"
214
+ })
215
+ }
216
+ });
217
+ });
218
+ }
219
+
220
+ // ios
221
+ getImageJPG(): Promise<string> {
222
+ return new Promise<string>((resolve, reject) => {
223
+ this.requestPermission().then(res => {
224
+ if (res) {
225
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call getImageJPG");
226
+ let systemPasteboard = pasteboard.getSystemPasteboard();
227
+
228
+ systemPasteboard.getData().then((pasteData) => {
229
+ let pixMap = pasteData.getPrimaryPixelMap();
230
+
231
+ //packer方式
232
+ const imagePackerApi = image.createImagePacker();
233
+ let packOpt: image.PackingOption = {
234
+ format: "image/jpeg",
235
+ quality: 96
236
+ }
237
+ imagePackerApi.packing(pixMap, packOpt).then(data => {
238
+ let uint8Array = new Uint8Array(data);
239
+ let base64Helper = new util.Base64Helper();
240
+ let base64Str = base64Helper.encodeToStringSync(uint8Array, util.Type.BASIC)
241
+ let finalStr = prefixJPG + base64Str
242
+ resolve(finalStr)
243
+ }).catch((err) => {
244
+ logger.error(TAG, "[RNOH]:RNCClipboardTurboModule call getImageJPG,failed to packing");
245
+ reject(err)
246
+ })
247
+ imagePackerApi.release().then(() => {
248
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call getImageJPG, releasing image packaging");
249
+ }).catch((error: BusinessError) => {
250
+ logger.error(TAG, "[RNOH]:RNCClipboardTurboModule call getImageJPG, releasing image packaging error");
251
+ })
252
+
253
+ }).catch((err) => {
254
+ logger.error(TAG, "[RNOH]:RNCClipboardTurboModule call getImageJPG,failed to getData");
255
+ reject(err)
256
+ })
257
+ } else {
258
+ reject({
259
+ code: 0,
260
+ message: "User refuses authorization"
261
+ })
262
+ }
263
+ });
264
+ });
265
+ }
266
+
267
+ setImage(content: string) {
268
+ logger.debug(TAG, `[RNOH]:RNCClipboardTurboModule call setImage:${content}`);
269
+ let iconBase64 = content
270
+
271
+ let base64 = new util.Base64Helper();
272
+ let uint8 = base64.decodeSync(iconBase64, util.Type.BASIC)
273
+ let arrayBuffer = uint8.buffer.slice(uint8.byteOffset, uint8.byteLength + uint8.byteOffset)
274
+ let imageSource: image.ImageSource = image.createImageSource(arrayBuffer);
275
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call setImage100");
276
+
277
+ imageSource.getImageInfo().then(value => {
278
+ let hValue = Math.round(value.size.height);
279
+ let wValue = Math.round(value.size.width);
280
+ let defaultSize: image.Size = {
281
+ height: hValue,
282
+ width: wValue
283
+ };
284
+ let opts: image.DecodingOptions = {
285
+ editable: true,
286
+ desiredSize: defaultSize
287
+ };
288
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call setImage200");
289
+ imageSource.createPixelMap(opts).then((pixMap) => {
290
+ let iconPixelMap = pixMap
291
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call setImage300");
292
+ imageSource.release()
293
+
294
+ let systemPasteboard = pasteboard.getSystemPasteboard();
295
+ systemPasteboard.getData().then((pasteData) => {
296
+ let record = pasteboard.createRecord(pasteboard.MIMETYPE_PIXELMAP, iconPixelMap)
297
+ pasteData.addRecord(record)
298
+
299
+ systemPasteboard.setData(pasteData).then((data: void) => {
300
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call setImage305,successed in setting pasteData");
301
+ }).catch((err) => {
302
+ logger.error(TAG, "[RNOH]:RNCClipboardTurboModule call setImage305,failed in setting pasteData");
303
+ })
304
+ }).catch((err) => {
305
+ logger.debug(TAG, `[RNOH]:RNCClipboardTurboModule call setImage,failed get pasteData.cause:${err.message}`);
306
+ })
307
+ })
308
+ })
309
+
310
+ }
311
+
312
+ getImage(): Promise<string> {
313
+ return new Promise<string>((resolve, reject) => {
314
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call getImage");
315
+ resolve("demo-todo")
316
+ });
317
+ }
318
+
319
+ setStrings(content: string[]) {
320
+ logger.debug(TAG, "[RNOH]:RNCClipboardTurboModule call setStrings fun");
321
+ let systemPasteboard = pasteboard.getSystemPasteboard();
322
+ systemPasteboard.clear().then(() => {
323
+ systemPasteboard.getData().then((pasteData) => {
324
+ for (let i = 0; i < content.length; i++) {
325
+ pasteData.addRecord(pasteboard.MIMETYPE_TEXT_PLAIN, content[i]);
326
+ logger.debug(TAG, `[RNOH]:setStrings,PasteData--addRecord:${content[i]}`);
327
+ }
328
+
329
+ // setData
330
+ systemPasteboard.setData(pasteData).then((data: void) => {
331
+ logger.debug(TAG, "setStrings,Succeeded in setting PasteData.");
332
+ }).catch((err) => {
333
+ logger.error(TAG, `setStrings,Failed to set PasteData. Cause:${err.message}`);
334
+ });
335
+ }).catch((err) => {
336
+ logger.error(TAG, `setStrings,getData error,Cause:${err.message}`);
337
+ })
338
+ }).catch((err: BusinessError) => {
339
+ console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
340
+ });
341
+ return;
342
+ }
343
+
344
+ hasImage(): Promise<boolean> {
345
+ return new Promise<boolean>((resolve, reject) => {
346
+ this.requestPermission().then(res => {
347
+ if (res) {
348
+ logger.debug(TAG, "RNCClipboardTurboModule call hasImage");
349
+ let systemPasteboard = pasteboard.getSystemPasteboard();
350
+ systemPasteboard.getData().then((pasteData) => {
351
+ let pixelMapObj = pasteData.getPrimaryPixelMap();
352
+ let result = false
353
+ if (pixelMapObj) {
354
+ logger.debug(TAG, "RNCClipboardTurboModule call hasImage,hasPixelobj");
355
+ result = true
356
+ }
357
+ resolve(result)
358
+ }).catch((err) => {
359
+ logger.error(TAG, `hasImage,Failed to get PasteData. Cause:${err.message}`);
360
+ reject(err)
361
+ })
362
+ } else {
363
+ reject({
364
+ code: 0,
365
+ message: "User refuses authorization"
366
+ })
367
+ }
368
+ });
369
+ });
370
+ }
371
+
372
+ hasURL(): Promise<boolean> {
373
+ return new Promise<boolean>((resolve, reject) => {
374
+ this.requestPermission().then(res => {
375
+ if (res) {
376
+ logger.debug(TAG, "RNCClipboardTurboModule call hasWebURL");
377
+ let systemPasteboard = pasteboard.getSystemPasteboard();
378
+ systemPasteboard.getData().then((pasteData) => {
379
+ let count = pasteData.getRecordCount();
380
+ let result = false;
381
+ let isValidUrl = (string) => {
382
+ try {
383
+ url.URL.parseURL(string);
384
+ return true;
385
+ } catch (err) {
386
+ return false;
387
+ }
388
+ };
389
+ for (let index = 0; index < count; index++) {
390
+ let record = pasteData.getRecord(index);
391
+ if (record.mimeType == pasteboard.MIMETYPE_TEXT_URI) {
392
+ if (isValidUrl(record.uri)) {
393
+ logger.debug(TAG, "hasURL,mimeType=MIMETYPE_TEXT_URI");
394
+ result = true
395
+ break
396
+ }
397
+ } else if (record.mimeType == pasteboard.MIMETYPE_TEXT_PLAIN) {
398
+ if (isValidUrl(record.plainText)) {
399
+ logger.debug(TAG, "hasURL,find URL in MIMETYPE_TEXT_PLAIN");
400
+ result = true
401
+ break
402
+ }
403
+ }
404
+ }
405
+ resolve(result)
406
+ }).catch((err) => {
407
+ logger.error(TAG, `[RNOH]: hasURL,Failed to get PasteData. Cause:${err.message}`);
408
+ reject(err)
409
+ });
410
+ } else {
411
+ reject({
412
+ code: 0,
413
+ message: "User refuses authorization"
414
+ })
415
+ }
416
+ });
417
+ });
418
+ }
419
+
420
+ hasWebURL(): Promise<boolean> {
421
+ return new Promise<boolean>((resolve, reject) => {
422
+ this.requestPermission().then(res => {
423
+ if (res) {
424
+ logger.debug(TAG, "RNCClipboardTurboModule call hasWebURL");
425
+ let systemPasteboard = pasteboard.getSystemPasteboard();
426
+ systemPasteboard.getData().then((pasteData) => {
427
+ let count = pasteData.getRecordCount();
428
+ let result = false
429
+ let reg = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
430
+
431
+ for (let index = 0; index < count; index++) {
432
+ let record = pasteData.getRecord(index);
433
+ if (record.mimeType == pasteboard.MIMETYPE_TEXT_URI) {
434
+ if (reg.test(record.uri)) {
435
+ logger.debug(TAG, "hasWebURL,find webURL in MIMETYPE_TEXT_URI");
436
+ result = true
437
+ break
438
+ }
439
+ } else if (record.mimeType == pasteboard.MIMETYPE_TEXT_PLAIN) {
440
+ if (reg.test(record.plainText)) {
441
+ logger.debug(TAG, "hasWebURL,find webURL in MIMETYPE_TEXT_PLAIN");
442
+ result = true
443
+ break
444
+ }
445
+ }
446
+
447
+ }
448
+ resolve(result)
449
+ }).catch((err) => {
450
+ logger.error(TAG, `hasWebURL,Failed to get PasteData. Cause:${err.message}`);
451
+ reject(err)
452
+ });
453
+ } else {
454
+ reject({
455
+ code: 0,
456
+ message: "User refuses authorization"
457
+ })
458
+ }
459
+ });
460
+ });
461
+ }
462
+
463
+ requestPermission(): Promise<boolean> {
464
+ return new Promise<boolean>((resolve) => {
465
+ abilityAccessCtrl.createAtManager()
466
+ .requestPermissionsFromUser(this.ctx.uiAbilityContext, PERMISSIONS).then(result => {
467
+ if (result.authResults[0] == 0) {
468
+ resolve(true);
469
+ } else {
470
+ logger.debug(TAG, `getString,text out:用户拒绝授权`);
471
+ resolve(false);
472
+ }
473
+ }).catch(() => {
474
+ logger.debug(TAG, `getString,text out:用户拒绝授权`);
475
+ resolve(false);
476
+ })
477
+ });
478
+ }
479
+
480
+ addListener(eventName: string): void {}
481
+ removeListeners(count: number): void {}
482
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "module": {
3
+ "name": "clipboard",
4
+ "type": "har",
5
+ "deviceTypes": ['default'],
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from npm package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export * from './src/main/ets/ClipboardPackage'
26
+ export * from './src/main/ets/RNCClipboardTurboModule'
Binary file