projax 0.1.29 → 1.0.1

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.
@@ -308,3 +308,240 @@ electron_1.ipcMain.handle('get-project-ports', async (_, projectId) => {
308
308
  const db = getDatabaseManager();
309
309
  return db.getProjectPorts(projectId);
310
310
  });
311
+ // Get running processes
312
+ electron_1.ipcMain.handle('get-running-processes', async () => {
313
+ // Try bundled path first (when bundled in CLI: dist/electron/main.js -> dist/script-runner.js)
314
+ // Then try local dev path (packages/electron/dist/main.js -> packages/cli/dist/script-runner.js)
315
+ const bundledScriptRunnerPath = path.join(__dirname, '..', 'script-runner.js');
316
+ const localScriptRunnerPath = path.join(__dirname, '..', '..', '..', 'cli', 'dist', 'script-runner.js');
317
+ let scriptRunnerPath;
318
+ if (fs.existsSync(bundledScriptRunnerPath)) {
319
+ scriptRunnerPath = bundledScriptRunnerPath;
320
+ }
321
+ else {
322
+ scriptRunnerPath = localScriptRunnerPath;
323
+ }
324
+ const { getRunningProcesses } = await Promise.resolve(`${scriptRunnerPath}`).then(s => __importStar(require(s)));
325
+ return getRunningProcesses();
326
+ });
327
+ // Stop script by PID
328
+ electron_1.ipcMain.handle('stop-script', async (_, pid) => {
329
+ // Try bundled path first (when bundled in CLI: dist/electron/main.js -> dist/script-runner.js)
330
+ // Then try local dev path (packages/electron/dist/main.js -> packages/cli/dist/script-runner.js)
331
+ const bundledScriptRunnerPath = path.join(__dirname, '..', 'script-runner.js');
332
+ const localScriptRunnerPath = path.join(__dirname, '..', '..', '..', 'cli', 'dist', 'script-runner.js');
333
+ let scriptRunnerPath;
334
+ if (fs.existsSync(bundledScriptRunnerPath)) {
335
+ scriptRunnerPath = bundledScriptRunnerPath;
336
+ }
337
+ else {
338
+ scriptRunnerPath = localScriptRunnerPath;
339
+ }
340
+ const { stopScript } = await Promise.resolve(`${scriptRunnerPath}`).then(s => __importStar(require(s)));
341
+ return await stopScript(pid);
342
+ });
343
+ // Stop all processes for a project
344
+ electron_1.ipcMain.handle('stop-project', async (_, projectPath) => {
345
+ // Try bundled path first (when bundled in CLI: dist/electron/main.js -> dist/script-runner.js)
346
+ // Then try local dev path (packages/electron/dist/main.js -> packages/cli/dist/script-runner.js)
347
+ const bundledScriptRunnerPath = path.join(__dirname, '..', 'script-runner.js');
348
+ const localScriptRunnerPath = path.join(__dirname, '..', '..', '..', 'cli', 'dist', 'script-runner.js');
349
+ let scriptRunnerPath;
350
+ if (fs.existsSync(bundledScriptRunnerPath)) {
351
+ scriptRunnerPath = bundledScriptRunnerPath;
352
+ }
353
+ else {
354
+ scriptRunnerPath = localScriptRunnerPath;
355
+ }
356
+ const { stopProjectProcesses } = await Promise.resolve(`${scriptRunnerPath}`).then(s => __importStar(require(s)));
357
+ return await stopProjectProcesses(projectPath);
358
+ });
359
+ // Open URL in browser
360
+ electron_1.ipcMain.handle('open-url', async (_, url) => {
361
+ // Try bundled path first (when bundled in CLI: dist/electron/main.js -> dist/core)
362
+ // Then try local dev path (packages/electron/dist/main.js -> packages/core/dist)
363
+ const bundledCorePath = path.join(__dirname, '..', 'core');
364
+ const localCorePath = path.join(__dirname, '..', '..', '..', 'core', 'dist');
365
+ let corePath;
366
+ if (fs.existsSync(bundledCorePath)) {
367
+ corePath = bundledCorePath;
368
+ }
369
+ else {
370
+ corePath = localCorePath;
371
+ }
372
+ const { getBrowserSettings } = await Promise.resolve(`${corePath}`).then(s => __importStar(require(s)));
373
+ const browserSettings = getBrowserSettings();
374
+ let command;
375
+ let args = [url];
376
+ if (browserSettings.type === 'custom' && browserSettings.customPath) {
377
+ command = browserSettings.customPath;
378
+ }
379
+ else {
380
+ // Platform-specific browser commands
381
+ if (process.platform === 'darwin') {
382
+ // macOS
383
+ switch (browserSettings.type) {
384
+ case 'chrome':
385
+ command = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
386
+ break;
387
+ case 'firefox':
388
+ command = '/Applications/Firefox.app/Contents/MacOS/firefox';
389
+ break;
390
+ case 'safari':
391
+ command = 'open';
392
+ args = ['-a', 'Safari', url];
393
+ break;
394
+ case 'edge':
395
+ command = '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge';
396
+ break;
397
+ default:
398
+ command = 'open';
399
+ args = [url];
400
+ }
401
+ }
402
+ else if (process.platform === 'win32') {
403
+ // Windows
404
+ switch (browserSettings.type) {
405
+ case 'chrome':
406
+ command = 'chrome';
407
+ break;
408
+ case 'firefox':
409
+ command = 'firefox';
410
+ break;
411
+ case 'edge':
412
+ command = 'msedge';
413
+ break;
414
+ case 'safari':
415
+ command = 'safari';
416
+ break;
417
+ default:
418
+ command = 'start';
419
+ args = [url];
420
+ }
421
+ }
422
+ else {
423
+ // Linux
424
+ switch (browserSettings.type) {
425
+ case 'chrome':
426
+ command = 'google-chrome';
427
+ break;
428
+ case 'firefox':
429
+ command = 'firefox';
430
+ break;
431
+ case 'edge':
432
+ command = 'microsoft-edge';
433
+ break;
434
+ case 'safari':
435
+ command = 'safari';
436
+ break;
437
+ default:
438
+ command = 'xdg-open';
439
+ args = [url];
440
+ }
441
+ }
442
+ }
443
+ const { spawn } = require('child_process');
444
+ spawn(command, args, {
445
+ detached: true,
446
+ stdio: 'ignore',
447
+ }).unref();
448
+ });
449
+ // Open project in editor
450
+ electron_1.ipcMain.handle('open-in-editor', async (_, projectPath) => {
451
+ // Try bundled path first (when bundled in CLI: dist/electron/main.js -> dist/core)
452
+ // Then try local dev path (packages/electron/dist/main.js -> packages/core/dist)
453
+ const bundledCorePath = path.join(__dirname, '..', 'core');
454
+ const localCorePath = path.join(__dirname, '..', '..', '..', 'core', 'dist');
455
+ let corePath;
456
+ if (fs.existsSync(bundledCorePath)) {
457
+ corePath = bundledCorePath;
458
+ }
459
+ else {
460
+ corePath = localCorePath;
461
+ }
462
+ const { getEditorSettings } = await Promise.resolve(`${corePath}`).then(s => __importStar(require(s)));
463
+ const editorSettings = getEditorSettings();
464
+ let command;
465
+ let args = [projectPath];
466
+ if (editorSettings.type === 'custom' && editorSettings.customPath) {
467
+ command = editorSettings.customPath;
468
+ }
469
+ else {
470
+ switch (editorSettings.type) {
471
+ case 'vscode':
472
+ command = 'code';
473
+ break;
474
+ case 'cursor':
475
+ command = 'cursor';
476
+ break;
477
+ case 'windsurf':
478
+ command = 'windsurf';
479
+ break;
480
+ case 'zed':
481
+ command = 'zed';
482
+ break;
483
+ default:
484
+ command = 'code'; // Default to VS Code
485
+ }
486
+ }
487
+ const { spawn } = require('child_process');
488
+ spawn(command, args, {
489
+ detached: true,
490
+ stdio: 'ignore',
491
+ }).unref();
492
+ });
493
+ // Get settings
494
+ electron_1.ipcMain.handle('get-settings', async () => {
495
+ try {
496
+ // Use the same import pattern as other handlers
497
+ let settingsModule;
498
+ try {
499
+ // Try relative import first (when bundled in CLI: dist/electron/main.js -> dist/core)
500
+ settingsModule = require('../core');
501
+ }
502
+ catch {
503
+ try {
504
+ // Try alternative path (local development: packages/electron/dist/main.js -> packages/cli/dist/core)
505
+ settingsModule = require('../../cli/dist/core');
506
+ }
507
+ catch {
508
+ // Fallback to package import
509
+ settingsModule = require('@projax/core');
510
+ }
511
+ }
512
+ const { getAppSettings } = settingsModule;
513
+ return getAppSettings();
514
+ }
515
+ catch (error) {
516
+ console.error('Error getting settings:', error);
517
+ throw error;
518
+ }
519
+ });
520
+ // Save settings
521
+ electron_1.ipcMain.handle('save-settings', async (_, settings) => {
522
+ try {
523
+ // Use the same import pattern as other handlers
524
+ let settingsModule;
525
+ try {
526
+ // Try relative import first (when bundled in CLI: dist/electron/main.js -> dist/core)
527
+ settingsModule = require('../core');
528
+ }
529
+ catch {
530
+ try {
531
+ // Try alternative path (local development: packages/electron/dist/main.js -> packages/cli/dist/core)
532
+ settingsModule = require('../../cli/dist/core');
533
+ }
534
+ catch {
535
+ // Fallback to package import
536
+ settingsModule = require('@projax/core');
537
+ }
538
+ }
539
+ const { setAppSettings } = settingsModule;
540
+ setAppSettings(settings);
541
+ console.log('Settings saved successfully');
542
+ }
543
+ catch (error) {
544
+ console.error('Error saving settings:', error);
545
+ throw error;
546
+ }
547
+ });
@@ -46,4 +46,38 @@ export interface ElectronAPI {
46
46
  scanProjectPorts: (projectId: number) => Promise<ProjectPort[]>;
47
47
  scanAllPorts: () => Promise<Record<number, ProjectPort[]>>;
48
48
  getProjectPorts: (projectId: number) => Promise<ProjectPort[]>;
49
+ getRunningProcesses: () => Promise<Array<{
50
+ pid: number;
51
+ projectPath: string;
52
+ projectName: string;
53
+ scriptName: string;
54
+ command: string;
55
+ startedAt: number;
56
+ logFile: string;
57
+ detectedUrls?: string[];
58
+ }>>;
59
+ stopScript: (pid: number) => Promise<boolean>;
60
+ stopProject: (projectPath: string) => Promise<number>;
61
+ openUrl: (url: string) => Promise<void>;
62
+ openInEditor: (projectPath: string) => Promise<void>;
63
+ getSettings: () => Promise<{
64
+ editor: {
65
+ type: string;
66
+ customPath?: string;
67
+ };
68
+ browser: {
69
+ type: string;
70
+ customPath?: string;
71
+ };
72
+ }>;
73
+ saveSettings: (settings: {
74
+ editor: {
75
+ type: string;
76
+ customPath?: string;
77
+ };
78
+ browser: {
79
+ type: string;
80
+ customPath?: string;
81
+ };
82
+ }) => Promise<void>;
49
83
  }
@@ -18,4 +18,11 @@ electron_1.contextBridge.exposeInMainWorld('electronAPI', {
18
18
  scanProjectPorts: (projectId) => electron_1.ipcRenderer.invoke('scan-project-ports', projectId),
19
19
  scanAllPorts: () => electron_1.ipcRenderer.invoke('scan-all-ports'),
20
20
  getProjectPorts: (projectId) => electron_1.ipcRenderer.invoke('get-project-ports', projectId),
21
+ getRunningProcesses: () => electron_1.ipcRenderer.invoke('get-running-processes'),
22
+ stopScript: (pid) => electron_1.ipcRenderer.invoke('stop-script', pid),
23
+ stopProject: (projectPath) => electron_1.ipcRenderer.invoke('stop-project', projectPath),
24
+ openUrl: (url) => electron_1.ipcRenderer.invoke('open-url', url),
25
+ openInEditor: (projectPath) => electron_1.ipcRenderer.invoke('open-in-editor', projectPath),
26
+ getSettings: () => electron_1.ipcRenderer.invoke('get-settings'),
27
+ saveSettings: (settings) => electron_1.ipcRenderer.invoke('save-settings', settings),
21
28
  });