clocktopus 1.6.4 → 1.6.6

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.
@@ -11,7 +11,6 @@ import timerRoutes from './routes/timer.js';
11
11
  import dataRoutes from './routes/data.js';
12
12
  import monitorRoutes from './routes/monitor.js';
13
13
  import calendarRoutes from './routes/calendar.js';
14
- import serverRoutes from './routes/server.js';
15
14
  const app = new Hono();
16
15
  app.use('*', cors());
17
16
  app.get('/', (c) => c.html(indexPage()));
@@ -23,7 +22,6 @@ app.route('/api', timerRoutes);
23
22
  app.route('/api', dataRoutes);
24
23
  app.route('/api', monitorRoutes);
25
24
  app.route('/api', calendarRoutes);
26
- app.route('/api', serverRoutes);
27
25
  export function startDashboard() {
28
26
  console.log(`Clocktopus dashboard running at http://localhost:${DASHBOARD_PORT}`);
29
27
  serve({ fetch: app.fetch, port: DASHBOARD_PORT });
@@ -111,23 +111,9 @@ export function indexPage() {
111
111
  .toggle input:checked + .slider { background: #238636; }
112
112
  .toggle input:checked + .slider::before { transform: translateX(16px); background: #fff; }
113
113
 
114
- /* Server restart overlay */
115
- .overlay { position: fixed; inset: 0; background: rgba(13, 17, 23, 0.92); display: none; align-items: center; justify-content: center; z-index: 9999; }
116
- .overlay.active { display: flex; }
117
- .overlay-box { background: #1c1f26; border: 1px solid #30363d; border-radius: 12px; padding: 2rem 2.5rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
118
- .spinner { width: 32px; height: 32px; border: 3px solid #30363d; border-top-color: #d29922; border-radius: 50%; animation: spin 0.8s linear infinite; }
119
- .overlay-text { color: #e1e4e8; font-size: 0.95rem; }
120
- @keyframes spin { to { transform: rotate(360deg); } }
121
114
  </style>
122
115
  </head>
123
116
  <body oncontextmenu="return false;">
124
- <div id="server-overlay" class="overlay">
125
- <div class="overlay-box">
126
- <div class="spinner"></div>
127
- <div class="overlay-text" id="server-overlay-text">Restarting Server...</div>
128
- </div>
129
- </div>
130
-
131
117
  <div class="header">
132
118
  <h1>Clocktopus</h1>
133
119
  <div class="nav">
@@ -294,17 +280,6 @@ export function indexPage() {
294
280
  <div class="msg" id="google-msg"></div>
295
281
  </div>
296
282
 
297
- <!-- Server -->
298
- <div class="card">
299
- <div class="card-header">
300
- <div class="dot green"></div>
301
- <h2>Server</h2>
302
- </div>
303
- <p style="font-size:0.85rem;color:#8b949e;margin-bottom:0.5rem;">Restart the Clocktopus dashboard server.</p>
304
- <button id="server-restart-btn" onclick="restartServer()" style="background:#30363d;">Restart Server</button>
305
- <div class="msg" id="server-msg"></div>
306
- </div>
307
-
308
283
  <!-- Jira -->
309
284
  <div class="card">
310
285
  <div class="card-header">
@@ -734,79 +709,6 @@ export function indexPage() {
734
709
  }
735
710
  }
736
711
 
737
- // --- Server restart ---
738
- async function restartServer() {
739
- const btn = document.getElementById('server-restart-btn');
740
- const overlay = document.getElementById('server-overlay');
741
- const overlayText = document.getElementById('server-overlay-text');
742
- btn.disabled = true;
743
- btn.textContent = 'Restarting...';
744
- overlayText.textContent = 'Restarting Server...';
745
- overlay.classList.add('active');
746
- setMsg('server-msg', '', true);
747
-
748
- const tauriApi = window.__TAURI__ || window.__TAURI_INTERNALS__;
749
- const inTauri = !!(tauriApi && tauriApi.core && tauriApi.core.invoke);
750
-
751
- if (inTauri) {
752
- try {
753
- await tauriApi.core.invoke('restart_server');
754
- } catch (err) {
755
- overlayText.textContent = 'Restart failed: ' + (err && err.message ? err.message : String(err));
756
- setTimeout(function() {
757
- overlay.classList.remove('active');
758
- btn.disabled = false;
759
- btn.textContent = 'Restart Server';
760
- }, 4000);
761
- return;
762
- }
763
- } else {
764
- let managed = false;
765
- try {
766
- const res = await fetch('/api/server/restart', { method: 'POST' });
767
- const data = await res.json();
768
- managed = !!data.managed;
769
- } catch {
770
- // Expected — server dies mid-response
771
- }
772
- if (!managed) {
773
- overlayText.textContent = 'Server stopped. Start it manually: clocktopus serve';
774
- setMsg('server-msg', 'Not managed by PM2 — restart manually.', false);
775
- setTimeout(function() {
776
- overlay.classList.remove('active');
777
- btn.disabled = false;
778
- btn.textContent = 'Restart Server';
779
- }, 3500);
780
- return;
781
- }
782
- }
783
-
784
- // Poll /api/status until server responds
785
- const start = Date.now();
786
- const MAX_WAIT_MS = 30000;
787
- async function poll() {
788
- try {
789
- const r = await fetch('/api/status', { cache: 'no-store' });
790
- if (r.ok) {
791
- overlayText.textContent = 'Server back online. Reloading...';
792
- setTimeout(function() { window.location.reload(); }, 400);
793
- return;
794
- }
795
- } catch {}
796
- if (Date.now() - start > MAX_WAIT_MS) {
797
- overlayText.textContent = 'Server did not come back. Check logs.';
798
- setTimeout(function() {
799
- overlay.classList.remove('active');
800
- btn.disabled = false;
801
- btn.textContent = 'Restart Server';
802
- }, 3000);
803
- return;
804
- }
805
- setTimeout(poll, 500);
806
- }
807
- setTimeout(poll, 1000);
808
- }
809
-
810
712
  // --- Projects ---
811
713
  async function loadProjects() {
812
714
  try {
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import * as fs from 'fs';
7
7
  import * as path from 'path';
8
8
  import { fileURLToPath } from 'url';
9
9
  import { createRequire } from 'module';
10
+ import { execSync } from 'child_process';
10
11
  import { completeLatestSession, getLatestSession } from './lib/db.js';
11
12
  import { stopJiraTimer } from './lib/jira.js';
12
13
  import { startDashboard } from './dashboard/server.js';
@@ -291,6 +292,15 @@ const isDev = __dirname.includes('/Projects/') || __dirname.includes('/src/');
291
292
  const MONITOR_PM2_NAME = isDev ? 'clocktopus-monitor-dev' : 'clocktopus-monitor';
292
293
  const DASH_PM2_NAME = isDev ? 'clocktopus-dash-dev' : 'clocktopus-dash';
293
294
  const pm2Bin = path.join(path.dirname(createRequire(import.meta.url).resolve('pm2')), 'bin', 'pm2');
295
+ const bunBin = (() => {
296
+ try {
297
+ return execSync('which bun', { encoding: 'utf-8' }).trim();
298
+ }
299
+ catch {
300
+ return 'bun';
301
+ }
302
+ })();
303
+ const pm2Cmd = `${bunBin} ${pm2Bin}`;
294
304
  program
295
305
  .command('monitor')
296
306
  .description('Start idle monitor as a background daemon.')
@@ -301,10 +311,10 @@ program
301
311
  const scriptPath = path.join(__dirname, 'index.js');
302
312
  try {
303
313
  try {
304
- execSync(`${pm2Bin} delete ${MONITOR_PM2_NAME}`, { stdio: 'ignore' });
314
+ execSync(`${pm2Cmd} delete ${MONITOR_PM2_NAME}`, { stdio: 'ignore' });
305
315
  }
306
316
  catch { }
307
- execSync(`${pm2Bin} start ${scriptPath} --name ${MONITOR_PM2_NAME} --interpreter ${bunPath} -- monitor:run`, {
317
+ execSync(`${pm2Cmd} start ${scriptPath} --name ${MONITOR_PM2_NAME} --interpreter ${bunPath} -- monitor:run`, {
308
318
  stdio: 'inherit',
309
319
  });
310
320
  console.log(chalk.green('Idle monitor started in background.'));
@@ -321,7 +331,7 @@ program
321
331
  .action(async () => {
322
332
  const { execSync } = await import('child_process');
323
333
  try {
324
- execSync(`${pm2Bin} stop ${MONITOR_PM2_NAME}`, { stdio: 'inherit' });
334
+ execSync(`${pm2Cmd} stop ${MONITOR_PM2_NAME}`, { stdio: 'inherit' });
325
335
  }
326
336
  catch {
327
337
  console.log(chalk.yellow('Monitor is not running.'));
@@ -333,7 +343,7 @@ program
333
343
  .action(async () => {
334
344
  const { execSync } = await import('child_process');
335
345
  try {
336
- execSync(`${pm2Bin} logs ${MONITOR_PM2_NAME} --lines 50`, { stdio: 'inherit' });
346
+ execSync(`${pm2Cmd} logs ${MONITOR_PM2_NAME} --lines 50`, { stdio: 'inherit' });
337
347
  }
338
348
  catch {
339
349
  console.log(chalk.yellow('Monitor is not running.'));
@@ -348,10 +358,10 @@ program
348
358
  const scriptPath = path.join(__dirname, 'index.js');
349
359
  try {
350
360
  try {
351
- execSync(`${pm2Bin} delete ${DASH_PM2_NAME}`, { stdio: 'ignore' });
361
+ execSync(`${pm2Cmd} delete ${DASH_PM2_NAME}`, { stdio: 'ignore' });
352
362
  }
353
363
  catch { }
354
- execSync(`${pm2Bin} start ${scriptPath} --name ${DASH_PM2_NAME} --interpreter ${bunPath} -- dash`, {
364
+ execSync(`${pm2Cmd} start ${scriptPath} --name ${DASH_PM2_NAME} --interpreter ${bunPath} -- dash`, {
355
365
  stdio: 'inherit',
356
366
  });
357
367
  console.log(chalk.green(`Dashboard running at ${DASHBOARD_URL}`));
@@ -368,7 +378,7 @@ program
368
378
  .action(async () => {
369
379
  const { execSync } = await import('child_process');
370
380
  try {
371
- execSync(`${pm2Bin} stop ${DASH_PM2_NAME}`, { stdio: 'inherit' });
381
+ execSync(`${pm2Cmd} stop ${DASH_PM2_NAME}`, { stdio: 'inherit' });
372
382
  }
373
383
  catch {
374
384
  console.log(chalk.yellow('Dashboard is not running.'));
@@ -380,7 +390,7 @@ program
380
390
  .action(async () => {
381
391
  const { execSync } = await import('child_process');
382
392
  try {
383
- execSync(`${pm2Bin} logs ${DASH_PM2_NAME} --lines 50`, { stdio: 'inherit' });
393
+ execSync(`${pm2Cmd} logs ${DASH_PM2_NAME} --lines 50`, { stdio: 'inherit' });
384
394
  }
385
395
  catch {
386
396
  console.log(chalk.yellow('Dashboard is not running.'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clocktopus",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -42,6 +42,7 @@
42
42
  "hono": "^4.12.3",
43
43
  "inquirer": "^8.2.4",
44
44
  "macos-notification-state": "^3.0.0",
45
+ "node-gyp": "^11.2.0",
45
46
  "node-notifier": "^10.0.1",
46
47
  "pm2": "^6.0.8",
47
48
  "uuid": "^11.1.0",