Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions src/main/engine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChildProcessWithoutNullStreams, spawn } from 'node:child_process';
import { ChildProcessWithoutNullStreams } from 'node:child_process';
import path from 'node:path';

import dotenv from 'dotenv';
Expand All @@ -13,7 +13,7 @@ import { IpcEvents } from '../ipc-events';
* enginePort 现在存的是完整的 url
*/
export class TachybaseEngine {
private engineStatus = 'initialization';
private engineStatus = 'ready';
private enginePort = '';
private child: ChildProcessWithoutNullStreams | null = null;

Expand All @@ -22,13 +22,15 @@ export class TachybaseEngine {
event.returnValue = this.engineStatus + '|' + this.enginePort;
});

ipcMainManager.handle(
IpcEvents.ENGINE_START,
(_: IpcMainEvent, env: string) => this.start.bind(this)(env),
);
// ipcMainManager.handle(
// IpcEvents.ENGINE_START,
// (_: IpcMainEvent, env: string) => this.start.bind(this)(env),
// );
ipcMainManager.handle(IpcEvents.ENGINE_STOP, (_: IpcMainEvent) =>
this.stop.bind(this)(),
);

this.start('');
}

async start(rawEnvString: string) {
Expand Down Expand Up @@ -59,7 +61,9 @@ export class TachybaseEngine {
'ENGINE_PATH, ENGINE_WORKING_DIR, and APP_PORT must be set',
);
}
remoteUrl = `http://localhost:${appPort}`;
if (!remoteUrl) {
remoteUrl = `http://localhost:${appPort}/signin`;
}

env.NODE_MODULES_PATH = path.join(workingDir, 'plugins/node_modules');

Expand All @@ -86,33 +90,33 @@ export class TachybaseEngine {
}
};

await checkRunning();

this.child = spawn(enginePath, ['start', '--quickstart'], {
cwd: workingDir,
env,
stdio: 'pipe',
});
this.child.stdout.on('data', (data) => {
ipcMainManager.send(IpcEvents.ENGINE_STDOUT, [data.toString()]);
});

this.child.stderr.on('data', (data) => {
ipcMainManager.send(IpcEvents.ENGINE_STDERR, [data.toString()]);
});

this.child.on('error', (error) => {
console.error(`[Engine]: Error starting engine: ${error.message}`);
});

this.child.on('exit', (code) => {
console.log(`[Engine]: engine exited with code ${code}`);

if (this.engineStatus !== 'stopped') {
this.engineStatus = 'stopped';
ipcMainManager.send(IpcEvents.ENGINE_STATUS_CHANGED, ['stopped']);
}
});
// await checkRunning();

// this.child = spawn(enginePath, ['start', '--quickstart'], {
// cwd: workingDir,
// env,
// stdio: 'pipe',
// });
// this.child.stdout.on('data', (data) => {
// ipcMainManager.send(IpcEvents.ENGINE_STDOUT, [data.toString()]);
// });

// this.child.stderr.on('data', (data) => {
// ipcMainManager.send(IpcEvents.ENGINE_STDERR, [data.toString()]);
// });

// this.child.on('error', (error) => {
// console.error(`[Engine]: Error starting engine: ${error.message}`);
// });

// this.child.on('exit', (code) => {
// console.log(`[Engine]: engine exited with code ${code}`);

// if (this.engineStatus !== 'stopped') {
// this.engineStatus = 'stopped';
// ipcMainManager.send(IpcEvents.ENGINE_STATUS_CHANGED, ['stopped']);
// }
// });
}

async stop() {
Expand Down
1 change: 1 addition & 0 deletions src/main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function getMainWindowOptions(): Electron.BrowserWindowConstructorOptions
? path.join(process.cwd(), './.webpack/renderer/main_window/preload.js')
: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
autoHideMenuBar: true, // 自动隐藏菜单栏,按Alt键显示
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/commands-runner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Runner = observer(
case 'initialization': {
props.text = 'Stop';
try {
window.ElectronFiddle.startEngine(engineEnv);
// window.ElectronFiddle.startEngine(engineEnv);
} catch (err) {
this.props.appState.pushError(err.message, err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const Output = observer(
<div
className="output"
ref={this.outputRef}
style={{ display: isConsoleShowing ? 'inline-block' : 'none' }}
style={{ display: 'none' }}
/>
);
}
Expand Down
Loading