-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebview-stub.js
More file actions
68 lines (58 loc) · 2 KB
/
webview-stub.js
File metadata and controls
68 lines (58 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// webview-stub.js — заглушка Web Serial API для WebView
(function() {
if (navigator.serial) {
console.log('[Stub] Real Web Serial API detected, skipping');
return;
}
var _port = {
_readable: null,
_writable: null,
get readable() {
if (!this._readable) {
this._readable = new ReadableStream({
start: function(controller) {
window._stubController = controller;
}
});
}
return this._readable;
},
get writable() {
if (!this._writable) {
this._writable = new WritableStream({
write: function(chunk) {
var text = typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
if (window._uartWriteCallback) {
window._uartWriteCallback(text);
}
}
});
}
return this._writable;
},
open: function(options) {
this._readable = null;
this._writable = null;
return Promise.resolve();
},
close: function() {
return Promise.resolve();
},
getInfo: function() {
return { usbVendorId: 0x0403, usbProductId: 0x6001 };
},
forget: function() { return Promise.resolve(); },
setSignals: function(s) { return Promise.resolve(); },
getSignals: function() { return Promise.resolve({}); }
};
navigator.serial = {
requestPort: function(filters) {
return Promise.resolve(_port);
},
getPorts: function() {
return Promise.resolve([_port]);
},
addEventListener: function(event, callback) {},
removeEventListener: function(event, callback) {}
};
})();