onairos 0.1.400 → 1.0.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/dist/iframe/dataRequestHandler.js +86 -42
- package/dist/onairos.bundle.js +1 -1
- package/dist/onairos.bundle.js.map +1 -1
- package/dist/onairos.native.js +1 -1
- package/dist/onairosButton.js +113 -105
- package/package.json +100 -100
- package/src/iframe/dataRequestHandler.js +98 -48
- package/src/onairos.native.jsx +15 -15
- package/src/onairosButton.jsx +116 -112
- package/webpack.native.config.js +100 -100
|
@@ -13,56 +13,66 @@ exports.sendDataToIframe = sendDataToIframe;
|
|
|
13
13
|
* in the top right corner of the screen.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Gets the URL for the iframe HTML file
|
|
18
|
+
* Works in both extension and web contexts
|
|
19
|
+
*/
|
|
20
|
+
function getIframeUrl() {
|
|
21
|
+
if (typeof chrome !== 'undefined' && chrome.runtime) {
|
|
22
|
+
return chrome.runtime.getURL('data_request_iframe.html');
|
|
23
|
+
}
|
|
24
|
+
// For web context, use relative path
|
|
25
|
+
return '/data_request_iframe.html';
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
/**
|
|
17
29
|
* Opens a data request iframe in a new window positioned in the top right corner of the screen
|
|
18
|
-
*
|
|
30
|
+
* @returns {Window|null} The opened window or null if failed
|
|
19
31
|
*/
|
|
20
32
|
function openDataRequestIframe() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
try {
|
|
34
|
+
// Create iframe element
|
|
35
|
+
const iframe = document.createElement('iframe');
|
|
36
|
+
iframe.setAttribute('src', getIframeUrl());
|
|
37
|
+
iframe.setAttribute('title', 'Onairos Terminal');
|
|
38
|
+
iframe.classList.add('iframe-class');
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
// Style the iframe
|
|
41
|
+
iframe.style.width = '100%';
|
|
42
|
+
iframe.style.height = '600px';
|
|
43
|
+
iframe.style.border = 'none';
|
|
44
|
+
iframe.style.backgroundColor = 'transparent';
|
|
31
45
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
// Calculate position (top right corner)
|
|
47
|
+
const width = 400;
|
|
48
|
+
const height = 600;
|
|
49
|
+
const top = 10;
|
|
50
|
+
const left = window.innerWidth - width - 10;
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Open a new window and append the iframe to it
|
|
45
|
-
const newWindow = window.open(chrome.runtime.getURL('data_request_iframe.html'), 'Onairos Terminal', `width=${width},height=${height},top=${top},left=${left},resizable=no`);
|
|
52
|
+
// Open a new window and append the iframe to it
|
|
53
|
+
const newWindow = window.open(getIframeUrl(), 'Onairos Terminal', `width=${width},height=${height},top=${top},left=${left},resizable=no`);
|
|
54
|
+
if (!newWindow) {
|
|
55
|
+
throw new Error('Failed to open window - popup blocked');
|
|
56
|
+
}
|
|
46
57
|
|
|
47
|
-
// If window opened successfully, append the iframe
|
|
48
|
-
if (newWindow) {
|
|
49
58
|
// Set some basic styles for the popup window
|
|
50
59
|
newWindow.document.body.style.margin = '0';
|
|
51
60
|
newWindow.document.body.style.padding = '0';
|
|
52
61
|
newWindow.document.body.style.overflow = 'hidden';
|
|
53
62
|
|
|
54
|
-
// Add event listener for window close
|
|
63
|
+
// Add event listener for window close
|
|
55
64
|
newWindow.addEventListener('beforeunload', () => {
|
|
56
65
|
window.postMessage({
|
|
57
66
|
action: 'terminalClosed'
|
|
58
67
|
}, '*');
|
|
59
68
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
return newWindow;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('Error opening iframe:', error);
|
|
72
|
+
// Show user-friendly error message
|
|
73
|
+
alert('Unable to open Onairos Terminal. Please ensure popups are allowed for this site.');
|
|
74
|
+
return null;
|
|
64
75
|
}
|
|
65
|
-
return newWindow;
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
/**
|
|
@@ -71,33 +81,67 @@ function openDataRequestIframe() {
|
|
|
71
81
|
*/
|
|
72
82
|
function closeDataRequestIframe(windowRef) {
|
|
73
83
|
if (windowRef && !windowRef.closed) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
try {
|
|
85
|
+
windowRef.close();
|
|
86
|
+
window.postMessage({
|
|
87
|
+
action: 'terminalClosed'
|
|
88
|
+
}, '*');
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error('Error closing iframe:', error);
|
|
91
|
+
}
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
94
|
|
|
81
95
|
/**
|
|
82
|
-
* Send data to the iframe window
|
|
96
|
+
* Send data to the iframe window with timeout
|
|
83
97
|
* @param {Window} windowRef - Reference to the window object returned by openDataRequestIframe
|
|
84
98
|
* @param {Object} data - Data to send to the iframe
|
|
99
|
+
* @returns {Promise} Promise that resolves when data is sent or rejects on timeout
|
|
85
100
|
*/
|
|
86
101
|
function sendDataToIframe(windowRef, data) {
|
|
87
|
-
|
|
88
|
-
windowRef.
|
|
89
|
-
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
if (!windowRef || windowRef.closed) {
|
|
104
|
+
reject(new Error('Iframe window is not available'));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
windowRef.postMessage(data, '*');
|
|
109
|
+
|
|
110
|
+
// Set timeout for response
|
|
111
|
+
const timeout = setTimeout(() => {
|
|
112
|
+
reject(new Error('Timeout waiting for iframe response'));
|
|
113
|
+
}, 5000);
|
|
114
|
+
|
|
115
|
+
// Listen for acknowledgment
|
|
116
|
+
const messageHandler = event => {
|
|
117
|
+
if (event.data && event.data.action === 'dataReceived') {
|
|
118
|
+
clearTimeout(timeout);
|
|
119
|
+
window.removeEventListener('message', messageHandler);
|
|
120
|
+
resolve();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
window.addEventListener('message', messageHandler);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
reject(error);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
90
128
|
}
|
|
91
129
|
|
|
92
130
|
/**
|
|
93
131
|
* Set up a listener for messages from the iframe
|
|
94
132
|
* @param {Function} callback - Function to handle messages from the iframe
|
|
133
|
+
* @returns {Function} Cleanup function to remove the listener
|
|
95
134
|
*/
|
|
96
135
|
function listenForIframeMessages(callback) {
|
|
97
|
-
|
|
98
|
-
// Make sure the message is from our iframe
|
|
136
|
+
const messageHandler = event => {
|
|
99
137
|
if (event.data && event.data.source === 'onairosIframe') {
|
|
100
138
|
callback(event.data);
|
|
101
139
|
}
|
|
102
|
-
}
|
|
140
|
+
};
|
|
141
|
+
window.addEventListener('message', messageHandler);
|
|
142
|
+
|
|
143
|
+
// Return cleanup function
|
|
144
|
+
return () => {
|
|
145
|
+
window.removeEventListener('message', messageHandler);
|
|
146
|
+
};
|
|
103
147
|
}
|