@quangnv13/nonstop 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/ui.js +54 -36
  2. package/package.json +1 -1
package/dist/ui.js CHANGED
@@ -172,10 +172,15 @@ async function launchControlCenter() {
172
172
  let config = (0, config_js_1.loadConfigFromDisk)();
173
173
  const isTTY = process.stdin.isTTY;
174
174
  const wasRaw = process.stdin.isRaw;
175
- const rl = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
175
+ let rl;
176
176
  try {
177
177
  if ((0, config_js_1.getMissingConfigFields)(config).length > 0) {
178
- config = await runSetupWizard(config, rl);
178
+ const result = await runSetupWizard(config);
179
+ config = result.config;
180
+ rl = result.rl;
181
+ }
182
+ else {
183
+ rl = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
179
184
  }
180
185
  let lastSelection = 0;
181
186
  while (true) {
@@ -230,7 +235,12 @@ async function launchControlCenter() {
230
235
  }
231
236
  }
232
237
  finally {
233
- rl.close();
238
+ if (rl) {
239
+ try {
240
+ rl.close();
241
+ }
242
+ catch { /* ignore */ }
243
+ }
234
244
  process.stdout.write('\u001b[?25h');
235
245
  if (isTTY) {
236
246
  try {
@@ -242,8 +252,7 @@ async function launchControlCenter() {
242
252
  console.log(chalk_1.default.gray('Đã thoát nonstop client.'));
243
253
  }
244
254
  }
245
- async function runSetupWizard(currentConfig, rl) {
246
- rl.pause();
255
+ async function runSetupWizard(currentConfig) {
247
256
  const language = await runSelectionMenu(() => {
248
257
  console.log(titleBox('Thiết lập nonstop'));
249
258
  console.log(chalk_1.default.gray(' Chọn ngôn ngữ / Choose language:'));
@@ -251,39 +260,48 @@ async function runSetupWizard(currentConfig, rl) {
251
260
  { label: 'Tiếng Việt (vi)', value: 'vi' },
252
261
  { label: 'English (en)', value: 'en' }
253
262
  ], currentConfig.language === 'en' ? 1 : 0);
254
- rl.resume();
255
263
  const t = (0, i18n_js_1.createTranslator)(language);
256
- clearScreen();
257
- console.log(titleBox(t('wizard.title')));
258
- console.log('');
259
- const telegramBotToken = await askWithDefault(rl, t('wizard.token'), currentConfig.telegramBotToken);
260
- const adminUsername = await askWithDefault(rl, t('wizard.admin'), currentConfig.adminUsername);
261
- const clientName = await askWithDefault(rl, t('wizard.clientName'), currentConfig.clientName);
262
- rl.pause();
263
- const startupMode = await runSelectionMenu(() => {
264
+ const rl = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
265
+ try {
266
+ clearScreen();
264
267
  console.log(titleBox(t('wizard.title')));
265
- console.log(chalk_1.default.gray(` ${t('wizard.startupMode')}:`));
266
- }, [
267
- { label: `Tắt (disabled)`, value: 'disabled' },
268
- { label: `Chạy nền (background)`, value: 'background' },
269
- { label: `Mở giao diện (open-ui)`, value: 'open-ui' }
270
- ], 0);
271
- rl.resume();
272
- const nextConfig = {
273
- ...currentConfig,
274
- language,
275
- telegramBotToken,
276
- adminUsername,
277
- telegramUsername: adminUsername,
278
- clientName,
279
- startupMode
280
- };
281
- (0, config_js_1.saveConfigToDisk)(nextConfig);
282
- clearScreen();
283
- console.log(titleBox(t('wizard.title')));
284
- console.log(`\n${chalk_1.default.green(t('wizard.complete'))}`);
285
- await pause(rl);
286
- return nextConfig;
268
+ console.log('');
269
+ const telegramBotToken = await askWithDefault(rl, t('wizard.token'), currentConfig.telegramBotToken);
270
+ const adminUsername = await askWithDefault(rl, t('wizard.admin'), currentConfig.adminUsername);
271
+ const clientName = await askWithDefault(rl, t('wizard.clientName'), currentConfig.clientName);
272
+ rl.pause();
273
+ const startupMode = await runSelectionMenu(() => {
274
+ console.log(titleBox(t('wizard.title')));
275
+ console.log(chalk_1.default.gray(` ${t('wizard.startupMode')}:`));
276
+ }, [
277
+ { label: `Tắt (disabled)`, value: 'disabled' },
278
+ { label: `Chạy nền (background)`, value: 'background' },
279
+ { label: `Mở giao diện (open-ui)`, value: 'open-ui' }
280
+ ], 0);
281
+ rl.resume();
282
+ const nextConfig = {
283
+ ...currentConfig,
284
+ language,
285
+ telegramBotToken,
286
+ adminUsername,
287
+ telegramUsername: adminUsername,
288
+ clientName,
289
+ startupMode
290
+ };
291
+ (0, config_js_1.saveConfigToDisk)(nextConfig);
292
+ clearScreen();
293
+ console.log(titleBox(t('wizard.title')));
294
+ console.log(`\n${chalk_1.default.green(t('wizard.complete'))}`);
295
+ await pause(rl);
296
+ return { config: nextConfig, rl };
297
+ }
298
+ catch (error) {
299
+ try {
300
+ rl.close();
301
+ }
302
+ catch { /* ignore */ }
303
+ throw error;
304
+ }
287
305
  }
288
306
  async function handleToggleRuntime(config, rl) {
289
307
  const status = (0, runtime_manager_js_1.getRuntimeStatus)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quangnv13/nonstop",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "preferGlobal": true,
5
5
  "publishConfig": {
6
6
  "access": "public"