更新utools api到6.0

This commit is contained in:
fofolee 2024-12-22 10:12:17 +08:00
parent 36f6e0ceed
commit 3566e45704
2 changed files with 272 additions and 307 deletions

View File

@ -1,9 +1,22 @@
const getuToolsLite = () => {
var utoolsLite = Object.assign({}, _.cloneDeep(utools))
// if (utools.isDev()) return utoolsLite
const dbBlackList = ['db', 'dbStorage', 'removeFeature', 'setFeature', 'onDbPull']
const dbBlackList = [
"db",
"dbStorage",
"dbCryptoStorage",
"removeFeature",
"setFeature",
"onDbPull",
];
const payBlackList = ['fetchUserServerTemporaryToken', 'isPurchasedUser', 'openPurchase', 'getUserServerTemporaryToken', 'openPayment', 'fetchUserPayments']
const etcBlackList = ['onPluginEnter', 'onPluginOut', 'onMainPush', 'createBrowserWindow']
const etcBlackList = [
"onPluginEnter",
"onPluginOut",
"onMainPush",
"createBrowserWindow",
"team",
];
_.concat(dbBlackList, payBlackList, etcBlackList).forEach(item => {
delete utoolsLite[item]
})

View File

@ -9,7 +9,11 @@ interface UBrowser {
* @param headers
* @param timeout , 60000 ms(60)
*/
goto(url: string, headers?: { Referer: string, userAgent: string }, timeout?: number): this;
goto(
url: string,
headers?: { Referer: string; userAgent: string },
timeout?: number
): this;
/**
*
*/
@ -29,7 +33,7 @@ interface UBrowser {
/**
*
*/
press(key: string, ...modifier: ('ctrl' | 'shift' | 'alt' | 'meta')[]): this;
press(key: string, ...modifier: ("ctrl" | "shift" | "alt" | "meta")[]): this;
/**
*
* @param text base64编码字符串
@ -40,17 +44,31 @@ interface UBrowser {
* @param arg 1. - DOM元素 2. - 3. -
* @param savePath .png文件完全路径,
*/
screenshot(arg: string | { x: number, y: number, width: number, height: number }, savePath?: string): this;
screenshot(
arg: string | { x: number; y: number; width: number; height: number },
savePath?: string
): this;
/**
* PDF
* @param options
* @param savePath PDF保存路径 .pdf文件完全路径,
*/
pdf(options?: { marginsType: 0 | 1 | 2, pageSize: ('A3' | 'A4' | 'A5' | 'Legal' | 'Letter' | 'Tabloid') | ({ width: number, height: number }) }, savePath?: string): this;
pdf(
options?: {
marginsType: 0 | 1 | 2;
pageSize:
| ("A3" | "A4" | "A5" | "Legal" | "Letter" | "Tabloid")
| { width: number; height: number };
},
savePath?: string
): this;
/**
*
*/
device(arg: ('iPhone 11' | 'iPhone X' | 'iPad' | 'iPhone 6/7/8 Plus' | 'iPhone 6/7/8' | 'iPhone 5/SE' | 'HUAWEI Mate10' | 'HUAWEI Mate20' | 'HUAWEI Mate30' | 'HUAWEI Mate30 Pro') | { size: { width: number, height: number }, useragent: string }): this;
device(arg: {
size: { width: number; height: number };
useragent: string;
}): this;
/**
* cookie
* @param name cookie
@ -63,7 +81,7 @@ interface UBrowser {
/**
* Cookie
*/
setCookies(cookies: { name: string, value: string }[]): this;
setCookies(cookies: { name: string; value: string }[]): this;
/**
* cookie
*/
@ -76,13 +94,13 @@ interface UBrowser {
/**
*
*/
devTools(mode?: 'right' | 'bottom' | 'undocked' | 'detach'): this;
devTools(mode?: "right" | "bottom" | "undocked" | "detach"): this;
/**
* JS计算
* @param func
* @param params func
*/
evaluate(func: (...params: any[]) => any, ...params: any[]): this;
evaluate<T extends any[]>(func: (...params: T) => any, ...params: T): this;
/**
*
* @param ms
@ -100,9 +118,13 @@ interface UBrowser {
* @param timeout 60000 ms(60)
* @param params func
*/
wait(func: (...params: any[]) => boolean, timeout?: number, ...params: any[]): this;
wait<T extends any[]>(
func: (...params: T) => boolean,
timeout?: number,
...params: T
): this;
/**
* end
* end
* @param selector DOM元素
*/
when(selector: string): this;
@ -111,7 +133,7 @@ interface UBrowser {
* @param func JS函数
* @param params func
*/
when(func: (...params: any[]) => boolean, ...params: any[]): this;
when<T extends any[]>(func: (...params: T) => boolean, ...params: T): this;
/**
* when 使
*/
@ -162,42 +184,50 @@ interface UBrowser {
*
*/
download(url: string, savePath?: string): this;
/**
*
*/
download(
func: (...params: any[]) => string,
savePath: string | null,
...params: any[]
): this;
/**
* ubrowser
*
* @param options
*/
run(options: {
show?: boolean,
width?: number,
height?: number,
x?: number,
y?: number,
center?: boolean,
minWidth?: number,
minHeight?: number,
maxWidth?: number,
maxHeight?: number,
resizable?: boolean,
movable?: boolean,
minimizable?: boolean,
maximizable?: boolean,
alwaysOnTop?: boolean,
fullscreen?: boolean,
fullscreenable?: boolean,
enableLargerThanScreen?: boolean,
opacity?: number
}): Promise<any[]>;
run<T extends any = any[]>(options: {
show?: boolean;
width?: number;
height?: number;
x?: number;
y?: number;
center?: boolean;
minWidth?: number;
minHeight?: number;
maxWidth?: number;
maxHeight?: number;
resizable?: boolean;
movable?: boolean;
minimizable?: boolean;
maximizable?: boolean;
alwaysOnTop?: boolean;
fullscreen?: boolean;
fullscreenable?: boolean;
enableLargerThanScreen?: boolean;
opacity?: number;
}): Promise<T>;
/**
* ubrowser
* @param ubrowserId 1. run(options) , ubrowser 2. utools.getIdleUBrowsers()
*/
run(ubrowserId: number): Promise<any[]>;
run<T extends any = any[]>(ubrowserId: number): Promise<T>;
}
interface Display {
accelerometerSupport: ('available' | 'unavailable' | 'unknown');
bounds: { x: number, y: number, width: number, height: number };
accelerometerSupport: "available" | "unavailable" | "unknown";
bounds: { x: number; y: number; width: number; height: number };
colorDepth: number;
colorSpace: string;
depthPerComponent: number;
@ -206,48 +236,34 @@ interface Display {
monochrome: boolean;
rotation: number;
scaleFactor: number;
size: { width: number, height: number };
touchSupport: ('available' | 'unavailable' | 'unknown');
workArea: { x: number, y: number, width: number, height: number };
workAreaSize: { width: number, height: number };
size: { width: number; height: number };
touchSupport: "available" | "unavailable" | "unknown";
workArea: { x: number; y: number; width: number; height: number };
workAreaSize: { width: number; height: number };
}
interface DbDoc {
_id: string,
_rev?: string,
[key: string]: any
interface PluginFeature {
code: string;
explain?: string;
platform?:
| ("darwin" | "win32" | "linux")
| Array<"darwin" | "win32" | "linux">;
icon?: string;
cmds: (
| string
| {
type: "img" | "files" | "regex" | "over" | "window";
label: string;
}
)[];
mainHide?: boolean;
mainPush?: boolean;
}
interface DbReturn {
id: string,
rev?: string,
ok?: boolean,
error?: boolean,
name?: string,
message?: string
}
type PluginEnterFrom = "main" | "panel" | "hotkey" | "redirect";
interface UToolsApi {
/**
*
*/
//onPluginEnter(callback: (action: {code: string, type: string, payload: any, option: any }) => void): void;
/**
*
*/
//onMainPush(callback: (action: {code: string, type: string, payload: any }) => { icon?: string, text: string, title?: string }[], selectCallback: (action: {code: string, type: string, payload: any, option: { icon?: string, text: string, title?: string }}) => void): void;
/**
* 退
*/
//onPluginOut(callback: (processExit: boolean) => void): void;
/**
*
*/
onPluginDetach(callback: () => void): void;
/**
*
*/
//onDbPull(callback: (docs: { _id: string, _rev: string }[]) => void): void;
/**
*
* @param isRestorePreWindow true
@ -267,7 +283,11 @@ interface UToolsApi {
* @param placeholder
* @param isFocus true
*/
setSubInput(onChange: (text: string) => void, placeholder?: string, isFocus?: boolean): boolean;
setSubInput(
onChange: (input: { text: string }) => void,
placeholder?: string,
isFocus?: boolean
): boolean;
/**
*
*/
@ -294,11 +314,11 @@ interface UToolsApi {
* @param options https://www.electronjs.org/docs/api/browser-window#new-browserwindowoptions
* @param callback url
*/
//createBrowserWindow(url: string, options: { width?: number, height?: number }, callback?: () => void): { id: number, [key: string]: any, webContents: { id: number, [key: string]: any } };
/**
*
* @param {boolean|undefined} isKill `true`
*/
outPlugin(): boolean;
outPlugin(isKill?: boolean): boolean;
/**
*
*/
@ -306,97 +326,31 @@ interface UToolsApi {
/**
*
*/
getUser(): { avatar: string, nickname: string, type: string } | null;
getUser(): { avatar: string; nickname: string; type: string } | null;
/**
*
*
*/
//fetchUserServerTemporaryToken(): Promise<{ token: string, expiredAt: number }>;
/**
*
*/
//isPurchasedUser(): boolean;
// /**
// * 打开付费 (软件付费)
// * @param callback 购买成功触发
// */
// openPurchase(options: {
// /**
// * 商品 ID在「开发者工具」插件应用中创建
// */
// goodsId: string,
// /**
// * 第三方服务生成的订单号(可选)
// */
// outOrderId?: string,
// /**
// * 第三方服务附加数据在查询API和支付通知中原样返回可作为自定义参数使用(可选)
// */
// attach?: string
// }, callback?: () => void): void;
// /**
// * 打开支付 (付费付费)
// * @param callback 支付成功触发
// */
// openPayment(options: {
// /**
// * 商品 ID在「开发者工具」插件应用中创建
// */
// goodsId: string,
// /**
// * 第三方服务生成的订单号(可选)
// */
// outOrderId?: string,
// /**
// * 第三方服务附加数据在查询API和支付通知中原样返回可作为自定义参数使用(可选)
// */
// attach?: string
// }, callback?: () => void): void;
// /**
// * 获取用户支付记录
// */
// fetchUserPayments(): Promise<{ order_id: string, total_fee: number, body: string, attach: string, goods_id: string, out_order_id: string, paid_at: string }[]>;
// /**
// * 设置插件应用动态功能
// */
// setFeature(feature: {
// code: string,
// explain: string,
// platform: ('darwin' | 'win32' | 'linux') | (Array<'darwin' | 'win32' | 'linux'>),
// icon?: string,
// cmds: (string | {
// type: 'img' | 'files' | 'regex' | 'over' | 'window',
// label: string
// })[]
// }): boolean;
// /**
// * 移除插件应用动态功能
// */
// removeFeature(code: string): boolean;
// /**
// * 获取插件应用动态功能,参数为空获取所有动态功能
// */
getFeatures(codes?: string[]): {
code: string,
explain: string,
platform: ('darwin' | 'win32' | 'linux') | (Array<'darwin' | 'win32' | 'linux'>),
icon?: string,
cmds: string | {
type: 'img' | 'files' | 'regex' | 'over' | 'window',
label: string
}[]
}[];
getFeatures(codes?: string[]): PluginFeature[];
/**
*
* @todo type的多个重载
*/
redirect(label: string | string[], payload: string | { type: 'text' | 'img' | 'files', data: any }): void;
redirect(
label: string | string[],
payload: string | { type: "text" | "img" | "files"; data: any }
): void;
/**
* ubrowser
*/
getIdleUBrowsers(): { id: number, title: string, url: string}[];
getIdleUBrowsers(): { id: number; title: string; url: string }[];
/**
* ubrowser https://www.electronjs.org/docs/api/session#sessetproxyconfig
*/
setUBrowserProxy(config: {pacScript?: string, proxyRules?: string, proxyBypassRules?: string}): boolean;
setUBrowserProxy(config: {
pacScript?: string;
proxyRules?: string;
proxyBypassRules?: string;
}): boolean;
/**
* ubrowser
*/
@ -404,47 +358,68 @@ interface UToolsApi {
/**
*
*/
showNotification(body: string): void;
showNotification(body: string, featureName?: string): void;
/**
*
*/
showOpenDialog(options: {
title?: string,
defaultPath?: string,
buttonLabel?: string,
filters?: { name: string, extensions: string[] }[],
properties?: Array<'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory' | 'dontAddToRecent'>,
message?: string,
securityScopedBookmarks?: boolean
}): (string[]) | (undefined);
title?: string;
defaultPath?: string;
buttonLabel?: string;
filters?: { name: string; extensions: string[] }[];
properties?: Array<
| "openFile"
| "openDirectory"
| "multiSelections"
| "showHiddenFiles"
| "createDirectory"
| "promptToCreate"
| "noResolveAliases"
| "treatPackageAsDirectory"
| "dontAddToRecent"
>;
message?: string;
securityScopedBookmarks?: boolean;
}): string[] | undefined;
/**
*
*/
showSaveDialog(options: {
title?: string,
defaultPath?: string,
buttonLabel?: string,
filters?: { name: string, extensions: string[] }[],
message?: string,
nameFieldLabel?: string,
showsTagField?: string,
properties?: Array<'showHiddenFiles' | 'createDirectory' | 'treatPackageAsDirectory' | 'showOverwriteConfirmation' | 'dontAddToRecent'>,
securityScopedBookmarks?: boolean
}): (string) | (undefined);
title?: string;
defaultPath?: string;
buttonLabel?: string;
filters?: { name: string; extensions: string[] }[];
message?: string;
nameFieldLabel?: string;
showsTagField?: string;
properties?: Array<
| "showHiddenFiles"
| "createDirectory"
| "treatPackageAsDirectory"
| "showOverwriteConfirmation"
| "dontAddToRecent"
>;
securityScopedBookmarks?: boolean;
}): string | undefined;
/**
*
*/
findInPage(text: string, options?: {
forward?: boolean,
findNext?: boolean,
matchCase?: boolean,
wordStart?: boolean,
medialCapitalAsWordStart?: boolean
}): void;
findInPage(
text: string,
options?: {
forward?: boolean;
findNext?: boolean;
matchCase?: boolean;
wordStart?: boolean;
medialCapitalAsWordStart?: boolean;
}
): void;
/**
*
*/
stopFindInPage (action: 'clearSelection' | 'keepSelection' | 'activateSelection'): void;
stopFindInPage(
action: "clearSelection" | "keepSelection" | "activateSelection"
): void;
/**
*
*/
@ -452,7 +427,9 @@ interface UToolsApi {
/**
*
*/
screenColorPick(callback: (color: { hex: string, rgb: string }) => void): void;
screenColorPick(
callback: (color: { hex: string; rgb: string }) => void
): void;
/**
*
*/
@ -472,11 +449,32 @@ interface UToolsApi {
/**
*
*/
getPath(name: 'home' | 'appData' | 'userData' | 'cache' | 'temp' | 'exe' | 'module' | 'desktop' | 'documents' | 'downloads' | 'music' | 'pictures' | 'videos' | 'logs' | 'pepperFlashSystemPlugin'): string;
getPath(
name:
| "home"
| "appData"
| "userData"
| "cache"
| "temp"
| "exe"
| "module"
| "desktop"
| "documents"
| "downloads"
| "music"
| "pictures"
| "videos"
| "logs"
| "pepperFlashSystemPlugin"
): string;
/**
*
*/
getFileIcon(filePath: string): string;
/**
* , 'main' | 'detach' | 'browser' createBrowserWindow
*/
getWindowType(): "main" | "detach" | "browser";
/**
*
*/
@ -493,10 +491,15 @@ interface UToolsApi {
/**
*
*/
getCopyedFiles(): { isFile: boolean, isDirectory: boolean, name: string, path: string }[];
getCopyedFiles(): {
isFile: boolean;
isDirectory: boolean;
name: string;
path: string;
}[];
/**
* (linux )
*/
*/
readCurrentFolderPath(): Promise<string>;
/**
* URL(linux )
@ -509,6 +512,10 @@ interface UToolsApi {
*
*/
shellOpenPath(fullPath: string): void;
/**
*
*/
shellTrashItem(filename: string): Promise<void>;
/**
*
*/
@ -522,25 +529,36 @@ interface UToolsApi {
*/
shellBeep(): void;
/*
*
*/
*
*/
hideMainWindowTypeString(str: string): void;
/*
*
*/
*
*/
hideMainWindowPasteFile(file: string | string[]): void;
/*
*
*/
hideMainWindowPasteImage(img: string): void;
*
*/
hideMainWindowPasteImage(img: string | Uint8Array): void;
/*
*
*/
*
*/
hideMainWindowPasteText(text: string): void;
/**
*
*/
simulateKeyboardTap(key: string, ...modifier: ('control' | 'ctrl' | 'shift' | 'option' | 'alt' | 'command' | 'super')[]): void;
simulateKeyboardTap(
key: string,
...modifier: (
| "control"
| "ctrl"
| "shift"
| "option"
| "alt"
| "command"
| "super"
)[]
): void;
/**
*
*/
@ -560,7 +578,7 @@ interface UToolsApi {
/**
*
*/
getCursorScreenPoint(): { x: number, y: number };
getCursorScreenPoint(): { x: number; y: number };
/**
*
*/
@ -572,15 +590,56 @@ interface UToolsApi {
/**
*
*/
getDisplayNearestPoint(point: { x: number, y: number }): Display;
getDisplayNearestPoint(point: { x: number; y: number }): Display;
/**
*
*/
getDisplayMatching(rect: { x: number, y: number, width: number, height: number }): Display;
getDisplayMatching(rect: {
x: number;
y: number;
width: number;
height: number;
}): Display;
/**
* DIP
*/
screenToDipPoint(point: { x: number; y: number }): { x: number; y: number };
/**
* DIP
*/
dipToScreenPoint(point: { x: number; y: number }): { x: number; y: number };
/**
* DIP
*/
screenToDipRect(rect: {
x: number;
y: number;
width: number;
height: number;
}): { x: number; y: number; width: number; height: number };
/**
* DIP
*/
dipToScreenRect(rect: {
x: number;
y: number;
width: number;
height: number;
}): { x: number; y: number; width: number; height: number };
/**
*
*/
desktopCaptureSources(options: { types: string[], thumbnailSize?: { width: number, height: number }, fetchWindowIcons?: boolean }):Promise<{appIcon: {}, display_id: string, id: string, name: string, thumbnail: {} }>;
desktopCaptureSources(options: {
types: string[];
thumbnailSize?: { width: number; height: number };
fetchWindowIcons?: boolean;
}): Promise<{
appIcon: {};
display_id: string;
id: string;
name: string;
thumbnail: {};
}>;
/**
*
*/
@ -598,113 +657,6 @@ interface UToolsApi {
*/
isLinux(): boolean;
// db: {
// /**
// * 创建/更新文档
// */
// put(doc: DbDoc): DbReturn;
// /**
// * 获取文档
// */
// get(id: string): DbDoc | null;
// /**
// * 删除文档
// */
// remove(doc: string | DbDoc): DbReturn;
// /**
// * 批量操作文档(新增、修改、删除)
// */
// bulkDocs(docs: DbDoc[]): DbReturn[];
// /**
// * 获取所有文档 可根据文档id前缀查找
// */
// allDocs(key?: string): DbDoc[];
// /**
// * 存储附件到新文档
// * @param docId 文档ID
// * @param attachment 附件 buffer
// * @param type 附件类型示例image/png, text/plain
// */
// postAttachment(docId: string, attachment: Uint8Array, type: string): DbReturn;
// /**
// * 获取附件
// * @param docId 文档ID
// */
// getAttachment(docId: string): Uint8Array | null;
// /**
// * 获取附件类型
// * @param docId 文档ID
// */
// getAttachmentType(docId: string): string | null;
// /**
// * 云端复制数据状态 (null: 未开启数据同步、0: 已完成复制、1复制中)
// */
// replicateStateFromCloud(): null | 0 | 1;
// /**
// * 异步
// */
// promises: {
// /**
// * 创建/更新文档
// */
// put(doc: DbDoc): Promise<DbReturn>;
// /**
// * 获取文档
// */
// get(id: string): Promise<DbDoc | null>;
// /**
// * 删除文档
// */
// remove(doc: string | DbDoc): Promise<DbReturn>;
// /**
// * 批量操作文档(新增、修改、删除)
// */
// bulkDocs(docs: DbDoc[]): Promise<DbReturn[]>;
// /**
// * 获取所有文档 可根据文档id前缀查找
// */
// allDocs(key?: string): Promise<DbDoc[]>;
// /**
// * 存储附件到新文档
// * @param docId 文档ID
// * @param attachment 附件 buffer
// * @param type 附件类型示例image/png, text/plain
// */
// postAttachment(docId: string, attachment: Uint8Array, type: string): Promise<DbReturn>;
// /**
// * 获取附件
// * @param docId 文档ID
// */
// getAttachment(docId: string): Promise<Uint8Array | null>;
// /**
// * 获取附件类型
// * @param docId 文档ID
// */
// getAttachmentType(docId: string): Promise<string | null>;
// /**
// * 云端复制数据状态 (null: 未开启数据同步、0: 已完成复制、1复制中)
// */
// replicateStateFromCloud(): Promise<null | 0 | 1>;
// }
// };
// dbStorage: {
// /**
// * 键值对存储,如果键名存在,则更新其对应的值
// * @param key 键名(同时为文档ID)
// * @param value 键值
// */
// setItem (key: string, value: any): void;
// /**
// * 获取键名对应的值
// */
// getItem (key: string): any;
// /**
// * 删除键值对(删除文档)
// */
// removeItem (key: string): void;
// };
ubrowser: UBrowser;
}