Skip to content

Commit 1ee338c

Browse files
Fix for WebView
1 parent 31dedfa commit 1ee338c

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="ru">
33
<head>
4+
<script src="webview-stub.js"></script>
45
<meta charset="UTF-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1.0">
67
<title>🤿 RedPhone DX Config</title>
@@ -185,8 +186,7 @@ <h2 data-i18n="log_title">Лог обмена</h2>
185186
<span class="footer-desc" data-i18n="footer_desc">Open Source Configuration Tool</span>
186187
</div>
187188
</div>
188-
</footer>
189-
189+
</footer>
190190
<!-- NMEA + Serial + RPHPort -->
191191
<script src="rph-nmea.js"></script>
192192
<script src="serial-bridge.js"></script>

webview-stub.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// webview-stub.js — заглушка Web Serial API для WebView
2+
// Не мешает работе в обычных браузерах с реальным Web Serial API
3+
(function() {
4+
// Проверяем, есть ли уже navigator.serial (в обычном Chrome — есть)
5+
if (navigator.serial) {
6+
console.log('[Stub] Real Web Serial API detected, skipping stub');
7+
return;
8+
}
9+
10+
console.log('[Stub] Creating virtual serial port for WebView');
11+
12+
var _port = null;
13+
14+
navigator.serial = {
15+
requestPort: function(filters) {
16+
console.log('[Stub] requestPort called', filters);
17+
if (!_port) {
18+
_port = {
19+
readable: new ReadableStream({
20+
start: function(controller) {
21+
window._stubController = controller;
22+
console.log('[Stub] ReadableStream started');
23+
}
24+
}),
25+
writable: new WritableStream({
26+
write: function(chunk) {
27+
var text = typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
28+
console.log('[Stub] Write:', text);
29+
if (window._uartWriteCallback) {
30+
window._uartWriteCallback(text);
31+
}
32+
}
33+
}),
34+
open: function(options) {
35+
console.log('[Stub] Port opened with', options);
36+
return Promise.resolve();
37+
},
38+
close: function() {
39+
console.log('[Stub] Port closed');
40+
return Promise.resolve();
41+
},
42+
getInfo: function() {
43+
return {
44+
usbVendorId: 0x0403,
45+
usbProductId: 0x6001
46+
};
47+
}
48+
};
49+
}
50+
return Promise.resolve(_port);
51+
},
52+
53+
getPorts: function() {
54+
console.log('[Stub] getPorts called');
55+
var ports = _port ? [_port] : [];
56+
return Promise.resolve(ports);
57+
},
58+
59+
addEventListener: function(event, callback) {
60+
console.log('[Stub] addEventListener:', event);
61+
if (event === 'connect') {
62+
// Сразу вызываем callback с виртуальным событием
63+
setTimeout(function() {
64+
callback({ target: navigator.serial });
65+
}, 100);
66+
}
67+
},
68+
69+
removeEventListener: function(event, callback) {
70+
console.log('[Stub] removeEventListener:', event);
71+
}
72+
};
73+
74+
console.log('[Stub] Virtual serial port ready');
75+
})();

0 commit comments

Comments
 (0)