diff --git a/src/main/engine.ts b/src/main/engine.ts index 883edf80..c85ae380 100644 --- a/src/main/engine.ts +++ b/src/main/engine.ts @@ -13,7 +13,7 @@ import { IpcEvents } from '../ipc-events'; * enginePort 现在存的是完整的 url */ export class TachybaseEngine { - private engineStatus = 'stopped'; + private engineStatus = 'initialization'; private enginePort = ''; private child: ChildProcessWithoutNullStreams | null = null; diff --git a/src/renderer/components/commands-runner.tsx b/src/renderer/components/commands-runner.tsx index c2803276..5ad25364 100644 --- a/src/renderer/components/commands-runner.tsx +++ b/src/renderer/components/commands-runner.tsx @@ -16,10 +16,19 @@ export const Runner = observer( class Runner extends React.Component { public render() { const { engineStatus, engineEnv } = this.props.appState; - const props: ButtonProps = { disabled: false }; switch (engineStatus) { + case 'initialization': { + props.text = 'Stop'; + try { + window.ElectronFiddle.startEngine(engineEnv); + } catch (err) { + this.props.appState.pushError(err.message, err); + } + props.icon = 'stop'; + break; + } case 'stopped': { props.text = 'Run'; props.onClick = async () => { diff --git a/src/renderer/components/commands.tsx b/src/renderer/components/commands.tsx index 48678a5c..20836d67 100644 --- a/src/renderer/components/commands.tsx +++ b/src/renderer/components/commands.tsx @@ -10,6 +10,7 @@ import { AppState } from '../state'; interface CommandsProps { appState: AppState; + isTabbingHidden?: boolean; } /** @@ -20,6 +21,9 @@ export const Commands = observer( class Commands extends React.Component { constructor(props: CommandsProps) { super(props); + this.state = { + isTabbingHidden: true, + }; } private handleDoubleClick = (e: React.MouseEvent) => { @@ -29,53 +33,76 @@ export const Commands = observer( } }; + componentDidMount() { + document.addEventListener('keydown', this.handleKeyDown); + } + + componentWillUnmount() { + document.removeEventListener('keydown', this.handleKeyDown); + } + + private handleKeyDown = (e: KeyboardEvent) => { + const isInputFocused = ['INPUT', 'TEXTAREA'].includes( + (document.activeElement?.tagName || '').toUpperCase(), + ); + + if (!isInputFocused && e.shiftKey && e.key.toLowerCase() === 'k') { + e.preventDefault(); + this.setState((prevState: CommandsProps) => ({ + isTabbingHidden: !prevState.isTabbingHidden, + })); + } + }; + public render() { const { appState } = this.props; const { isBisectCommandShowing, title, isSettingsShowing } = appState; - + const { isTabbingHidden } = this.state as CommandsProps; return ( -
-
- -
+ {window.ElectronFiddle.platform === 'darwin' ? ( +
{title}
+ ) : undefined}
- {window.ElectronFiddle.platform === 'darwin' ? ( -
{title}
- ) : undefined} - + ) ); } }, diff --git a/src/renderer/state.ts b/src/renderer/state.ts index 4cb3dfa1..04e18d8a 100644 --- a/src/renderer/state.ts +++ b/src/renderer/state.ts @@ -174,7 +174,12 @@ export class AppState { public isDeletingAll = false; /// -- Engine -- - public engineStatus: 'stopped' | 'ready' | 'starting' | 'remote' = 'stopped'; + public engineStatus: + | 'stopped' + | 'initialization' + | 'ready' + | 'starting' + | 'remote' = 'stopped'; public enginePort = ''; public engineEnv = (localStorage.getItem(GlobalSetting.engineEnv) as string) ??