@asdf-overlay/electron 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +7 -0
- package/lib/index.js +2 -0
- package/lib/input/conv.d.ts +3 -0
- package/lib/input/conv.js +159 -0
- package/lib/input/index.d.ts +24 -0
- package/lib/input/index.js +286 -0
- package/lib/surface.d.ts +19 -0
- package/lib/surface.js +66 -0
- package/package.json +33 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Cursor } from '@asdf-overlay/core';
|
|
2
|
+
// https://www.electronjs.org/docs/latest/api/web-contents
|
|
3
|
+
// https://developer.mozilla.org/ko/docs/Web/CSS/cursor
|
|
4
|
+
export function toCursor(cursor) {
|
|
5
|
+
switch (cursor) {
|
|
6
|
+
case 'pointer': return Cursor.Default;
|
|
7
|
+
case 'crosshair': return Cursor.Crosshair;
|
|
8
|
+
case 'hand': return Cursor.Pointer;
|
|
9
|
+
case 'text': return Cursor.Text;
|
|
10
|
+
case 'wait': return Cursor.Wait;
|
|
11
|
+
case 'help': return Cursor.Help;
|
|
12
|
+
case 'e-resize':
|
|
13
|
+
case 'w-resize':
|
|
14
|
+
case 'ew-resize': return Cursor.EastWestResize;
|
|
15
|
+
case 'n-resize':
|
|
16
|
+
case 's-resize':
|
|
17
|
+
case 'ns-resize': return Cursor.NorthSouthResize;
|
|
18
|
+
case 'ne-resize':
|
|
19
|
+
case 'sw-resize':
|
|
20
|
+
case 'nesw-resize': return Cursor.NorthEastSouthWestResize;
|
|
21
|
+
case 'nw-resize':
|
|
22
|
+
case 'se-resize':
|
|
23
|
+
case 'nwse-resize': return Cursor.NorthWestSouthEastResize;
|
|
24
|
+
case 'col-resize': return Cursor.ColResize;
|
|
25
|
+
case 'row-resize': return Cursor.RowResize;
|
|
26
|
+
case 'm-panning': return Cursor.PanMiddle;
|
|
27
|
+
case 'm-panning-vertical': return Cursor.PanMiddleVertical;
|
|
28
|
+
case 'm-panning-horizontal': return Cursor.PanMiddleHorizontal;
|
|
29
|
+
case 'e-panning': return Cursor.PanEast;
|
|
30
|
+
case 'n-panning': return Cursor.PanNorth;
|
|
31
|
+
case 'ne-panning': return Cursor.PanNorthEast;
|
|
32
|
+
case 'nw-panning': return Cursor.PanNorthWest;
|
|
33
|
+
case 's-panning': return Cursor.PanSouth;
|
|
34
|
+
case 'se-panning': return Cursor.PanSouthEast;
|
|
35
|
+
case 'sw-panning': return Cursor.PanSouthWest;
|
|
36
|
+
case 'w-panning': return Cursor.PanWest;
|
|
37
|
+
case 'move': return Cursor.Move;
|
|
38
|
+
case 'vertical-text': return Cursor.VerticalText;
|
|
39
|
+
case 'cell': return Cursor.Cell;
|
|
40
|
+
case 'alias': return Cursor.Alias;
|
|
41
|
+
case 'progress': return Cursor.Progress;
|
|
42
|
+
case 'nodrop':
|
|
43
|
+
case 'not-allowed': return Cursor.NotAllowed;
|
|
44
|
+
case 'copy': return Cursor.Copy;
|
|
45
|
+
case 'none': return;
|
|
46
|
+
case 'zoom-in': return Cursor.ZoomIn;
|
|
47
|
+
case 'zoom-out': return Cursor.ZoomOut;
|
|
48
|
+
case 'grab': return Cursor.Grab;
|
|
49
|
+
case 'grabbing': return Cursor.Grabbing;
|
|
50
|
+
default: return Cursor.Default;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// As per https://www.electronjs.org/docs/latest/api/accelerator
|
|
54
|
+
// and https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
|
|
55
|
+
export const KEYS = {
|
|
56
|
+
8: 'Backspace',
|
|
57
|
+
9: 'Tab',
|
|
58
|
+
13: 'Enter',
|
|
59
|
+
16: 'Shift',
|
|
60
|
+
17: 'Control',
|
|
61
|
+
18: 'Alt',
|
|
62
|
+
20: 'Capslock',
|
|
63
|
+
27: 'Escape',
|
|
64
|
+
32: 'Space',
|
|
65
|
+
33: 'PageUp',
|
|
66
|
+
34: 'PageDown',
|
|
67
|
+
35: 'End',
|
|
68
|
+
36: 'Home',
|
|
69
|
+
37: 'Left',
|
|
70
|
+
38: 'Up',
|
|
71
|
+
39: 'Right',
|
|
72
|
+
44: 'PrintScreen',
|
|
73
|
+
45: 'Insert',
|
|
74
|
+
46: 'Delete',
|
|
75
|
+
48: '0',
|
|
76
|
+
49: '1',
|
|
77
|
+
50: '2',
|
|
78
|
+
51: '3',
|
|
79
|
+
52: '4',
|
|
80
|
+
53: '5',
|
|
81
|
+
54: '6',
|
|
82
|
+
55: '7',
|
|
83
|
+
56: '8',
|
|
84
|
+
57: '9',
|
|
85
|
+
65: 'A',
|
|
86
|
+
66: 'B',
|
|
87
|
+
67: 'C',
|
|
88
|
+
68: 'D',
|
|
89
|
+
69: 'E',
|
|
90
|
+
70: 'F',
|
|
91
|
+
71: 'G',
|
|
92
|
+
72: 'H',
|
|
93
|
+
73: 'I',
|
|
94
|
+
74: 'J',
|
|
95
|
+
75: 'K',
|
|
96
|
+
76: 'L',
|
|
97
|
+
77: 'M',
|
|
98
|
+
78: 'N',
|
|
99
|
+
79: 'O',
|
|
100
|
+
80: 'P',
|
|
101
|
+
81: 'Q',
|
|
102
|
+
82: 'R',
|
|
103
|
+
83: 'S',
|
|
104
|
+
84: 'T',
|
|
105
|
+
85: 'U',
|
|
106
|
+
86: 'V',
|
|
107
|
+
87: 'W',
|
|
108
|
+
88: 'X',
|
|
109
|
+
89: 'Y',
|
|
110
|
+
90: 'Z',
|
|
111
|
+
91: 'Super',
|
|
112
|
+
92: 'Super',
|
|
113
|
+
93: 'Meta',
|
|
114
|
+
112: 'F1',
|
|
115
|
+
113: 'F2',
|
|
116
|
+
114: 'F3',
|
|
117
|
+
115: 'F4',
|
|
118
|
+
116: 'F5',
|
|
119
|
+
117: 'F6',
|
|
120
|
+
118: 'F7',
|
|
121
|
+
119: 'F8',
|
|
122
|
+
120: 'F9',
|
|
123
|
+
121: 'F10',
|
|
124
|
+
122: 'F11',
|
|
125
|
+
123: 'F12',
|
|
126
|
+
124: 'F13',
|
|
127
|
+
125: 'F14',
|
|
128
|
+
126: 'F15',
|
|
129
|
+
127: 'F16',
|
|
130
|
+
128: 'F17',
|
|
131
|
+
129: 'F18',
|
|
132
|
+
130: 'F19',
|
|
133
|
+
131: 'F20',
|
|
134
|
+
132: 'F21',
|
|
135
|
+
133: 'F22',
|
|
136
|
+
134: 'F23',
|
|
137
|
+
135: 'F24',
|
|
138
|
+
144: 'Numlock',
|
|
139
|
+
145: 'Scrolllock',
|
|
140
|
+
176: 'MediaNextTrack',
|
|
141
|
+
177: 'MediaPreviousTrack',
|
|
142
|
+
178: 'MediaStop',
|
|
143
|
+
179: 'MediaPlayPause',
|
|
144
|
+
181: 'VolumeMute',
|
|
145
|
+
182: 'VolumeDown',
|
|
146
|
+
183: 'VolumeUp',
|
|
147
|
+
186: ';',
|
|
148
|
+
187: '=',
|
|
149
|
+
188: ',',
|
|
150
|
+
189: '-',
|
|
151
|
+
190: '.',
|
|
152
|
+
191: '/',
|
|
153
|
+
192: '`',
|
|
154
|
+
219: '[',
|
|
155
|
+
220: '\\',
|
|
156
|
+
221: ']',
|
|
157
|
+
222: '\'',
|
|
158
|
+
225: 'AltGr',
|
|
159
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WebContents } from 'electron';
|
|
2
|
+
import type { OverlayWindow } from '../index.js';
|
|
3
|
+
import type { CursorInput, KeyboardInput } from '@asdf-overlay/core/input';
|
|
4
|
+
export declare class ElectronOverlayInput {
|
|
5
|
+
private readonly window;
|
|
6
|
+
private readonly contents;
|
|
7
|
+
private readonly cursorInputHandler;
|
|
8
|
+
private readonly keyboardInputHandler;
|
|
9
|
+
private readonly cursorChangedHandler;
|
|
10
|
+
forwardInput: boolean;
|
|
11
|
+
private constructor();
|
|
12
|
+
static connect(window: OverlayWindow, contents: WebContents): ElectronOverlayInput;
|
|
13
|
+
disconnect(): Promise<void>;
|
|
14
|
+
private readonly clickCounts;
|
|
15
|
+
private processCursorAction;
|
|
16
|
+
private readonly lastWindowCursor;
|
|
17
|
+
sendCursorInput(input: CursorInput): void;
|
|
18
|
+
private readonly modifiersMap;
|
|
19
|
+
private modifiers;
|
|
20
|
+
private updateModifiers;
|
|
21
|
+
sendKeyboardInput(input: KeyboardInput): void;
|
|
22
|
+
private processIme;
|
|
23
|
+
private sendInput;
|
|
24
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { KEYS, toCursor } from './conv.js';
|
|
2
|
+
import { Cursor } from '@asdf-overlay/core';
|
|
3
|
+
export class ElectronOverlayInput {
|
|
4
|
+
window;
|
|
5
|
+
contents;
|
|
6
|
+
cursorInputHandler;
|
|
7
|
+
keyboardInputHandler;
|
|
8
|
+
cursorChangedHandler;
|
|
9
|
+
forwardInput = false;
|
|
10
|
+
constructor(window, contents) {
|
|
11
|
+
this.window = window;
|
|
12
|
+
this.contents = contents;
|
|
13
|
+
this.window = { ...window };
|
|
14
|
+
this.window.overlay.event.on('cursor_input', this.cursorInputHandler = (id, input) => {
|
|
15
|
+
if (id !== window.id) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
this.sendCursorInput(input);
|
|
19
|
+
});
|
|
20
|
+
this.window.overlay.event.on('keyboard_input', this.keyboardInputHandler = (id, input) => {
|
|
21
|
+
if (id !== window.id) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.sendKeyboardInput(input);
|
|
25
|
+
});
|
|
26
|
+
this.contents.on('cursor-changed', this.cursorChangedHandler = (_, type) => {
|
|
27
|
+
void this.window.overlay.setBlockingCursor(this.window.id, toCursor(type));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static connect(window, contents) {
|
|
31
|
+
return new ElectronOverlayInput({ ...window }, contents);
|
|
32
|
+
}
|
|
33
|
+
async disconnect() {
|
|
34
|
+
this.window.overlay.event.off('cursor_input', this.cursorInputHandler);
|
|
35
|
+
this.window.overlay.event.off('keyboard_input', this.keyboardInputHandler);
|
|
36
|
+
this.contents.off('cursor-changed', this.cursorChangedHandler);
|
|
37
|
+
try {
|
|
38
|
+
await this.window.overlay.setBlockingCursor(this.window.id, Cursor.Default);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
//
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
clickCounts = [];
|
|
45
|
+
processCursorAction(input, movementX, movementY) {
|
|
46
|
+
let button;
|
|
47
|
+
switch (input.action) {
|
|
48
|
+
case 'Left': {
|
|
49
|
+
button = 'left';
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'Middle': {
|
|
53
|
+
button = 'middle';
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'Right': {
|
|
57
|
+
button = 'right';
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'Forward': {
|
|
61
|
+
this.contents.navigationHistory.goForward();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
case 'Back': {
|
|
65
|
+
this.contents.navigationHistory.goBack();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (input.state === 'Pressed') {
|
|
70
|
+
const clickCount = 1 + ~~input.doubleClick;
|
|
71
|
+
this.clickCounts.push(clickCount);
|
|
72
|
+
this.sendInput({
|
|
73
|
+
type: 'mouseDown',
|
|
74
|
+
button,
|
|
75
|
+
clickCount,
|
|
76
|
+
x: input.clientX,
|
|
77
|
+
y: input.clientY,
|
|
78
|
+
globalX: input.windowX,
|
|
79
|
+
globalY: input.windowY,
|
|
80
|
+
movementX,
|
|
81
|
+
movementY,
|
|
82
|
+
modifiers: this.modifiers,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const clickCount = this.clickCounts.pop() ?? 1;
|
|
87
|
+
this.sendInput({
|
|
88
|
+
type: 'mouseUp',
|
|
89
|
+
button,
|
|
90
|
+
clickCount,
|
|
91
|
+
x: input.clientX,
|
|
92
|
+
y: input.clientY,
|
|
93
|
+
globalX: input.windowX,
|
|
94
|
+
globalY: input.windowY,
|
|
95
|
+
movementX,
|
|
96
|
+
movementY,
|
|
97
|
+
modifiers: this.modifiers,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
lastWindowCursor = {
|
|
102
|
+
x: 0,
|
|
103
|
+
y: 0,
|
|
104
|
+
};
|
|
105
|
+
sendCursorInput(input) {
|
|
106
|
+
const movementX = input.windowX - this.lastWindowCursor.x;
|
|
107
|
+
const movementY = input.windowY - this.lastWindowCursor.y;
|
|
108
|
+
switch (input.kind) {
|
|
109
|
+
case 'Enter': {
|
|
110
|
+
this.sendInput({
|
|
111
|
+
type: 'mouseEnter',
|
|
112
|
+
x: input.clientX,
|
|
113
|
+
y: input.clientY,
|
|
114
|
+
globalX: input.windowX,
|
|
115
|
+
globalY: input.windowY,
|
|
116
|
+
movementX,
|
|
117
|
+
movementY,
|
|
118
|
+
modifiers: this.modifiers,
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'Leave': {
|
|
123
|
+
this.sendInput({
|
|
124
|
+
type: 'mouseLeave',
|
|
125
|
+
x: input.clientX,
|
|
126
|
+
y: input.clientY,
|
|
127
|
+
globalX: input.windowX,
|
|
128
|
+
globalY: input.windowY,
|
|
129
|
+
movementX,
|
|
130
|
+
movementY,
|
|
131
|
+
modifiers: this.modifiers,
|
|
132
|
+
});
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'Move': {
|
|
136
|
+
this.sendInput({
|
|
137
|
+
type: 'mouseMove',
|
|
138
|
+
x: input.clientX,
|
|
139
|
+
y: input.clientY,
|
|
140
|
+
globalX: input.windowX,
|
|
141
|
+
globalY: input.windowY,
|
|
142
|
+
movementX,
|
|
143
|
+
movementY,
|
|
144
|
+
modifiers: this.modifiers,
|
|
145
|
+
});
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case 'Scroll': {
|
|
149
|
+
let scroll;
|
|
150
|
+
if (input.axis === 'Y') {
|
|
151
|
+
scroll = {
|
|
152
|
+
type: 'mouseWheel',
|
|
153
|
+
deltaY: input.delta,
|
|
154
|
+
x: input.clientX,
|
|
155
|
+
y: input.clientY,
|
|
156
|
+
globalX: input.windowX,
|
|
157
|
+
globalY: input.windowY,
|
|
158
|
+
movementX,
|
|
159
|
+
movementY,
|
|
160
|
+
modifiers: this.modifiers,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
scroll = {
|
|
165
|
+
type: 'mouseWheel',
|
|
166
|
+
deltaX: input.delta,
|
|
167
|
+
x: input.clientX,
|
|
168
|
+
y: input.clientY,
|
|
169
|
+
globalX: input.windowX,
|
|
170
|
+
globalY: input.windowY,
|
|
171
|
+
movementX,
|
|
172
|
+
movementY,
|
|
173
|
+
modifiers: this.modifiers,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
this.sendInput(scroll);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case 'Action': {
|
|
180
|
+
this.processCursorAction(input, movementX, movementY);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
this.lastWindowCursor.x = input.windowX;
|
|
185
|
+
this.lastWindowCursor.y = input.windowY;
|
|
186
|
+
}
|
|
187
|
+
modifiersMap = {
|
|
188
|
+
shift: false,
|
|
189
|
+
ctrl: false,
|
|
190
|
+
alt: false,
|
|
191
|
+
super: false,
|
|
192
|
+
meta: false,
|
|
193
|
+
};
|
|
194
|
+
modifiers = [];
|
|
195
|
+
updateModifiers(key, downState) {
|
|
196
|
+
switch (key) {
|
|
197
|
+
case 'Control': {
|
|
198
|
+
this.modifiersMap.ctrl = downState;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 'Shift': {
|
|
202
|
+
this.modifiersMap.shift = downState;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 'Super': {
|
|
206
|
+
this.modifiersMap.super = downState;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case 'Meta': {
|
|
210
|
+
this.modifiersMap.meta = downState;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case 'Alt': {
|
|
214
|
+
this.modifiersMap.alt = downState;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
default: {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
this.modifiers = [];
|
|
222
|
+
if (this.modifiersMap.shift) {
|
|
223
|
+
this.modifiers.push('shift');
|
|
224
|
+
}
|
|
225
|
+
if (this.modifiersMap.ctrl) {
|
|
226
|
+
this.modifiers.push('ctrl');
|
|
227
|
+
}
|
|
228
|
+
if (this.modifiersMap.alt) {
|
|
229
|
+
this.modifiers.push('alt');
|
|
230
|
+
}
|
|
231
|
+
if (this.modifiersMap.meta) {
|
|
232
|
+
this.modifiers.push('meta');
|
|
233
|
+
}
|
|
234
|
+
if (this.modifiersMap.super) {
|
|
235
|
+
this.modifiers.push('cmd');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
sendKeyboardInput(input) {
|
|
239
|
+
switch (input.kind) {
|
|
240
|
+
case 'Key': {
|
|
241
|
+
const keyCode = KEYS[input.key.code];
|
|
242
|
+
if (!keyCode) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const pressed = input.state === 'Pressed';
|
|
246
|
+
this.updateModifiers(keyCode, pressed);
|
|
247
|
+
this.sendInput({
|
|
248
|
+
type: pressed ? 'keyDown' : 'keyUp',
|
|
249
|
+
keyCode,
|
|
250
|
+
modifiers: this.modifiers,
|
|
251
|
+
});
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
case 'Char': {
|
|
255
|
+
this.sendInput({
|
|
256
|
+
type: 'char',
|
|
257
|
+
keyCode: input.ch,
|
|
258
|
+
modifiers: this.modifiers,
|
|
259
|
+
});
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
case 'Ime': {
|
|
263
|
+
this.processIme(input);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
processIme(input) {
|
|
269
|
+
if (input.ime.kind !== 'Commit') {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
for (const ch of input.ime.text) {
|
|
273
|
+
this.sendInput({
|
|
274
|
+
type: 'char',
|
|
275
|
+
keyCode: ch,
|
|
276
|
+
modifiers: this.modifiers,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
sendInput(e) {
|
|
281
|
+
if (!this.forwardInput) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.contents.sendInputEvent(e);
|
|
285
|
+
}
|
|
286
|
+
}
|
package/lib/surface.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WebContents } from 'electron';
|
|
2
|
+
import type { OverlayWindow } from './index.js';
|
|
3
|
+
import EventEmitter from 'node:events';
|
|
4
|
+
type Emitter = EventEmitter<{
|
|
5
|
+
error: [e: unknown];
|
|
6
|
+
}>;
|
|
7
|
+
export declare class ElectronOverlaySurface {
|
|
8
|
+
private readonly window;
|
|
9
|
+
private readonly contents;
|
|
10
|
+
readonly events: Emitter;
|
|
11
|
+
private handler;
|
|
12
|
+
private constructor();
|
|
13
|
+
static connect(window: OverlayWindow, contents: WebContents): ElectronOverlaySurface;
|
|
14
|
+
disconnect(): Promise<void>;
|
|
15
|
+
private paintAccelerated;
|
|
16
|
+
private paintSoftware;
|
|
17
|
+
private emitError;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
package/lib/surface.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
export class ElectronOverlaySurface {
|
|
3
|
+
window;
|
|
4
|
+
contents;
|
|
5
|
+
events = new EventEmitter();
|
|
6
|
+
handler;
|
|
7
|
+
constructor(window, contents) {
|
|
8
|
+
this.window = window;
|
|
9
|
+
this.contents = contents;
|
|
10
|
+
this.handler = (e, rect, image) => {
|
|
11
|
+
const offscreenTexture = e.texture;
|
|
12
|
+
if (offscreenTexture) {
|
|
13
|
+
void this.paintAccelerated(offscreenTexture.textureInfo).finally(() => {
|
|
14
|
+
offscreenTexture.release();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const size = image.getSize();
|
|
19
|
+
// offscreenTexture undefined if image is empty, handle the case
|
|
20
|
+
if (size.width === 0 || size.height === 0) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
void this.paintSoftware(rect, image);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
contents.on('paint', this.handler);
|
|
27
|
+
contents.invalidate();
|
|
28
|
+
}
|
|
29
|
+
static connect(window, contents) {
|
|
30
|
+
return new ElectronOverlaySurface({ ...window }, contents);
|
|
31
|
+
}
|
|
32
|
+
async disconnect() {
|
|
33
|
+
this.contents.off('paint', this.handler);
|
|
34
|
+
await this.window.overlay.clearSurface(this.window.id);
|
|
35
|
+
}
|
|
36
|
+
async paintAccelerated(texture) {
|
|
37
|
+
const rect = texture.metadata.captureUpdateRect ?? texture.contentRect;
|
|
38
|
+
// update only changed part
|
|
39
|
+
try {
|
|
40
|
+
await this.window.overlay.updateShtex(this.window.id, texture.codedSize.width, texture.codedSize.height, texture.sharedTextureHandle, {
|
|
41
|
+
dstX: rect.x,
|
|
42
|
+
dstY: rect.y,
|
|
43
|
+
src: rect,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
this.emitError(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async paintSoftware(_dirtyRect, image) {
|
|
51
|
+
// TODO:: update only changed part
|
|
52
|
+
try {
|
|
53
|
+
await this.window.overlay.updateBitmap(this.window.id, image.getSize().width, image.toBitmap());
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
this.emitError(e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
emitError(e) {
|
|
60
|
+
if (this.events.listenerCount('error') !== 0) {
|
|
61
|
+
this.events.emit('error', e);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@asdf-overlay/electron",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Asdf overlay Electron integration",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"author": "storycraft <storycraft@pancake.sh>",
|
|
9
|
+
"homepage": "https://github.com/storycraft/asdf-overlay#readme",
|
|
10
|
+
"license": "MIT OR Apache-2.0",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/storycraft/asdf-overlay/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/storycraft/asdf-overlay"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"lib/**/*"
|
|
20
|
+
],
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^24.1.0",
|
|
23
|
+
"typescript": "^5.8.3"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"electron": "^37.3.1",
|
|
27
|
+
"@asdf-overlay/core": "0.9.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build:dist": "tsc",
|
|
31
|
+
"build": "npm run build:dist"
|
|
32
|
+
}
|
|
33
|
+
}
|