|
9 | 9 | import * as pioNodeHelpers from 'platformio-node-helpers'; |
10 | 10 |
|
11 | 11 | import { IS_OSX } from './constants'; |
| 12 | +import crypto from 'crypto'; |
12 | 13 | import { extension } from './main'; |
13 | 14 | import { notifyError } from './utils'; |
14 | 15 | import path from 'path'; |
@@ -136,30 +137,33 @@ export default class PIOHome { |
136 | 137 | }, |
137 | 138 | }); |
138 | 139 | const theme = this.getTheme(); |
| 140 | + const iframeId = |
| 141 | + 'pioHomeIFrame-' + |
| 142 | + crypto.createHash('sha1').update(crypto.randomBytes(512)).digest('hex'); |
139 | 143 | return `<!DOCTYPE html> |
140 | 144 | <html lang="en"> |
141 | 145 | <head> |
142 | 146 | <script> |
| 147 | + for (const command of ['selectAll', 'copy', 'paste', 'cut', 'undo', 'redo']) { |
| 148 | + document.addEventListener(command, (e) => { |
| 149 | + document.getElementById('${iframeId}').contentWindow.postMessage({'command': 'execCommand', 'data': command}, '*'); |
| 150 | + }); |
| 151 | + } |
143 | 152 | window.addEventListener('message', (e) => { |
144 | | - switch (e.data.command) { |
145 | | - case 'kbd-event': { |
146 | | - if (${IS_OSX}) { |
147 | | - window.dispatchEvent(new KeyboardEvent('keydown', e.data.data)); |
148 | | - } |
149 | | - break; |
150 | | - } |
| 153 | + if (e.data.command === 'kbd-event' && ${IS_OSX}) { |
| 154 | + window.dispatchEvent(new KeyboardEvent('keydown', e.data.data)); |
151 | 155 | } |
152 | | - }, false); |
| 156 | + }); |
153 | 157 | </script> |
154 | 158 | </head> |
155 | 159 | <body style="margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: ${ |
156 | 160 | theme === 'light' ? '#FFF' : '#1E1E1E' |
157 | 161 | }"> |
158 | | - <iframe src="${pioNodeHelpers.home.getFrontendUrl({ |
159 | | - start: startUrl, |
160 | | - theme, |
161 | | - workspace: extension.getEnterpriseSetting('defaultPIOHomeWorkspace'), |
162 | | - })}" |
| 162 | + <iframe id="${iframeId}" src="${pioNodeHelpers.home.getFrontendUrl({ |
| 163 | + start: startUrl, |
| 164 | + theme, |
| 165 | + workspace: extension.getEnterpriseSetting('defaultPIOHomeWorkspace'), |
| 166 | + })}" |
163 | 167 | width="100%" |
164 | 168 | height="100%" |
165 | 169 | frameborder="0" |
|
0 commit comments