Skip to content

Commit da79be6

Browse files
mondalacicursoragentert78gb
authored
feat: expand macro field limits according to user configuration data types (#2998)
Align mouse move/scroll and delay macro editor limits with Int16 and UInt16 serialization bounds, and clamp out-of-range coordinate input. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Kiss Róbert <ert78gb@gmail.com>
1 parent 1d271ef commit da79be6

5 files changed

Lines changed: 68 additions & 35 deletions

File tree

packages/uhk-common/src/config-serializer/assert.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22

3+
export const INT8_MIN = -0x80;
4+
export const INT8_MAX = 0x7F;
5+
export const INT16_MIN = -0x8000;
6+
export const INT16_MAX = 0x7FFF;
7+
export const INT32_MIN = -0x80000000;
8+
export const INT32_MAX = 0x7FFFFFFF;
9+
export const UINT8_MAX = 0xFF;
10+
export const UINT16_MAX = 0xFFFF;
11+
export const UINT32_MAX = 0xFFFFFFFF;
12+
313
export function assertUInt8(target: any, key: string) {
4-
return assertInteger(target, key, 0, 0xFF);
14+
return assertInteger(target, key, 0, UINT8_MAX);
515
}
616

717
export function assertInt8(target: any, key: string) {
8-
return assertInteger(target, key, -0x80, 0x7F);
18+
return assertInteger(target, key, INT8_MIN, INT8_MAX);
919
}
1020

1121
export function assertUInt16(target: any, key: string) {
12-
return assertInteger(target, key, 0, 0xFFFF);
22+
return assertInteger(target, key, 0, UINT16_MAX);
1323
}
1424

1525
export function assertInt16(target: any, key: string) {
16-
return assertInteger(target, key, -0x8000, 0x7FFF);
26+
return assertInteger(target, key, INT16_MIN, INT16_MAX);
1727
}
1828

1929
export function assertUInt32(target: any, key: string) {
20-
return assertInteger(target, key, 0, 0xFFFFFFFF);
30+
return assertInteger(target, key, 0, UINT32_MAX);
2131
}
2232

2333
export function assertInt32(target: any, key: string) {
24-
return assertInteger(target, key, -0x80000000, 0x7FFFFFFF);
34+
return assertInteger(target, key, INT32_MIN, INT32_MAX);
2535
}
2636

2737
export function assertFloat(target: any, key: string) {
28-
return assertInteger(target, key, -0x80000000, 0x7FFFFFFF);
38+
return assertInteger(target, key, INT32_MIN, INT32_MAX);
2939
}
3040

3141
export function assertCompactLength(target: any, key: string) {

packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ <h4>Delay</h4>
1010
<input #macroDelayInput
1111
type="number"
1212
min="0"
13-
max="65"
13+
[max]="maxDelaySeconds"
1414
step="0.1"
1515
placeholder="Delay amount"
1616
class="form-control"
1717
[ngModel]="delay"
18-
(ngModelChange)="setDelay(macroDelayInput.value)">
18+
(ngModelChange)="setDelay(macroDelayInput.valueAsNumber)">
1919
seconds
2020
</div>
2121
</div>

packages/uhk-web/src/app/components/macro/action-editor/tab/delay/macro-delay.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import {
44
Input,
55
OnInit
66
} from '@angular/core';
7-
import { DelayMacroAction } from 'uhk-common';
7+
import { DelayMacroAction, UINT16_MAX } from 'uhk-common';
88

99
import { MacroBaseComponent } from '../macro-base.component';
1010

1111
const INITIAL_DELAY = 0.5; // In seconds
12+
const MAX_DELAY_SECONDS = UINT16_MAX / 1000;
1213

1314
@Component({
1415
selector: 'macro-delay-tab',
@@ -21,6 +22,7 @@ const INITIAL_DELAY = 0.5; // In seconds
2122
export class MacroDelayTabComponent extends MacroBaseComponent implements OnInit {
2223
@Input() macroAction: DelayMacroAction;
2324

25+
maxDelaySeconds = MAX_DELAY_SECONDS;
2426
presets: number[] = [0.1, 0.5, 1, 5, 10];
2527

2628
get delay(): number {
@@ -44,11 +46,15 @@ export class MacroDelayTabComponent extends MacroBaseComponent implements OnInit
4446
}
4547

4648
setDelay(value: number): void {
47-
this._delay = Math.min(value, 65);
48-
this.macroAction.delay = this._delay * 1000;
49-
this.validate();
49+
if (Number.isNaN(value)) {
50+
return;
51+
}
52+
53+
const delayMs = Math.min(Math.max(Math.round(value * 1000), 0), UINT16_MAX);
54+
this.macroAction.delay = delayMs;
55+
this.delay = delayMs / 1000;
5056
}
5157

52-
isMacroValid = () => this.macroAction.delay !== 0;
58+
isMacroValid = () => this.macroAction.delay > 0 && this.macroAction.delay <= UINT16_MAX;
5359

5460
}

packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.html

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ <h4>Move mouse pointer</h4>
4242
<input id="move-mouse-x"
4343
type="number"
4444
class="form-control"
45-
[(ngModel)]="macroAction['x']"
46-
(ngModelChange)="validate()"
47-
min="-9999"
48-
max="9999"
49-
maxlength="4"> pixels
45+
[ngModel]="macroAction['x']"
46+
(ngModelChange)="setCoordinate('x', $event)"
47+
[min]="INT16_MIN"
48+
[max]="INT16_MAX"
49+
maxlength="6"> pixels
5050
</div>
5151
<div class="mb-2">
5252
<label for="move-mouse-y">Y:</label>
5353
<input id="move-mouse-y"
5454
type="number"
5555
class="form-control"
56-
[(ngModel)]="macroAction['y']"
57-
(ngModelChange)="validate()"
58-
min="-9999"
59-
max="9999"
60-
maxlength="4"> pixels
56+
[ngModel]="macroAction['y']"
57+
(ngModelChange)="setCoordinate('y', $event)"
58+
[min]="INT16_MIN"
59+
[max]="INT16_MAX"
60+
maxlength="6"> pixels
6161
</div>
6262
</div>
6363
</div>
@@ -69,22 +69,22 @@ <h4>Scroll with mouse</h4>
6969
<input id="scroll-mouse-x"
7070
type="number"
7171
class="form-control"
72-
[(ngModel)]="macroAction['x']"
73-
(ngModelChange)="validate()"
74-
min="-9999"
75-
max="9999"
76-
maxlength="4"> pixels
72+
[ngModel]="macroAction['x']"
73+
(ngModelChange)="setCoordinate('x', $event)"
74+
[min]="INT16_MIN"
75+
[max]="INT16_MAX"
76+
maxlength="6"> pixels
7777
</div>
7878
<div class="mb-2">
7979
<label for="scroll-mouse-y">Y:</label>
8080
<input id="scroll-mouse-y"
8181
type="number"
8282
class="form-control"
83-
[(ngModel)]="macroAction['y']"
84-
(ngModelChange)="validate()"
85-
min="-9999"
86-
max="9999"
87-
maxlength="4"> pixels
83+
[ngModel]="macroAction['y']"
84+
(ngModelChange)="setCoordinate('y', $event)"
85+
[min]="INT16_MIN"
86+
[max]="INT16_MAX"
87+
maxlength="6"> pixels
8888
</div>
8989
</div>
9090
</div>

packages/uhk-web/src/app/components/macro/action-editor/tab/mouse/macro-mouse.component.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Component, Input, OnChanges, OnInit } from '@angular/core';
22
import { faArrowsAlt, faArrowsAltV, faHandPaper, faHandRock, faMousePointer } from '@fortawesome/free-solid-svg-icons';
33

44
import {
5+
INT16_MAX,
6+
INT16_MIN,
57
MacroMouseSubAction,
68
MouseButtons,
79
MouseButtonMacroAction,
@@ -33,6 +35,8 @@ enum TabName {
3335
export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit, OnChanges {
3436
@Input() macroAction: MouseMacroAction;
3537

38+
INT16_MAX = INT16_MAX;
39+
INT16_MIN = INT16_MIN;
3640
MouseButtons = MouseButtons;
3741
TabName = TabName;
3842
activeTab: TabName;
@@ -114,6 +118,17 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit
114118
}
115119
}
116120

121+
setCoordinate(axis: 'x' | 'y', value: number | string): void {
122+
const numericValue = Number(value);
123+
if (Number.isNaN(numericValue)) {
124+
return;
125+
}
126+
127+
const action = this.macroAction as MoveMouseMacroAction | ScrollMouseMacroAction;
128+
action[axis] = Math.min(Math.max(Math.round(numericValue), INT16_MIN), INT16_MAX);
129+
this.validate();
130+
}
131+
117132
getTabName(action: MouseMacroAction): TabName {
118133
if (action instanceof MouseButtonMacroAction) {
119134
if (!action.action || action.isOnlyClickAction()) {
@@ -137,7 +152,9 @@ export class MacroMouseTabComponent extends MacroBaseComponent implements OnInit
137152
case ScrollMouseMacroAction: {
138153
const { x, y } = this.macroAction as MoveMouseMacroAction;
139154
return x !== undefined && x !== null && y !== undefined && y !== null &&
140-
(x !== 0 || y !== 0) && x < 10000 && x > -10000 && y < 10000 && y > -10000;
155+
(x !== 0 || y !== 0) &&
156+
x >= INT16_MIN && x <= INT16_MAX &&
157+
y >= INT16_MIN && y <= INT16_MAX;
141158
}
142159

143160
case MouseButtonMacroAction: {

0 commit comments

Comments
 (0)