mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
style: 简化loader 避免全局error
This commit is contained in:
@@ -1,17 +1,10 @@
|
|||||||
import { require_dlopen } from '.';
|
import { require_dlopen } from '.';
|
||||||
|
export function pty_loader() {
|
||||||
let pty: any;
|
let pty: any;
|
||||||
|
|
||||||
try {
|
|
||||||
pty = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node');
|
|
||||||
} catch (outerError) {
|
|
||||||
try {
|
try {
|
||||||
pty = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node');
|
pty = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node');
|
||||||
} catch (innerError) {
|
} catch (outerError) {
|
||||||
console.error('innerError', innerError);
|
pty = undefined;
|
||||||
// Re-throw the exception from the Release require if the Debug require fails as well
|
|
||||||
throw outerError;
|
|
||||||
}
|
}
|
||||||
}
|
return pty;
|
||||||
|
};
|
||||||
export default pty;
|
|
||||||
|
@@ -11,8 +11,9 @@ import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from '@homebridge/node-pty-prebu
|
|||||||
import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from '@homebridge/node-pty-prebuilt-multiarch/src/interfaces';
|
import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from '@homebridge/node-pty-prebuilt-multiarch/src/interfaces';
|
||||||
import { ArgvOrCommandLine } from '@homebridge/node-pty-prebuilt-multiarch/src/types';
|
import { ArgvOrCommandLine } from '@homebridge/node-pty-prebuilt-multiarch/src/types';
|
||||||
import { assign } from '@homebridge/node-pty-prebuilt-multiarch/src/utils';
|
import { assign } from '@homebridge/node-pty-prebuilt-multiarch/src/utils';
|
||||||
|
import { pty_loader } from './prebuild-loader';
|
||||||
|
export const pty = pty_loader();
|
||||||
|
|
||||||
import pty from './prebuild-loader';
|
|
||||||
let helperPath: string;
|
let helperPath: string;
|
||||||
helperPath = '../build/Release/spawn-helper';
|
helperPath = '../build/Release/spawn-helper';
|
||||||
|
|
||||||
@@ -254,7 +255,7 @@ export class UnixTerminal extends Terminal {
|
|||||||
public get process(): string {
|
public get process(): string {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
const title = pty.process(this._fd);
|
const title = pty.process(this._fd);
|
||||||
return (title !== 'kernel_task' ) ? title : this._file;
|
return (title !== 'kernel_task') ? title : this._file;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pty.process(this._fd, this._pty) || this._file;
|
return pty.process(this._fd, this._pty) || this._file;
|
||||||
|
@@ -63,31 +63,11 @@ export class WindowsPtyAgent {
|
|||||||
}
|
}
|
||||||
if (this._useConpty) {
|
if (this._useConpty) {
|
||||||
if (!conptyNative) {
|
if (!conptyNative) {
|
||||||
try {
|
|
||||||
conptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/conpty.node');
|
conptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/conpty.node');
|
||||||
} catch (outerError) {
|
|
||||||
try {
|
|
||||||
conptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/conpty.node');
|
|
||||||
} catch (innerError) {
|
|
||||||
console.error('innerError', innerError);
|
|
||||||
// Re-throw the exception from the Release require if the Debug require fails as well
|
|
||||||
throw outerError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!winptyNative) {
|
if (!winptyNative) {
|
||||||
try {
|
|
||||||
winptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node');
|
winptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node');
|
||||||
} catch (outerError) {
|
|
||||||
try {
|
|
||||||
winptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node');
|
|
||||||
} catch (innerError) {
|
|
||||||
console.error('innerError', innerError);
|
|
||||||
// Re-throw the exception from the Release require if the Debug require fails as well
|
|
||||||
throw outerError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._ptyNative = this._useConpty ? conptyNative : winptyNative;
|
this._ptyNative = this._useConpty ? conptyNative : winptyNative;
|
||||||
|
Reference in New Issue
Block a user