From fede4231513bd1b4a4be12462141fb228e9b6c95 Mon Sep 17 00:00:00 2001 From: MayGo Date: Sat, 30 Nov 2024 22:06:08 +0200 Subject: [PATCH] v3.22.2 --- electron/package.json | 2 +- electron/src/jobs/app-track-item-job.ts | 52 ++++++++++++------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/electron/package.json b/electron/package.json index c9e70f73..88789759 100644 --- a/electron/package.json +++ b/electron/package.json @@ -1,6 +1,6 @@ { "name": "tockler", - "version": "3.22.1", + "version": "3.22.2", "description": "Automatically track applications usage and working time", "author": "Maigo Erit ", "license": "GPL-2.0", diff --git a/electron/src/jobs/app-track-item-job.ts b/electron/src/jobs/app-track-item-job.ts index ecaaae94..9a0d5bbe 100644 --- a/electron/src/jobs/app-track-item-job.ts +++ b/electron/src/jobs/app-track-item-job.ts @@ -6,10 +6,29 @@ import { backgroundService } from '../background-service'; import { TrackItemType } from '../enums/track-item-type'; import { taskAnalyser, TrackItemRaw } from '../task-analyser'; import { TrackItem } from '../models/TrackItem'; -import { dialog } from 'electron'; +import activeWindow from 'active-win'; let logger = logManager.getLogger('AppTrackItemJob'); +const errorWindowItem: activeWindow.Result = { + platform: 'macos', + title: 'Active Window undefined', + owner: { + name: 'PERMISSION_ERROR', + processId: 0, + path: '', + bundleId: '', + }, + id: 0, + bounds: { + x: 0, + y: 0, + width: 0, + height: 0, + }, + memoryUsage: 0, +}; + export class AppTrackItemJob { lastUpdatedItem: TrackItem | null = null; errorDialogIsOpen = false; @@ -23,7 +42,7 @@ export class AppTrackItemJob { try { if (this.checkIfIsInCorrectState()) { let activeWindow = await activeWin(); - let updatedItem: TrackItem = await this.saveActiveWindow(activeWindow ? activeWindow : {}); + let updatedItem: TrackItem = await this.saveActiveWindow(activeWindow ?? errorWindowItem); if (!BackgroundUtils.isSameItems(updatedItem as TrackItemRaw, this.lastUpdatedItem as TrackItemRaw)) { logger.debug('App and title changed. Analysing title'); @@ -41,33 +60,14 @@ export class AppTrackItemJob { return true; } catch (error: any) { - const activeWinError = await this.checkIfPermissionError(error); - - if (activeWinError) { - logger.debug('Permission error: ' + activeWinError); - } else { - logger.error(`Error in AppTrackItemJob: ${error.toString()}`, error); - } + logger.error(`Error in AppTrackItemJob: ${error.toString()}`, error); + let updatedItem: TrackItem = await this.saveActiveWindow({ ...errorWindowItem, title: error.toString() }); + this.lastUpdatedItem = updatedItem; } return false; } - async checkIfPermissionError(e: any) { - const activeWinError = e.stdout; - - if (activeWinError) { - this.errorDialogIsOpen = true; - await dialog.showMessageBox({ - message: activeWinError.replace('get-windows', 'Tockler'), - }); - - this.errorDialogIsOpen = false; - return activeWinError; - } - return; - } - checkIfIsInCorrectState() { if (stateManager.isSystemSleeping()) { stateManager.resetAppTrackItem(); @@ -83,7 +83,7 @@ export class AppTrackItemJob { return true; } - async saveActiveWindow(result: any): Promise { + async saveActiveWindow(result: activeWindow.Result): Promise { let rawItem: any = { taskName: TrackItemType.AppTrackItem }; rawItem.beginDate = BackgroundUtils.currentTimeMinusJobInterval(); @@ -103,8 +103,6 @@ export class AppTrackItemJob { rawItem.title = result.title.replace(/\n$/, '').replace(/^\s/, ''); } - rawItem.url = result.url; - // logger.debug('Active window (parsed):', rawItem); let savedItem = await backgroundService.createOrUpdate(rawItem);