chore: 🤖 Add custom key handler for windows (#2001)
* chore: 🤖 Add custom key handler for windows
Add custom key handler only for Windows OS so we achieve Ctrl+C to copy
within the embedded terminal
* Await for clipboard promise to complete
This commit is contained in:
1 parent
4127f6abd7
commit
cb3a9e3bdc
2 files changed
+31
-5
No files matched your search
@@ -50,12 +50,29 @@ export default class SessionTerminalTabsComponent extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
const { isWindows } = await this.ipc.invoke('checkOS');
|
||||
const xterm = new Terminal(terminalOptions);
|
||||
this.terminal = xterm;
|
||||
const fitAddon = new FitAddon();
|
||||
const termContainer = document.getElementById(`terminal-container`);
|
||||
calculateTerminalContainerHeight(termContainer);
|
||||
|
||||
/**
|
||||
* Custom key event handler for windows to achieve Ctrl+C as on the other OS's
|
||||
*/
|
||||
if (isWindows) {
|
||||
xterm.attachCustomKeyEventHandler(async (arg) => {
|
||||
if (arg.ctrlKey && arg.code === 'KeyC' && arg.type === 'keydown') {
|
||||
const selection = xterm.getSelection();
|
||||
if (selection) {
|
||||
await navigator.clipboard.writeText(selection);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
xterm.loadAddon(fitAddon);
|
||||
xterm.loadAddon(new CanvasAddon());
|
||||
xterm.open(termContainer);
|
||||
@@ -80,7 +97,7 @@ export default class SessionTerminalTabsComponent extends Component {
|
||||
// Send an SSH command immediately
|
||||
window.terminal.send(
|
||||
`ssh ${proxy_address} -p ${proxy_port} -o NoHostAuthenticationForLocalhost=yes\r`,
|
||||
this.id
|
||||
this.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ handle('openExternal', async (href) => {
|
||||
} else {
|
||||
throw new Error(
|
||||
`URLs may only be opened over HTTPS in an external browser.
|
||||
The URL '${href}' could not be opened.`
|
||||
The URL '${href}' could not be opened.`,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -68,7 +68,7 @@ handle('cliExists', () => boundaryCli.exists());
|
||||
* Establishes a boundary session and returns session details.
|
||||
*/
|
||||
handle('connect', ({ target_id, token, host_id }) =>
|
||||
sessionManager.start(runtimeSettings.clusterUrl, target_id, token, host_id)
|
||||
sessionManager.start(runtimeSettings.clusterUrl, target_id, token, host_id),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ handle('stop', ({ session_id }) => sessionManager.stopById(session_id));
|
||||
* `DISABLE_WINDOW_CHROME=true`.
|
||||
*/
|
||||
handle('hasMacOSChrome', () =>
|
||||
process.env.DISABLE_WINDOW_CHROME ? false : isMac()
|
||||
process.env.DISABLE_WINDOW_CHROME ? false : isMac(),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ handle('hasMacOSChrome', () =>
|
||||
* `DISABLE_WINDOW_CHROME=true`.
|
||||
*/
|
||||
handle('showWindowActions', () =>
|
||||
process.env.DISABLE_WINDOW_CHROME ? false : !isMac()
|
||||
process.env.DISABLE_WINDOW_CHROME ? false : !isMac(),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -117,6 +117,15 @@ handle('closeWindow', () => app.quit());
|
||||
*/
|
||||
handle('checkCommand', async (command) => which(command, { nothrow: true }));
|
||||
|
||||
/**
|
||||
* Return an object containing helper fields for determining what OS we're running on
|
||||
*/
|
||||
handle('checkOS', () => ({
|
||||
isLinux: isLinux(),
|
||||
isMac: isMac(),
|
||||
isWindows: isWindows(),
|
||||
}));
|
||||
|
||||
/**
|
||||
* Handler to help create terminal windows. We don't use the helper `handle` method
|
||||
* as we need access to the event and don't need to be using `ipcMain.handle`.
|
||||
|
||||
Reference in new issue
Block a user