@quangnv13/nonstop 1.0.2 → 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 +78 -68
  2. package/package.json +1 -1
package/dist/ui.js CHANGED
@@ -172,67 +172,75 @@ 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
+ let rl;
175
176
  try {
176
177
  if ((0, config_js_1.getMissingConfigFields)(config).length > 0) {
177
- config = await runSetupWizard(config);
178
+ const result = await runSetupWizard(config);
179
+ config = result.config;
180
+ rl = result.rl;
178
181
  }
179
- const rl = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
180
- try {
181
- let lastSelection = 0;
182
- while (true) {
183
- config = (0, config_js_1.loadConfigFromDisk)();
184
- const t = (0, i18n_js_1.createTranslator)(config.language);
185
- const isRunning = (0, runtime_manager_js_1.getRuntimeStatus)().running;
186
- const isVi = config.language === 'vi';
187
- const toggleLabel = isRunning
188
- ? (isVi ? 'Tắt runtime nền' : 'Dừng background runtime')
189
- : (isVi ? 'Bật runtime nền' : 'Chạy background runtime');
190
- const options = [
191
- { label: toggleLabel, value: 'toggle' },
192
- { label: t('menu.settings'), value: 'settings' },
193
- { label: t('menu.workspaces'), value: 'workspaces' },
194
- { label: t('menu.startup'), value: 'startup' },
195
- { label: t('menu.language'), value: 'language' },
196
- { label: t('menu.logs'), value: 'logs' },
197
- { label: t('menu.exit'), value: 'exit' }
198
- ];
199
- const choice = await runSelectionMenu(() => renderDashboardHeader(config, (0, runtime_manager_js_1.getRuntimeStatus)().snapshot), options, lastSelection);
200
- lastSelection = options.findIndex(opt => opt.value === choice);
201
- if (lastSelection < 0)
202
- lastSelection = 0;
203
- if (choice === 'exit')
204
- break;
205
- if (choice === 'toggle') {
206
- await handleToggleRuntime(config, rl);
207
- continue;
208
- }
209
- if (choice === 'settings') {
210
- config = await editConfig(config, rl);
211
- continue;
212
- }
213
- if (choice === 'workspaces') {
214
- await manageWorkspaces(rl, config.language);
215
- continue;
216
- }
217
- if (choice === 'startup') {
218
- config = await configureStartup(config, rl);
219
- continue;
220
- }
221
- if (choice === 'language') {
222
- config = await switchLanguage(config, rl);
223
- continue;
224
- }
225
- if (choice === 'logs') {
226
- await showRecentLogs(rl);
227
- continue;
228
- }
229
- }
182
+ else {
183
+ rl = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
230
184
  }
231
- finally {
232
- rl.close();
185
+ let lastSelection = 0;
186
+ while (true) {
187
+ config = (0, config_js_1.loadConfigFromDisk)();
188
+ const t = (0, i18n_js_1.createTranslator)(config.language);
189
+ const isRunning = (0, runtime_manager_js_1.getRuntimeStatus)().running;
190
+ const isVi = config.language === 'vi';
191
+ const toggleLabel = isRunning
192
+ ? (isVi ? 'Tắt runtime nền' : 'Dừng background runtime')
193
+ : (isVi ? 'Bật runtime nền' : 'Chạy background runtime');
194
+ const options = [
195
+ { label: toggleLabel, value: 'toggle' },
196
+ { label: t('menu.settings'), value: 'settings' },
197
+ { label: t('menu.workspaces'), value: 'workspaces' },
198
+ { label: t('menu.startup'), value: 'startup' },
199
+ { label: t('menu.language'), value: 'language' },
200
+ { label: t('menu.logs'), value: 'logs' },
201
+ { label: t('menu.exit'), value: 'exit' }
202
+ ];
203
+ rl.pause();
204
+ const choice = await runSelectionMenu(() => renderDashboardHeader(config, (0, runtime_manager_js_1.getRuntimeStatus)().snapshot), options, lastSelection);
205
+ rl.resume();
206
+ lastSelection = options.findIndex(opt => opt.value === choice);
207
+ if (lastSelection < 0)
208
+ lastSelection = 0;
209
+ if (choice === 'exit')
210
+ break;
211
+ if (choice === 'toggle') {
212
+ await handleToggleRuntime(config, rl);
213
+ continue;
214
+ }
215
+ if (choice === 'settings') {
216
+ config = await editConfig(config, rl);
217
+ continue;
218
+ }
219
+ if (choice === 'workspaces') {
220
+ await manageWorkspaces(rl, config.language);
221
+ continue;
222
+ }
223
+ if (choice === 'startup') {
224
+ config = await configureStartup(config, rl);
225
+ continue;
226
+ }
227
+ if (choice === 'language') {
228
+ config = await switchLanguage(config, rl);
229
+ continue;
230
+ }
231
+ if (choice === 'logs') {
232
+ await showRecentLogs(rl);
233
+ continue;
234
+ }
233
235
  }
234
236
  }
235
237
  finally {
238
+ if (rl) {
239
+ try {
240
+ rl.close();
241
+ }
242
+ catch { /* ignore */ }
243
+ }
236
244
  process.stdout.write('\u001b[?25h');
237
245
  if (isTTY) {
238
246
  try {
@@ -261,7 +269,7 @@ async function runSetupWizard(currentConfig) {
261
269
  const telegramBotToken = await askWithDefault(rl, t('wizard.token'), currentConfig.telegramBotToken);
262
270
  const adminUsername = await askWithDefault(rl, t('wizard.admin'), currentConfig.adminUsername);
263
271
  const clientName = await askWithDefault(rl, t('wizard.clientName'), currentConfig.clientName);
264
- rl.close();
272
+ rl.pause();
265
273
  const startupMode = await runSelectionMenu(() => {
266
274
  console.log(titleBox(t('wizard.title')));
267
275
  console.log(chalk_1.default.gray(` ${t('wizard.startupMode')}:`));
@@ -270,6 +278,7 @@ async function runSetupWizard(currentConfig) {
270
278
  { label: `Chạy nền (background)`, value: 'background' },
271
279
  { label: `Mở giao diện (open-ui)`, value: 'open-ui' }
272
280
  ], 0);
281
+ rl.resume();
273
282
  const nextConfig = {
274
283
  ...currentConfig,
275
284
  language,
@@ -280,23 +289,18 @@ async function runSetupWizard(currentConfig) {
280
289
  startupMode
281
290
  };
282
291
  (0, config_js_1.saveConfigToDisk)(nextConfig);
283
- const rl2 = (0, promises_1.createInterface)({ input: node_process_1.stdin, output: node_process_1.stdout });
284
- try {
285
- clearScreen();
286
- console.log(titleBox(t('wizard.title')));
287
- console.log(`\n${chalk_1.default.green(t('wizard.complete'))}`);
288
- await pause(rl2);
289
- }
290
- finally {
291
- rl2.close();
292
- }
293
- return 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 };
294
297
  }
295
- finally {
298
+ catch (error) {
296
299
  try {
297
300
  rl.close();
298
301
  }
299
- catch { /* already closed */ }
302
+ catch { /* ignore */ }
303
+ throw error;
300
304
  }
301
305
  }
302
306
  async function handleToggleRuntime(config, rl) {
@@ -358,10 +362,12 @@ async function manageWorkspaces(rl, language) {
358
362
  })),
359
363
  { label: isVi ? '← Quay lại menu chính' : '← Back', value: { type: 'back' } }
360
364
  ];
365
+ rl.pause();
361
366
  const selection = await runSelectionMenu(() => {
362
367
  console.log(titleBox(isVi ? 'Quản lý Workspace' : 'Manage Workspaces'));
363
368
  console.log(chalk_1.default.gray(` ${isVi ? 'Chọn workspace hoặc thêm mới:' : 'Select workspace or add new:'}`));
364
369
  }, options);
370
+ rl.resume();
365
371
  if (selection.type === 'back')
366
372
  return;
367
373
  if (selection.type === 'add') {
@@ -428,6 +434,7 @@ async function manageWorkspaces(rl, language) {
428
434
  }
429
435
  async function configureStartup(config, rl) {
430
436
  const isVi = config.language === 'vi';
437
+ rl.pause();
431
438
  const nextMode = await runSelectionMenu(() => {
432
439
  console.log(titleBox(isVi ? 'Cấu hình khởi động' : 'Configure startup'));
433
440
  console.log(chalk_1.default.gray(` ${isVi ? 'Chế độ hiện tại:' : 'Current mode:'} ${config.startupMode}`));
@@ -436,6 +443,7 @@ async function configureStartup(config, rl) {
436
443
  { label: isVi ? 'Chạy nền (background)' : 'Background', value: 'background' },
437
444
  { label: isVi ? 'Mở giao diện (open-ui)' : 'Open UI', value: 'open-ui' }
438
445
  ], ['disabled', 'background', 'open-ui'].indexOf(config.startupMode));
446
+ rl.resume();
439
447
  const entryScriptPath = path.join(process.cwd(), 'dist', 'index.js');
440
448
  const result = (0, startup_js_1.applyStartupMode)(nextMode, entryScriptPath, process.cwd());
441
449
  const nextConfig = { ...config, startupMode: nextMode };
@@ -447,6 +455,7 @@ async function configureStartup(config, rl) {
447
455
  return nextConfig;
448
456
  }
449
457
  async function switchLanguage(config, rl) {
458
+ rl.pause();
450
459
  const language = await runSelectionMenu(() => {
451
460
  console.log(titleBox('Đổi ngôn ngữ / Switch language'));
452
461
  console.log(chalk_1.default.gray(` Hiện tại: ${config.language}`));
@@ -454,6 +463,7 @@ async function switchLanguage(config, rl) {
454
463
  { label: 'Tiếng Việt (vi)', value: 'vi' },
455
464
  { label: 'English (en)', value: 'en' }
456
465
  ], config.language === 'en' ? 1 : 0);
466
+ rl.resume();
457
467
  const nextConfig = { ...config, language };
458
468
  (0, config_js_1.saveConfigToDisk)(nextConfig);
459
469
  return nextConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quangnv13/nonstop",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "preferGlobal": true,
5
5
  "publishConfig": {
6
6
  "access": "public"