Skip to content

Commit 8ba28c1

Browse files
committed
Address comments
1 parent 48bf45c commit 8ba28c1

5 files changed

Lines changed: 106 additions & 9 deletions

File tree

electron_demo/car/renderer.js

Lines changed: 1 addition & 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;

electron_demo/topics/renderer.js

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

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

15-
const versionDiv = document.createElement('div');
16-
versionDiv.style.position = 'fixed';
17-
versionDiv.style.bottom = '10px';
18-
versionDiv.style.left = '10px';
19-
versionDiv.innerText = 'Electron version: ' + process.versions.electron;
20-
document.body.appendChild(versionDiv);
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+
});
2124

2225
ipcRenderer.on('topic-received', function (event, response) {
2326
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(1000n, () => {
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(100n, () => {
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(100n, () => {
538+
node.createTimer(100n, () => {
539539
const now = node.now();
540540
const fixedTransform = {
541541
header: {

test/electron/run_test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const { spawn } = require('child_process');
5+
6+
let electron;
7+
try {
8+
electron = require('electron');
9+
} catch (e) {
10+
console.error(
11+
'Electron module not found. Please install electron to run this test.'
12+
);
13+
process.exit(1);
14+
}
15+
16+
console.log('Launching Electron to run test_usability.js...');
17+
const child = spawn(electron, [path.join(__dirname, 'test_usability.js')], {
18+
stdio: 'inherit',
19+
env: { ...process.env, ELECTRON_ENABLE_LOGGING: true },
20+
});
21+
22+
child.on('close', (code) => {
23+
console.log(`Electron process exited with code ${code}`);
24+
if (code === 0) {
25+
console.log('Test Passed!');
26+
process.exit(0);
27+
} else {
28+
console.error('Test Failed!');
29+
process.exit(1);
30+
}
31+
});
32+
33+
child.on('error', (err) => {
34+
console.error('Failed to start electron:', err);
35+
process.exit(1);
36+
});

test/electron/test_usability.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
const rclnodejs = require('../../index.js');
4+
const { app } = require('electron');
5+
6+
app.on('ready', () => {
7+
console.log('Electron version:', process.versions.electron);
8+
rclnodejs
9+
.init()
10+
.then(() => {
11+
console.log('rclnodejs initialized successfully.');
12+
const node = rclnodejs.createNode('test_electron_node');
13+
const publisher = node.createPublisher(
14+
'std_msgs/msg/String',
15+
'electron_test_topic'
16+
);
17+
18+
const subscription = node.createSubscription(
19+
'std_msgs/msg/String',
20+
'electron_test_topic',
21+
(msg) => {
22+
if (msg.data === 'Hello from Electron') {
23+
console.log(
24+
'Successfully received message in Electron environment.'
25+
);
26+
rclnodejs.shutdown();
27+
app.quit();
28+
process.exit(0);
29+
}
30+
}
31+
);
32+
33+
console.log('Publisher and Subscriber created.');
34+
35+
// Publish repeatedly until received
36+
const interval = setInterval(() => {
37+
publisher.publish('Hello from Electron');
38+
console.log('Published message...');
39+
}, 100);
40+
41+
// Set a timeout to fail the test
42+
setTimeout(() => {
43+
console.error('Test Failed: Timeout waiting for message.');
44+
clearInterval(interval);
45+
rclnodejs.shutdown();
46+
app.quit();
47+
process.exit(1);
48+
}, 10000);
49+
50+
rclnodejs.spin(node);
51+
})
52+
.catch((e) => {
53+
console.error('Initialization failed:', e);
54+
app.quit();
55+
process.exit(1);
56+
});
57+
});

0 commit comments

Comments
 (0)