This commit is contained in:
2025-12-26 18:13:15 +08:00
parent 66e6370013
commit 413c147109
32 changed files with 2449 additions and 205 deletions

View File

@@ -0,0 +1,67 @@
import { app, core } from "../../app.ts";
/**
* 浏览器窗口边界信息
*/
export interface Bounds {
/**
* 窗口距离屏幕左边缘的偏移量(像素)
*/
left?: number;
/**
* 窗口距离屏幕上边缘的偏移量(像素)
*/
top?: number;
/**
* 窗口宽度(像素)
*/
width?: number;
/**
* 窗口高度(像素)
*/
height?: number;
/**
* 窗口状态,默认为 normal
*/
windowState?: "normal" | "minimized" | "maximized" | "fullscreen";
}
const desc = `窗口管理,参数为窗口位置和大小信息
参数示例:
left: 窗口左上角横坐标
top: 窗口左上角纵坐标
width: 窗口宽度
height: 窗口高度
windowState: 窗口状态,可选值有 normal正常, minimized最小化, maximized最大化, fullscreen全屏
`;
app.route({
path: 'window',
key: 'manager',
description: desc,
middleware: ['auth']
}).define(async (ctx) => {
const bounds = ctx.query as Bounds || {};
const { left, top, width, height, windowState } = bounds;
if (!left && !top && !width && !height && !windowState) {
bounds.windowState = 'normal'
}
const page = await core.getPage();
const cdp = await page.context().newCDPSession(page);
try {
const { windowId } = await cdp.send('Browser.getWindowForTarget');
const page2 = { left: -1920, top: 0 }
const full = { windowState: 'fullscreen' }
// 设定传入的窗口参数
await cdp.send('Browser.setWindowBounds', {
windowId,
bounds: bounds
});
ctx.body = { success: true, message: '窗口已调整' };
} catch (error) {
ctx.throw!(500, '调整窗口失败: ' + (error as Error).message);
} finally {
// 关闭session
await cdp.detach();
}
}).addTo(app);