Skip to content

Commit

Permalink
v3.22.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MayGo committed Nov 30, 2024
1 parent 2776219 commit fede423
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -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 <maigo.erit@gmail.com>",
"license": "GPL-2.0",
Expand Down
52 changes: 25 additions & 27 deletions electron/src/jobs/app-track-item-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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();
Expand All @@ -83,7 +83,7 @@ export class AppTrackItemJob {
return true;
}

async saveActiveWindow(result: any): Promise<TrackItem> {
async saveActiveWindow(result: activeWindow.Result): Promise<TrackItem> {
let rawItem: any = { taskName: TrackItemType.AppTrackItem };

rawItem.beginDate = BackgroundUtils.currentTimeMinusJobInterval();
Expand All @@ -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);
Expand Down

0 comments on commit fede423

Please sign in to comment.