Skip to content

Commit 486f9a4

Browse files
authored
Add basic Electron tests and pump its version for demos (#1379)
This pull request adds Electron version display to demo applications and updates Electron from version 31.x to 40.0.0. It also fixes timer parameter types in the turtle_tf2 demo by converting numeric literals to BigInt. **Changes:** - Updated the test command to include Electron tests via `test/electron/run_test.js` - Bumped Electron version from ^31.x to ^40.0.0 across all demo package.json files - Added Electron version display overlays to all demo renderer files - Fixed timer periods in turtle_tf2/main.js to use BigInt literals (100n, 1000n) Fix: #1378
1 parent 1fb7276 commit 486f9a4

15 files changed

Lines changed: 182 additions & 8 deletions

File tree

.github/workflows/linux-arm64-build-and-test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ jobs:
5252
- name: Install test-msgs on Linux
5353
run: |
5454
sudo apt install ros-${{ matrix.ros_distribution }}-test-msgs
55+
# Adjust dependencies based on Ubuntu version
56+
LIBASOUND_PKG="libasound2"
57+
if grep -q "24.04" /etc/os-release; then
58+
LIBASOUND_PKG="libasound2t64"
59+
fi
60+
sudo apt install -y xvfb libgtk-3-0 libnss3 $LIBASOUND_PKG libgbm-dev
5561
5662
- uses: actions/checkout@v6
5763

.github/workflows/linux-x64-build-and-test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ jobs:
5656
- name: Install test-msgs on Linux
5757
run: |
5858
sudo apt install ros-${{ matrix.ros_distribution }}-test-msgs
59+
# Adjust dependencies based on Ubuntu version
60+
LIBASOUND_PKG="libasound2"
61+
if grep -q "24.04" /etc/os-release; then
62+
LIBASOUND_PKG="libasound2t64"
63+
fi
64+
sudo apt install -y xvfb libgtk-3-0 libnss3 $LIBASOUND_PKG libgbm-dev
5965
6066
- uses: actions/checkout@v6
6167

electron_demo/car/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
},
2222
"devDependencies": {
2323
"@electron/rebuild": "^3.6.0",
24-
"electron": "^31.0.0"
24+
"electron": "^40.0.0"
2525
}
2626
}

electron_demo/car/renderer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// limitations under the License.
1212

1313
const { ipcRenderer } = require('electron');
14+
const process = require('process');
1415

1516
// DOM elements
1617
let currentCommandEl, linearXEl, angularZEl, topicNameEl;
@@ -27,6 +28,13 @@ document.addEventListener('DOMContentLoaded', function () {
2728
initializeElements();
2829
setupEventListeners();
2930
setupROSListeners();
31+
32+
const versionDiv = document.createElement('div');
33+
versionDiv.style.textAlign = 'center';
34+
versionDiv.style.padding = '10px';
35+
versionDiv.style.marginTop = '20px';
36+
versionDiv.innerText = 'Electron version: ' + process.versions.electron;
37+
document.querySelector('.container').appendChild(versionDiv);
3038
});
3139

3240
function initializeElements() {

electron_demo/manipulator/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ <h4>Two-Joint Manipulator Demo</h4>
153153
<li><strong>JointState</strong> - ROS2 sensor_msgs</li>
154154
</ul>
155155
<p>Use the sliders to control joint angles or start automatic animation.</p>
156+
<p>
157+
We are using Node.js <span id="node-version"></span>,
158+
Chromium <span id="chrome-version"></span>,
159+
and Electron <span id="electron-version"></span>.
160+
</p>
156161
<hr>
157162
<h5>🎯 What to Look For:</h5>
158163
<ul>

electron_demo/manipulator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
},
2525
"devDependencies": {
2626
"@electron/rebuild": "^3.7.2",
27-
"electron": "^31.7.7"
27+
"electron": "^40.0.0"
2828
}
2929
}

electron_demo/manipulator/renderer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// limitations under the License.
1212

1313
const { ipcRenderer } = require('electron');
14+
const process = require('process');
1415

1516
// Three.js scene components
1617
let scene, camera, renderer, controls;
@@ -28,6 +29,16 @@ let jointAngles = {
2829

2930
// Initialize the 3D scene
3031
function initScene() {
32+
const versionDiv = document.createElement('div');
33+
versionDiv.style.position = 'absolute';
34+
versionDiv.style.bottom = '10px';
35+
versionDiv.style.right = '10px';
36+
versionDiv.style.color = 'white';
37+
versionDiv.style.fontFamily = 'Arial, sans-serif';
38+
versionDiv.style.zIndex = '1000';
39+
versionDiv.innerText = 'Electron version: ' + process.versions.electron;
40+
document.body.appendChild(versionDiv);
41+
3142
const container = document.getElementById('canvas-container');
3243

3344
// Scene setup
@@ -358,6 +369,15 @@ window.addEventListener('resize', () => {
358369

359370
// UI event handlers
360371
document.addEventListener('DOMContentLoaded', () => {
372+
const replaceText = (selector, text) => {
373+
const element = document.getElementById(selector);
374+
if (element) element.innerText = text;
375+
};
376+
377+
for (const type of ['chrome', 'node', 'electron']) {
378+
replaceText(`${type}-version`, process.versions[type] || 'Unavailable');
379+
}
380+
361381
initScene();
362382
setupUIEventHandlers();
363383
startFrequencyMeasurement();

electron_demo/topics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
},
1818
"devDependencies": {
1919
"@electron/rebuild": "^3.6.0",
20-
"electron": "^31.0.0"
20+
"electron": "^40.0.0"
2121
}
2222
}

electron_demo/topics/renderer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
// limitations under the License.
1212

1313
const { ipcRenderer } = require('electron');
14+
const process = require('process');
15+
16+
document.addEventListener('DOMContentLoaded', () => {
17+
const versionDiv = document.createElement('div');
18+
versionDiv.style.position = 'fixed';
19+
versionDiv.style.bottom = '10px';
20+
versionDiv.style.left = '10px';
21+
versionDiv.innerText = 'Electron version: ' + process.versions.electron;
22+
document.body.appendChild(versionDiv);
23+
});
1424

1525
ipcRenderer.on('topic-received', function (event, response) {
1626
document.getElementById('received-topic').innerText = response;

electron_demo/turtle_tf2/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ async function createTurtleTf2Listener() {
335335
);
336336

337337
// Timer to check for transforms and control turtle2
338-
const timer = node.createTimer(1000, () => {
338+
node.createTimer(1000n, () => {
339339
// Wrap the async logic in a try-catch to handle promise rejections
340340
(async () => {
341341
try {
@@ -442,7 +442,7 @@ async function createDynamicFrameTf2Broadcaster() {
442442
const tfBroadcaster = node.createPublisher('tf2_msgs/msg/TFMessage', '/tf');
443443

444444
// Timer to broadcast dynamic transform
445-
const timer = node.createTimer(100, () => {
445+
node.createTimer(100n, () => {
446446
const now = node.now();
447447

448448
// Use a more stable time calculation to avoid NaN
@@ -535,7 +535,7 @@ async function createFixedFrameTf2Broadcaster() {
535535
const tfBroadcaster = node.createPublisher('tf2_msgs/msg/TFMessage', '/tf');
536536

537537
// Timer to broadcast fixed transform
538-
const timer = node.createTimer(100, () => {
538+
node.createTimer(100n, () => {
539539
const now = node.now();
540540
const fixedTransform = {
541541
header: {

0 commit comments

Comments
 (0)