diff --git a/README.md b/README.md index 1a0f751..e94a5a7 100644 --- a/README.md +++ b/README.md @@ -117,8 +117,8 @@ const UPDATE_INTERVAL = 5 * 60 * 1000; // Change to your preference (in millisec - Try re-logging in from the system tray menu ### Widget position not saving -- Position is reset on each launch -- Future version will include position memory +- Window position is now saved automatically when you drag it +- Position will be restored when you restart the app ### Build errors ```bash @@ -158,7 +158,7 @@ https://claude.ai/api/organizations/{org_id}/usage - [ ] Linux support - [ ] Custom themes - [ ] Notification alerts at usage thresholds -- [ ] Remember window position +- [x] Remember window position - [ ] Settings panel - [ ] Usage history graphs - [ ] Multiple account support diff --git a/main.js b/main.js index 0399471..40380a9 100644 --- a/main.js +++ b/main.js @@ -16,7 +16,9 @@ const WIDGET_WIDTH = 480; const WIDGET_HEIGHT = 140; function createMainWindow() { - mainWindow = new BrowserWindow({ + // Load saved position or use defaults + const savedPosition = store.get('windowPosition'); + const windowOptions = { width: WIDGET_WIDTH, height: WIDGET_HEIGHT, frame: false, @@ -30,7 +32,15 @@ function createMainWindow() { contextIsolation: true, preload: path.join(__dirname, 'preload.js') } - }); + }; + + // Apply saved position if it exists + if (savedPosition) { + windowOptions.x = savedPosition.x; + windowOptions.y = savedPosition.y; + } + + mainWindow = new BrowserWindow(windowOptions); mainWindow.loadFile('src/renderer/index.html'); @@ -38,6 +48,12 @@ function createMainWindow() { mainWindow.setAlwaysOnTop(true, 'floating'); mainWindow.setVisibleOnAllWorkspaces(true); + // Save position when window is moved + mainWindow.on('move', () => { + const position = mainWindow.getBounds(); + store.set('windowPosition', { x: position.x, y: position.y }); + }); + mainWindow.on('closed', () => { mainWindow = null; }); diff --git a/src/renderer/app.js b/src/renderer/app.js index d044a9c..1dbcb8b 100644 --- a/src/renderer/app.js +++ b/src/renderer/app.js @@ -9,6 +9,7 @@ const UPDATE_INTERVAL = 5 * 60 * 1000; // 5 minutes const elements = { loadingContainer: document.getElementById('loadingContainer'), loginContainer: document.getElementById('loginContainer'), + noUsageContainer: document.getElementById('noUsageContainer'), mainContent: document.getElementById('mainContent'), loginBtn: document.getElementById('loginBtn'), refreshBtn: document.getElementById('refreshBtn'), @@ -130,17 +131,30 @@ async function fetchUsageData() { } } -// Update UI with usage data +// Check if there's no usage data +function hasNoUsage(data) { + const sessionUtilization = data.five_hour?.utilization || 0; + const sessionResetsAt = data.five_hour?.resets_at; + const weeklyUtilization = data.seven_day?.utilization || 0; + const weeklyResetsAt = data.seven_day?.resets_at; + + return sessionUtilization === 0 && !sessionResetsAt && + weeklyUtilization === 0 && !weeklyResetsAt; +} + // Update UI with usage data function updateUI(data) { latestUsageData = data; + + // Check if there's no usage data + if (hasNoUsage(data)) { + showNoUsage(); + return; + } + + showMainContent(); refreshTimers(); startCountdown(); - - // Update timestamp - // Update timestamp - // const now = new Date(); - // elements.lastUpdate.textContent = `Updated ${now.toLocaleTimeString()}`; } // Track if we've already triggered a refresh for expired timers @@ -301,19 +315,29 @@ function updateTimer(timerElement, textElement, resetsAt, totalMinutes) { function showLoading() { elements.loadingContainer.style.display = 'block'; elements.loginContainer.style.display = 'none'; + elements.noUsageContainer.style.display = 'none'; elements.mainContent.style.display = 'none'; } function showLoginRequired() { elements.loadingContainer.style.display = 'none'; elements.loginContainer.style.display = 'flex'; // Use flex to preserve centering + elements.noUsageContainer.style.display = 'none'; elements.mainContent.style.display = 'none'; stopAutoUpdate(); } +function showNoUsage() { + elements.loadingContainer.style.display = 'none'; + elements.loginContainer.style.display = 'none'; + elements.noUsageContainer.style.display = 'flex'; + elements.mainContent.style.display = 'none'; +} + function showMainContent() { elements.loadingContainer.style.display = 'none'; elements.loginContainer.style.display = 'none'; + elements.noUsageContainer.style.display = 'none'; elements.mainContent.style.display = 'block'; } diff --git a/src/renderer/index.html b/src/renderer/index.html index 0a6a21e..35557f4 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -56,6 +56,19 @@ + +
+