Skip to content

Commit 68bce30

Browse files
committed
Apply extra script for PIO Home on macOS
1 parent a1acff8 commit 68bce30

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/home.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,23 @@ export default class PIOHome {
140140
const iframeId =
141141
'pioHomeIFrame-' +
142142
crypto.createHash('sha1').update(crypto.randomBytes(512)).digest('hex');
143+
const iframeScript = `
144+
<script>
145+
for (const command of ['selectAll', 'copy', 'paste', 'cut', 'undo', 'redo']) {
146+
document.addEventListener(command, (e) => {
147+
document.getElementById('${iframeId}').contentWindow.postMessage({'command': 'execCommand', 'data': command}, '*');
148+
});
149+
}
150+
window.addEventListener('message', (e) => {
151+
if (e.data.command === 'kbd-event') {
152+
window.dispatchEvent(new KeyboardEvent('keydown', e.data.data));
153+
}
154+
});
155+
</script>
156+
`;
143157
return `<!DOCTYPE html>
144158
<html lang="en">
145-
<head>
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-
}
152-
window.addEventListener('message', (e) => {
153-
if (e.data.command === 'kbd-event' && ${IS_OSX}) {
154-
window.dispatchEvent(new KeyboardEvent('keydown', e.data.data));
155-
}
156-
});
157-
</script>
158-
</head>
159+
<head>${IS_OSX ? iframeScript : ''}</head>
159160
<body style="margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: ${
160161
theme === 'light' ? '#FFF' : '#1E1E1E'
161162
}">

0 commit comments

Comments
 (0)