Go to file
zuotao 228ab9298a 剪切板动态启停优化
Signed-off-by: zuotao <zuotao2@huawei.com>
2023-04-28 10:21:05 +08:00
etc/init 剪贴板动态启停适配 2023-04-11 15:13:42 +08:00
figures Signed-off-by: LVB8189 <lvbai1@huawei.com> 2022-08-09 15:43:07 +08:00
framework 剪切板动态启停优化 2023-04-28 10:21:05 +08:00
interfaces update interfaces/kits/napi/test/unittest/pasteboardapi/PasteBoardPromiseJsunit.test.js. 2023-04-23 12:01:57 +00:00
profile 剪切板动态启停优化 2023-04-28 10:21:05 +08:00
services Marshall代码删除 2023-04-27 10:45:34 +08:00
test/fuzztest cde检测问题修改以及Copyright时间调整 2023-03-30 10:21:43 +08:00
utils/native/include 访问剪切板打点 2023-02-27 14:04:57 +08:00
.gitattributes 提交剪贴板代码 2022-03-09 13:23:51 +08:00
BUILD.gn delete old dialog 2022-10-07 19:16:40 +08:00
bundle.json 访问剪切板打点 2023-02-27 14:04:57 +08:00
LICENSE 提交剪贴板代码 2022-03-09 13:23:51 +08:00
OAT.xml add svg resource 2022-10-09 14:10:49 +08:00
pasteboard.gni support copy dlp 2022-08-08 20:24:22 +08:00
pasteboardEvent.yaml cde检测问题修改以及Copyright时间调整 2023-03-30 10:21:43 +08:00
README_ZH.md Signed-off-by: qimeng <qimeng11@huawei.com> 2022-10-13 20:30:30 +08:00
README.md Signed-off-by: lovechinamo <wangdongqi2@huawei.com> 2022-08-05 14:27:12 +08:00

pasteBoardService

Introduction

As a functional component of the stray subsystem, the clipboard service provides the ability to manage the system clipboard and supports the system copy and paste functions. The system clipboard supports package text, hypertext, URIs and other content operations.

picture 1 Subsystem Architecture Diagram

The clipboard service provides functions that support application developers to use clipboard-related services conveniently and efficiently. Its main components include clipboard management client and clipboard service. The clipboard management client is responsible for clipboard interface management, providing clipboard northbound JS API to applications; creating clipboard data on the application framework side, requesting clipboard SA to perform clipboard creation, deletion, query, text conversion, configuration, etc. The clipboard service is responsible for clipboard event management, manages the life cycle of clipboard SA (startup, destruction, multi-user, etc.); executes application requests, notifies clipboard data management, and returns the results to the clipboard management client.

Directory Structure

/foundation/distributeddatamgr/pasteboard
├── etc         # Configuration files for the processes contained in the component
├── figures     # Framework diagram
├── framework   # innerKit interface
├── interfaces  # The interface code provided by the component externally
│   └── kits    # Interface provided to the application
├── profile     # Configuration files for system services contained in the component
├── services    # clipboard service implementation
│    └── core   # Core code implementation
│    └── test   # native test code
│    └── zidl   # Cross-process communication code implementation
├── utils       # Tests or services use mocked data
└──README.md    # Instructions for use

illustrate

Interface Description

list 1 PasteBoard open main method

interface name

describe

createHtmlData(htmlText: string): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_HTML for HTML type data

createWantData(want: Want): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_WANT for data of type want

createPlainTextData(text: string): PasteData

Create a PasteData object of type MIMETYPE_TEXT_PLAIN for plain text data

createUriData(uri: string): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_URI for data of type URI

createHtmlTextRecord(htmlText: string): PasteDataRecord;

Create a PasteDataRecord object of type RecordMIMETYPE_TEXT_HTML for hypertext type data

createWantRecord(want: Want): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_WANT for data of type want

createPlainTextRecord(text: string): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_PLAIN for plain text data

createUriRecord(uri: string): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_URI for data of type URI

getSystemPasteboard(): SystemPasteboard

Get system clipboard

list 2 SystemPasteboard open main method

interface name

describe

on(type:'update', callback: () => void): void;

Callback called when the open pasteboard content changes

off(type: 'update', callback?: () => void): void

Callback called when the content of the pasteboard is closed

clear(callback: AsyncCallback): void

clear clipboard

clear(): Promise;

clear clipboard

getPasteData(callback: AsyncCallback<PasteData>): void

Get system clipboard data object

getPasteData():Promise<PasteData>

Get system clipboard data object

hasPasteData(callback: AsyncCallback<boolean>:void;

Check if there is content in the pasteboard

hasPasteData(): Promise<boolean>

Check if there is content in the pasteboard

setPasteData(data: PasteData, callback: AsyncCallback<void>:void;

Write PasteData to the pasteboard

setPasteData(data: PasteData): Promise<void>

Write PasteData to the pasteboard

list 3 PasteData open main method

interface name

describe

addHtmlRecord(htmlText: string): void;

Add the HTML text record to the PasteData object and update the MIME type to PasteData#MIMETYPE_TEXT_HTML in the DataProperty.

addWantRecord(want: Want): void;

Add want record to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_WANT in DataProperty

addRecord(record: PasteDataRecord): void;

Add PasteRecord to paste data object and update MIME type in data attribute

addTextRecord(text: string): void;;

Add plain text records to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_PLAIN in DataProperty

addUriRecord(uri: string): void;

Add URI record to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_URI in DataProperty

getMimeTypes(): Array<string>

MIME type of everything on the pasteboard

getPrimaryHtml(): string;

HTML text of the main record in the PasteData object

getPrimaryWant(): Want;

The want of the master record in the PasteData object

getPrimaryMimeType(): string;

The MIME type of the master record in the PasteData object

getPrimaryUri(): string;

URI of the master record in the PasteData object

getProperty(): PasteDataProperty;

Get the properties of the clipboard data object

getRecordAt(index: number): PasteDataRecord;

records based on the specified index

getRecordCount(): number;

Number of records in PasteData object

hasMimeType(mimeType: string): boolean;

Checks if data of the specified MIME type exists in the DataProperty

removeRecordAt(index: number): boolean;

Delete records based on specified index

replaceRecordAt(index: number, record: PasteDataRecord): boolean;

Replace the specified record with a new record

list 4 PasteDataRecord open main method

interface name

describe

convertToText(callback: AsyncCallback<string>): void;

Convert PasteData to text content

convertToText(): Promise<void>

Convert PasteData to text content

list 5 PasteDataProperty Parameter Description

name

type

illustrate

additions{[key:string]}

object

Additional property data key-value pair

mimeTypes

Array

Distinct MIME types for all records in PasteData

tag

string

User-defined labels for PasteData objects

timestamp

number

Timestamp indicating when the data was written to the system clipboard.

localOnly

boolean

Check if PasteData is set for local access only.

Instructions for use

Clipboard module usage example

// import module
import pasteboard from '@ohos.pasteboard'
//text copy
console.log('Get SystemPasteboard')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.clear()
        
var textData = 'Hello World!'
console.log('createPlainTextData = ' + textData)
var pasteData = pasteboard.createPlainTextData(textData)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
        
console.log('Checks the pasteboard content')
assert.equal(pasteData.getPrimaryText(), textData)
        
console.log('Checks there is a MIMETYPE_TEXT_PLAIN MIME type of data')
assert.equal(pasteData.hasMimeType(MIMETYPE_TEXT_PLAIN), true)
assert.equal(pasteData.getPrimaryMimeType(), MIMETYPE_TEXT_PLAIN)

//clipboard change listener
console.log('Off the content changes')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.off(contentChanges)
systemPasteboard.clear()
        
var textData = 'Hello World!'
console.log('createUriData = ' + textData)
var pasteData = pasteboard.createUriData(textData)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
        
console.log('On the content changes')
systemPasteboard.on(contentChanges)
        
console.log('Removes the Record')
assert.equal(pasteData.removeRecordAt(0), true)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 0)
        
console.log('Checks there is  no content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), false)
        
var textDataNew = 'Hello World!-New'
console.log('createUriData = ' + textDataNew)
var pasteData = pasteboard.createUriData(textDataNew)
        
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
        
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
        
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
        
console.log('Checks the pasteboard content')
assert.equal(pasteData.getRecordAt(0).plainText, textDataNew)

Distributed Data Management subsystem

distributeddatamgr_pasteboard