Skip to content

Commit

Permalink
Merge pull request #7275 from ever-co/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Dec 10, 2023
2 parents 07d2a89 + ed394da commit ae362e7
Show file tree
Hide file tree
Showing 67 changed files with 1,635 additions and 1,335 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@
"VULTR",
"Codegen",
"icns",
"pantone"
"pantone",
"msedge",
"openai",
"OPENAI"
],
Expand Down
70 changes: 0 additions & 70 deletions apps/desktop-timer/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { LanguagesEnum } from '@gauzy/contracts';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { NbToastrService } from '@nebular/theme';
import * as _ from 'underscore';
import { Router } from '@angular/router';
import { firstValueFrom } from 'rxjs';

@UntilDestroy({ checkProperties: true })
Expand All @@ -26,7 +25,6 @@ export class AppComponent implements OnInit, AfterViewInit {
private electronService: ElectronService,
private appService: AppService,
private authStrategy: AuthStrategy,
private router: Router,
public readonly translate: TranslateService,
private store: Store,
private toastrService: NbToastrService,
Expand Down Expand Up @@ -73,74 +71,6 @@ export class AppComponent implements OnInit, AfterViewInit {
}

ngAfterViewInit(): void {
this.electronService.ipcRenderer.on('collect_data', (event, arg) =>
this._ngZone.run(async () => {
const res = await this.appService.collectEvents(
arg.tpURL,
arg.tp,
arg.start,
arg.end
);
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'APP',
});
})
);

this.electronService.ipcRenderer.on('collect_afk', (event, arg) =>
this._ngZone.run(async () => {
const res = await this.appService.collectAfk(
arg.tpURL,
arg.tp,
arg.start,
arg.end
);
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'AFK',
});
})
);

this.electronService.ipcRenderer.on(
'collect_chrome_activities',
(event, arg) =>
this._ngZone.run(async () => {
const res =
await this.appService.collectChromeActivityFromAW(
arg.tpURL,
arg.start,
arg.end
);
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'URL',
});
})
);

this.electronService.ipcRenderer.on(
'collect_firefox_activities',
(event, arg) =>
this._ngZone.run(async () => {
const res =
await this.appService.collectFirefoxActivityFromAw(
arg.tpURL,
arg.start,
arg.end
);
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'URL',
});
})
);

this.electronService.ipcRenderer.on('server_ping', (event, arg) =>
this._ngZone.run(() => {
const pingHost = setInterval(async () => {
Expand Down
18 changes: 16 additions & 2 deletions apps/desktop-timer/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ import {
LanguageInterceptor,
AlwaysOnModule,
UnauthorizedInterceptor,
GAUZY_ENV
GAUZY_ENV,
OrganizationInterceptor,
ActivityWatchInterceptor,
ActivityWatchModule
} from '@gauzy/desktop-ui-lib';
import { NbCardModule, NbButtonModule } from '@nebular/theme';
import { NgSelectModule } from '@ng-select/ng-select';
Expand Down Expand Up @@ -97,7 +100,8 @@ import { environment } from '../environments/environment';
}
}),
NbDatepickerModule.forRoot(),
AboutModule
AboutModule,
ActivityWatchModule
],
providers: [
AppService,
Expand All @@ -121,6 +125,16 @@ import { environment } from '../environments/environment';
useClass: TenantInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: ActivityWatchInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: OrganizationInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: APIInterceptor,
Expand Down
133 changes: 6 additions & 127 deletions apps/desktop-timer/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,141 +1,20 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../environments/environment';
import { firstValueFrom } from 'rxjs';
import { UserOrganizationService } from '@gauzy/desktop-ui-lib';
import { IUserOrganization } from '@gauzy/contracts';

@Injectable({
providedIn: 'root',
providedIn: 'root'
})
export class AppService {
AW_HOST = environment.AWHost;
buckets: any = {};
constructor(
private http: HttpClient,
private readonly _userOrganizationService: UserOrganizationService
) {}
constructor(private http: HttpClient, private readonly _userOrganizationService: UserOrganizationService) {}

pingServer(values) {
return firstValueFrom(this.http.get(values.host + '/api'));
public pingServer({ host }) {
return firstValueFrom(this.http.get(host + '/api'));
}

startTime(id): Promise<any> {
const defaultValue: any = [
{
timestamp: new Date(),
data: {
running: true,
label: '',
},
},
];

if (id) defaultValue[0].id = id;
return firstValueFrom(
this.http.post(
`${this.AW_HOST}/api/0/buckets/aw-stopwatch/events`,
defaultValue
)
);
}

stopTime(historyTime): Promise<any> {
const defaultStopParams = [
{
timestamp: new Date(),
data: {
running: false,
label: '',
},
id: historyTime.id,
},
];
return firstValueFrom(
this.http.post(
`${this.AW_HOST}/api/0/buckets/aw-stopwatch/events`,
defaultStopParams
)
);
}

getAwBuckets(tpURL): Promise<any> {
return firstValueFrom(this.http.get(`${tpURL}/api/0/buckets`));
}

parseBuckets(buckets) {
Object.keys(buckets).forEach((key) => {
const keyParse = key.split('_')[0];
switch (keyParse) {
case 'aw-watcher-window':
this.buckets.windowBucket = buckets[key];
break;
case 'aw-watcher-afk':
this.buckets.afkBucket = buckets[key];
break;
case 'aw-watcher-web-chrome':
this.buckets.chromeBucket = buckets[key];
break;
case 'aw-watcher-web-firefox':
this.buckets.firefoxBucket = buckets[key];
break;
default:
break;
}
});
}

async collectEvents(tpURL, tp, start, end): Promise<any> {
if (!this.buckets.windowBucket) {
const allBuckets = await this.getAwBuckets(tpURL);
this.parseBuckets(allBuckets);
}
return this.collectFromAW(tpURL, start, end);
}

collectAfk(tpURL, tp, start, end): Promise<any> {
return this.collectAfkFromAW(tpURL, start, end);
}

collectChromeActivityFromAW(tpURL, start, end): Promise<any> {
if (!this.buckets.chromeBucket) return Promise.resolve([]);
return firstValueFrom(
this.http.get(
`${tpURL}/api/0/buckets/${this.buckets.chromeBucket.id}/events?start=${start}&end=${end}&limit=-1`
)
);
}

collectFirefoxActivityFromAw(tpURL, start, end): Promise<any> {
if (!this.buckets.firefoxBucket) return Promise.resolve([]);
return firstValueFrom(
this.http.get(
`${tpURL}/api/0/buckets/${this.buckets.firefoxBucket.id}/events?start=${start}&end=${end}&limit=-1`
)
);
}

pushActivityCollectionToGauzy() {
return true;
}
collectFromAW(tpURL, start, end) {
if (!this.buckets.windowBucket) return Promise.resolve([]);
return firstValueFrom(
this.http.get(
`${tpURL}/api/0/buckets/${this.buckets.windowBucket.id}/events?start=${start}&end=${end}&limit=-1`
)
);
}

collectAfkFromAW(tpURL, start, end) {
if (!this.buckets.afkBucket) return Promise.resolve([]);
return firstValueFrom(
this.http.get(
`${tpURL}/api/0/buckets/${this.buckets.afkBucket.id}/events?limit=1`
)
);
}

async getUserDetail() {
public async getUserDetail(): Promise<IUserOrganization> {
return await this._userOrganizationService.detail();
}
}
5 changes: 1 addition & 4 deletions apps/desktop-timer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
ipcTimer,
TrayIcon,
LocalStore,
DataModel,
AppMenu,
DesktopUpdater,
removeMainListener,
Expand Down Expand Up @@ -241,16 +240,14 @@ eventErrorManager.onShowError(async (message) => {
});

async function startServer(value, restart = false) {
const dataModel = new DataModel();
await dataModel.createNewTable(knex);
try {
const config: any = {
...value,
isSetup: true,
};
const aw = {
host: value.awHost,
isAw: value.aw,
isAw: !!value.aw?.isAw,
};
const projectConfig = store.get('project');
store.set({
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-timer/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@
"twing": "^5.0.2",
"underscore": "^1.13.3"
}
}
}
70 changes: 0 additions & 70 deletions apps/desktop/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,76 +38,6 @@ export class AppComponent implements OnInit, AfterViewInit {
}
);

this._electronService.ipcRenderer.on('collect_data', (event, arg) => {
this._ngZone.run(() =>
this._appService
.collectEvents(arg.tpURL, arg.tp, arg.start, arg.end)
.then((res) => {
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'APP',
});
})
);
});

this._electronService.ipcRenderer.on('collect_afk', (event, arg) => {
this._ngZone.run(() => {
this._appService
.collectAfk(arg.tpURL, arg.tp, arg.start, arg.end)
.then((res) => {
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'AFK',
});
});
});
});

this._electronService.ipcRenderer.on(
'collect_chrome_activities',
(event, arg) => {
this._ngZone.run(() => {
this._appService
.collectChromeActivityFromAW(
arg.tpURL,
arg.start,
arg.end
)
.then((res) => {
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'URL',
});
});
});
}
);

this._electronService.ipcRenderer.on(
'collect_firefox_activities',
(event, arg) => {
this._ngZone.run(() => {
this._appService
.collectFirefoxActivityFromAw(
arg.tpURL,
arg.start,
arg.end
)
.then((res) => {
event.sender.send('data_push_activity', {
timerId: arg.timerId,
windowEvent: res,
type: 'URL',
});
});
});
}
);

this._electronService.ipcRenderer.on('set_time_sheet', (event, arg) => {
this._ngZone.run(() => {
this._appService.pushToTimesheet(arg).then((res: any) => {
Expand Down
Loading

0 comments on commit ae362e7

Please sign in to comment.