Initial commit of akmon project
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cn.limeui.clipboard">
|
||||
<uses-permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND" />
|
||||
<uses-permission android:name="android.permission.WRITE_CLIPBOARD_IN_BACKGROUND" />
|
||||
</manifest>
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "21"
|
||||
}
|
||||
80
uni_modules/lime-clipboard/utssdk/app-android/index.uts
Normal file
80
uni_modules/lime-clipboard/utssdk/app-android/index.uts
Normal file
@@ -0,0 +1,80 @@
|
||||
import ClipData from "android.content.ClipData";
|
||||
import ClipboardManager from "android.content.ClipboardManager";
|
||||
import Context from "android.content.Context";
|
||||
import { UTSAndroid } from "io.dcloud.uts";
|
||||
|
||||
import { SetClipboardDataOption, GetClipboardDataOption, GetClipboardDataSuccessCallbackOption } from '../interface.uts';
|
||||
import { GeneralCallbackResultImpl } from '../unierror.uts';
|
||||
|
||||
|
||||
|
||||
|
||||
export function setClipboardData(options : SetClipboardDataOption) {
|
||||
const handleClipboardOperationFailure = () => {
|
||||
const res = new GeneralCallbackResultImpl(9010002)
|
||||
options.fail?.(res)
|
||||
options.complete?.(res)
|
||||
}
|
||||
try {
|
||||
const context = UTSAndroid.getAppContext();
|
||||
if (context != null) {
|
||||
const clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager;
|
||||
const clip = ClipData.newPlainText('label', options.data);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
const res = new GeneralCallbackResultImpl(9010001)
|
||||
if(options.showToast != false){
|
||||
uni.showToast({
|
||||
icon: 'success',
|
||||
title: '内容已复制'
|
||||
})
|
||||
}
|
||||
options.success?.(res)
|
||||
options.complete?.(res)
|
||||
} else {
|
||||
handleClipboardOperationFailure()
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
handleClipboardOperationFailure()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function getClipboardData(options : GetClipboardDataOption) {
|
||||
const handleClipboardOperationFailure = () => {
|
||||
const res = new GeneralCallbackResultImpl(9010002, 'get')
|
||||
options.fail?.(res)
|
||||
options.complete?.(res)
|
||||
}
|
||||
try {
|
||||
const context = UTSAndroid.getAppContext();
|
||||
if (context != null) {
|
||||
const clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager;
|
||||
const clip = clipboard.getPrimaryClip();
|
||||
if (clip != null && clip.getItemCount() > 0) {
|
||||
const text = clip.getItemAt(0).getText();
|
||||
if (text != null) {
|
||||
options.success?.({
|
||||
data: text.toString(),
|
||||
errMsg: '成功'
|
||||
} as GetClipboardDataSuccessCallbackOption)
|
||||
|
||||
} else {
|
||||
// 如果剪贴板没有文本数据,调用失败的处理函数
|
||||
handleClipboardOperationFailure();
|
||||
}
|
||||
} else {
|
||||
// 如果剪贴板没有内容,调用失败的处理函数
|
||||
handleClipboardOperationFailure();
|
||||
}
|
||||
} else {
|
||||
// 如果无法获取应用上下文,调用失败的处理函数
|
||||
handleClipboardOperationFailure();
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
handleClipboardOperationFailure()
|
||||
}
|
||||
|
||||
}
|
||||
3
uni_modules/lime-clipboard/utssdk/app-ios/config.json
Normal file
3
uni_modules/lime-clipboard/utssdk/app-ios/config.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "9"
|
||||
}
|
||||
33
uni_modules/lime-clipboard/utssdk/app-ios/index.uts
Normal file
33
uni_modules/lime-clipboard/utssdk/app-ios/index.uts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { UIPasteboard } from "UIKit"
|
||||
import { SetClipboardDataOption, GetClipboardDataOption, GetClipboardDataSuccessCallbackOption } from '../interface.uts';
|
||||
import { GeneralCallbackResultImpl } from '../unierror.uts';
|
||||
|
||||
export function setClipboardData(options : SetClipboardDataOption){
|
||||
let pasteboard = UIPasteboard.general
|
||||
pasteboard.string = options.data
|
||||
const res = new GeneralCallbackResultImpl(9010001)
|
||||
if(options.showToast != false){
|
||||
uni.showToast({
|
||||
icon: 'success',
|
||||
title: '内容已复制'
|
||||
})
|
||||
}
|
||||
options.success?.(res)
|
||||
options.complete?.(res)
|
||||
}
|
||||
|
||||
|
||||
export function getClipboardData(options : GetClipboardDataOption){
|
||||
let pasteboard = UIPasteboard.general;
|
||||
const res = new GeneralCallbackResultImpl(9010002, 'get')
|
||||
if(pasteboard.string == null){
|
||||
options.fail?.(res)
|
||||
options.complete?.(res)
|
||||
} else {
|
||||
options.success?.({
|
||||
errMsg: 'getClipboardData:ok',
|
||||
data: `${pasteboard.string!}`
|
||||
} as GetClipboardDataSuccessCallbackOption)
|
||||
options.complete?.(res)
|
||||
}
|
||||
}
|
||||
19
uni_modules/lime-clipboard/utssdk/index.uts
Normal file
19
uni_modules/lime-clipboard/utssdk/index.uts
Normal file
@@ -0,0 +1,19 @@
|
||||
export * from './interface'
|
||||
import {SetClipboardDataOption, GetClipboardDataOption} from './interface'
|
||||
/**
|
||||
* 设置系统剪贴板的内容
|
||||
*
|
||||
* 文档: [http://uniapp.dcloud.io/api/system/clipboard?id=setclipboarddata](http://uniapp.dcloud.io/api/system/clipboard?id=setclipboarddata)
|
||||
*/
|
||||
export function setClipboardData(options : SetClipboardDataOption) {
|
||||
uni.setClipboardData(options as UniNamespace.SetClipboardDataOptions)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得系统剪贴板的内容
|
||||
*
|
||||
* 文档: [http://uniapp.dcloud.io/api/system/clipboard?id=getclipboarddata](http://uniapp.dcloud.io/api/system/clipboard?id=getclipboarddata)
|
||||
*/
|
||||
export function getClipboardData(options : GetClipboardDataOption) {
|
||||
uni.getClipboardData(options as UniNamespace.GetClipboardDataOptions)
|
||||
}
|
||||
66
uni_modules/lime-clipboard/utssdk/interface.uts
Normal file
66
uni_modules/lime-clipboard/utssdk/interface.uts
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
* 根据uni错误码规范要求,建议错误码以90开头,以下是错误码示例:
|
||||
* - 9010001 错误信息1
|
||||
* - 9010002 错误信息2
|
||||
*/
|
||||
export type LimeClipboardErrorCode = 9010001 | 9010002;
|
||||
/**
|
||||
* myApi 的错误回调参数
|
||||
*/
|
||||
export interface GeneralCallbackResult extends IUniError {
|
||||
errCode : LimeClipboardErrorCode
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// export interface GeneralCallbackResult {
|
||||
// /** 错误信息 */
|
||||
// errMsg : string
|
||||
// }
|
||||
|
||||
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
||||
export type SetClipboardDataCompleteCallback = (res : UniError) => void
|
||||
/** 接口调用失败的回调函数 */
|
||||
export type SetClipboardDataFailCallback = (res : UniError) => void
|
||||
/** 接口调用成功的回调函数 */
|
||||
export type SetClipboardDataSuccessCallback = (res : UniError) => void
|
||||
|
||||
|
||||
export type SetClipboardDataOption = {
|
||||
showToast?: boolean
|
||||
/** 剪贴板的内容 */
|
||||
data : string
|
||||
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
||||
complete ?: SetClipboardDataCompleteCallback
|
||||
/** 接口调用失败的回调函数 */
|
||||
fail ?: SetClipboardDataFailCallback
|
||||
/** 接口调用成功的回调函数 */
|
||||
success ?: SetClipboardDataSuccessCallback
|
||||
}
|
||||
|
||||
|
||||
export type GetClipboardDataSuccessCallbackOption = {
|
||||
/** 剪贴板的内容 */
|
||||
data : string
|
||||
errMsg : string
|
||||
}
|
||||
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
||||
export type GetClipboardDataCompleteCallback = (res : UniError) => void
|
||||
/** 接口调用失败的回调函数 */
|
||||
export type GetClipboardDataFailCallback = (res : UniError) => void
|
||||
/** 接口调用成功的回调函数 */
|
||||
export type GetClipboardDataSuccessCallback = (
|
||||
option : GetClipboardDataSuccessCallbackOption
|
||||
) => void
|
||||
|
||||
export type GetClipboardDataOption = {
|
||||
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
||||
complete ?: GetClipboardDataCompleteCallback
|
||||
/** 接口调用失败的回调函数 */
|
||||
fail ?: GetClipboardDataFailCallback
|
||||
/** 接口调用成功的回调函数 */
|
||||
success ?: GetClipboardDataSuccessCallback
|
||||
}
|
||||
39
uni_modules/lime-clipboard/utssdk/unierror.uts
Normal file
39
uni_modules/lime-clipboard/utssdk/unierror.uts
Normal file
@@ -0,0 +1,39 @@
|
||||
/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
|
||||
import { LimeClipboardErrorCode, GeneralCallbackResult } from "./interface.uts"
|
||||
/**
|
||||
* 错误主题
|
||||
* 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
|
||||
* [可选实现]
|
||||
*/
|
||||
export const UniErrorSubject = 'ClipboardData';
|
||||
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
* @UniError
|
||||
* [可选实现]
|
||||
*/
|
||||
export const UniErrors : Map<LimeClipboardErrorCode, string> = new Map([
|
||||
/**
|
||||
* 错误码及对应的错误信息
|
||||
*/
|
||||
[9010001, 'ClipboardData:ok'],
|
||||
[9010002, 'ClipboardData:failed'],
|
||||
]);
|
||||
|
||||
|
||||
/**
|
||||
* 错误对象实现
|
||||
*/
|
||||
export class GeneralCallbackResultImpl extends UniError implements GeneralCallbackResult {
|
||||
|
||||
/**
|
||||
* 错误对象构造函数
|
||||
*/
|
||||
constructor(errCode : LimeClipboardErrorCode, type: string = 'set') {
|
||||
super();
|
||||
this.errSubject = type + UniErrorSubject;
|
||||
this.errCode = errCode;
|
||||
this.errMsg = type + (UniErrors[errCode] ?? "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user