From f9aef434cb41b89eddc7b7ec0f1c0a2dbaffcf6d Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 22 Feb 2021 00:41:00 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BF=AE=E5=A4=8Dhydrooj=20addon?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E5=AE=8C=E6=88=90=E5=90=8E=E4=B8=8D=E4=BC=9A?= =?UTF-8?q?=E8=87=AA=E8=A1=8C=E9=80=80=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrooj/bin/hydrooj.js | 3 ++- packages/hydrooj/package.json | 8 +++++--- packages/hydrooj/src/loader.ts | 9 +++++++++ packages/hydrooj/src/ui.ts | 12 ++++++++---- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/hydrooj/bin/hydrooj.js b/packages/hydrooj/bin/hydrooj.js index 696233a2b..eb417e91e 100755 --- a/packages/hydrooj/bin/hydrooj.js +++ b/packages/hydrooj/bin/hydrooj.js @@ -5,9 +5,9 @@ const path = require('path'); const cluster = require('cluster'); const fs = require('fs-extra'); const { argv } = require('yargs'); -const hydro = require('../dist/loader'); if (!cluster.isMaster) { + const hydro = require('../dist/loader'); // Forked by hydro hydro.load().catch((e) => { console.error(e); @@ -46,6 +46,7 @@ if (!cluster.isMaster) { fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2)); } } else { + const hydro = require('../dist/loader'); addons = Array.from(new Set(addons)); for (const addon of addons) hydro.addon(addon); (argv._[0] === 'cli' ? hydro.loadCli : hydro.load)().catch((e) => { diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 9c28c8fcb..fca6c6846 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.17.16", + "version": "2.17.17", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", @@ -8,7 +8,7 @@ "author": "undefined ", "license": "AGPL-3.0-only", "engines": { - "node": ">=14" + "node": ">=13" }, "dependencies": { "adm-zip": "^0.5.2", @@ -34,6 +34,7 @@ "superagent": "^6.1.0", "systeminformation": "^5.3.3", "terminal-kit": "^1.47.0", + "wtfnode": "^0.8.4", "yargs": "^16.2.0" }, "devDependencies": { @@ -52,6 +53,7 @@ "@types/sockjs": "^0.3.32", "@types/superagent": "^4.1.8", "@types/terminal-kit": "^1.28.2", + "@types/wtfnode": "^0.7.0", "@types/yargs": "^16.0.0", "formidable": "^1.2.2" }, @@ -59,4 +61,4 @@ "build": "tsc", "build:watch": "tsc --watch" } -} \ No newline at end of file +} diff --git a/packages/hydrooj/src/loader.ts b/packages/hydrooj/src/loader.ts index be9942d87..f4c19e5af 100644 --- a/packages/hydrooj/src/loader.ts +++ b/packages/hydrooj/src/loader.ts @@ -9,6 +9,7 @@ import path from 'path'; import cluster from 'cluster'; import fs from 'fs-extra'; import { argv } from 'yargs'; +import wtfnode from 'wtfnode'; import './utils'; export * from './interface'; @@ -47,6 +48,14 @@ import * as bus from './service/bus'; const logger = new Logger('loader'); logger.debug('%o', argv); +bus.on('app/exit', () => { + if (argv.debug) { + wtfnode.setLogger('info', logger.info.bind(logger)); + wtfnode.setLogger('warn', logger.warn.bind(logger)); + wtfnode.setLogger('error', logger.error.bind(logger)); + wtfnode.dump(); + } +}); async function fork(args: string[] = []) { const _args = process.argv.slice(2); diff --git a/packages/hydrooj/src/ui.ts b/packages/hydrooj/src/ui.ts index c1fc8189d..356393167 100644 --- a/packages/hydrooj/src/ui.ts +++ b/packages/hydrooj/src/ui.ts @@ -6,8 +6,11 @@ import { } from 'terminal-kit'; import { ProgressBarOptions } from 'terminal-kit/Terminal'; import { argv } from 'yargs'; +import { Logger } from './logger'; import * as bus from './service/bus'; +const logger = new Logger('ui'); + declare module 'terminal-kit/Terminal' { interface ProgressBarOptions { y?: number; @@ -46,12 +49,11 @@ export namespace Progress { async function terminate() { let hasError = false; try { - await require('./service/bus').parallel('app/exit'); + await bus.parallel('app/exit'); } catch (e) { hasError = true; } if (useTerminal) { - terminal.hideCursor(false); terminal.styleReset(); terminal.resetScrollingRegion(); terminal.moveTo(terminal.width, terminal.height); @@ -64,7 +66,6 @@ process.on('SIGINT', terminate); if (useTerminal) { terminal.clear(); terminal.grabInput(); - terminal.hideCursor(); // Clipboard doesn't work well over ssh env, it throws an error. terminal.getClipboard = () => { }; terminal.setClipboard = () => { }; @@ -92,7 +93,7 @@ if (useTerminal) { }); const history = ['']; let current = 0; - ShellInput.on('submit', async (input) => { + ShellInput.on('submit', async (input: string) => { history.push(input); current = history.length; ShellInput.input.setContent(' '.repeat(terminal.width), false, false); @@ -118,6 +119,9 @@ if (useTerminal) { terminal.on('key', (key) => { if (key === 'CTRL_C') terminate(); }); + if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) { + logger.warn('Running over ssh detected. Add a --legacy when starting if GUI mode doesn\'t work properly.'); + } } else if (cluster.isMaster) { console.log('Not running in a terminal environment. Interactive mode disabled.'); bus.on('message/log', (message) => {