Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #52

Merged
merged 3 commits into from
Feb 20, 2025
Merged

Dev #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
446 changes: 446 additions & 0 deletions examples/api.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions examples/demo/profiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fetch from 'node-fetch';

const BASE_URL = 'http://localhost:49156';

export async function openProfile(windowId) {
const response = await fetch(`${BASE_URL}/profiles/open?windowId=${windowId}`);
return await response.json();
}

export async function closeProfile(windowId) {
const response = await fetch(`${BASE_URL}/profiles/close?windowId=${windowId}`);
return await response.json();
}
34 changes: 34 additions & 0 deletions examples/demo/window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import fetch from 'node-fetch';

const BASE_URL = 'http://localhost:49156';

export async function createWindow(name) {
const response = await fetch(`${BASE_URL}/window/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name,
}),
});
return await response.json();
}

export async function batchCreateWindows(windows) {
const results = [];
for (const window of windows) {
try {
const result = await createWindow(window.name);
results.push(result);
} catch (error) {
console.error(`创建窗口失败: ${window.name}`, error);
}
}
return results;
}

export async function getAllWindows() {
const response = await fetch(`${BASE_URL}/window/all`);
return await response.json();
}
30 changes: 30 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {batchCreateWindows, getAllWindows} from './demo/window.js';
import {openProfile} from './demo/profiles.js';

async function main() {
try {
// 批量创建窗口
const windowsToCreate = [{name: '窗口1'}, {name: '窗口2'}, {name: '窗口3'}];

console.log('开始创建窗口...');
const createdWindows = await batchCreateWindows(windowsToCreate);
console.log('创建的窗口:', createdWindows);

console.log('打开指定 id 的窗口');
const openResult = await openProfile(247);
console.log('打开结果:', openResult);

const windows = await getAllWindows();

const openedWindows = windows?.filter(f => f.status > 1);
console.log('已打开的窗口:', openedWindows);

const connectInfo = await fetch(`http://localhost:${openedWindows[0].port}/json/version`);

console.log(await connectInfo.json());
} catch (error) {
console.error('执行过程中出现错误:', error);
}
}

main();
Loading
Loading