Skip to content

fix(execute): windows scaleFactor not work #2

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

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
5 changes: 5 additions & 0 deletions src/main/agent/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ScreenshotResult,
} from '@ui-tars/desktop-shared/types';

import * as env from '@main/env';
import { logger } from '@main/logger';

import { FACTOR } from './constant';
Expand Down Expand Up @@ -56,11 +57,15 @@ export class Desktop {
screenWidth: number,
screenHeight: number,
) {
const primaryDisplay = screen.getPrimaryDisplay();
const { scaleFactor } = primaryDisplay;

await execute({
prediction,
screenWidth,
screenHeight,
logger,
scaleFactor: !env.isMacOS ? scaleFactor : 1,
});
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/agent/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const moveStraightTo = async (startX: number | null, startY: number | null) => {
};

export const execute = async (executeParams: {
scaleFactor?: number;
prediction: PredictionParsed;
screenWidth: number;
screenHeight: number;
Expand All @@ -36,11 +37,13 @@ export const execute = async (executeParams: {
screenWidth,
screenHeight,
logger = console,
scaleFactor = 1,
} = executeParams;

logger.info(
'[execute] executeParams',
JSON.stringify({
scaleFactor,
prediction,
screenWidth,
screenHeight,
Expand All @@ -53,10 +56,14 @@ export const execute = async (executeParams: {

logger.info('[execute] action_type', action_type, 'startBoxStr', startBoxStr);

const { x: startX, y: startY } = startBoxStr
const { x, y } = startBoxStr
? parseBoxToScreenCoords(startBoxStr, screenWidth, screenHeight)
: { x: null, y: null };
logger.info('[execute] [Position]', startX, startY);

const startX = x ? x * scaleFactor : null;
const startY = y ? y * scaleFactor : null;

logger.info(`[execute] [Position] (${x}, ${y}) => (${startX}, ${startY})`);

// execute configs
mouse.config.mouseSpeed = 1500;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/RunMessages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const RunMessages: React.FC<RunMessagesProps> = (props) => {
);
}
})}
{thinking && <LoadingText>正在思考...</LoadingText>}
{thinking && <LoadingText>Thinking...</LoadingText>}
</Box>
</Box>
);
Expand Down
Loading