Skip to content

Commit

Permalink
Add experience sampling logs
Browse files Browse the repository at this point in the history
  • Loading branch information
SRichner committed Mar 13, 2024
1 parent 5ced89c commit 34307aa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/electron/electron/ipc/IpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export class IpcHandler {
);
}

private closeExperienceSamplingWindow(): void {
this.windowService.closeExperienceSamplingWindow();
private closeExperienceSamplingWindow(skippedExperienceSampling: boolean): void {
this.windowService.closeExperienceSamplingWindow(skippedExperienceSampling);
}

private closeOnboardingWindow(): void {
Expand Down
23 changes: 19 additions & 4 deletions src/electron/electron/main/services/WindowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import studyConfig from '../../../shared/study.config';
import { Settings } from '../entities/Settings';
import { UsageDataService } from './UsageDataService';
import { UsageDataEventType } from '../../enums/UsageDataEventType.enum';

const LOG = getLogger('WindowService');

Expand Down Expand Up @@ -38,8 +40,16 @@ export class WindowService {
this.createTray();
}

public async createExperienceSamplingWindow() {
this.closeExperienceSamplingWindow();
public async createExperienceSamplingWindow(isManuallyTriggered: boolean = false) {
if (this.experienceSamplingWindow) {
this.experienceSamplingWindow.close();
this.experienceSamplingWindow = null;
}

const usageDataEvent = isManuallyTriggered
? UsageDataEventType.ExperienceSamplingManuallyOpened
: UsageDataEventType.ExperienceSamplingAutomaticallyOpened;
UsageDataService.createNewUsageDataEvent(usageDataEvent);

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -95,7 +105,12 @@ export class WindowService {
});
}

public closeExperienceSamplingWindow() {
public closeExperienceSamplingWindow(skippedExperienceSampling: boolean) {
const usageDataEvent = skippedExperienceSampling
? UsageDataEventType.ExperienceSamplingSkipped
: UsageDataEventType.ExperienceSamplingAnswered;
UsageDataService.createNewUsageDataEvent(usageDataEvent);

if (this.experienceSamplingWindow) {
this.experienceSamplingWindow.close();
this.experienceSamplingWindow = null;
Expand Down Expand Up @@ -306,7 +321,7 @@ export class WindowService {
const windowMenu: MenuItemConstructorOptions[] = [
{
label: 'Open Experience Sampling',
click: () => this.createExperienceSamplingWindow()
click: () => this.createExperienceSamplingWindow(true)
},
{
label: 'Open Onboarding',
Expand Down
2 changes: 1 addition & 1 deletion src/electron/src/utils/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Commands = {
response?: number,
skipped?: boolean
) => Promise<void>;
closeExperienceSamplingWindow: () => void;
closeExperienceSamplingWindow: (skippedExperienceSampling: boolean) => void;
closeOnboardingWindow: () => void;
closeDataExportWindow: () => void;
getStudyInfo: () => Promise<StudyInfoDto>;
Expand Down
4 changes: 2 additions & 2 deletions src/electron/src/views/ExperienceSamplingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function createExperienceSample(value: number) {
),
new Promise((resolve) => setTimeout(resolve, 150))
]);
await typedIpcRenderer.invoke('closeExperienceSamplingWindow');
await typedIpcRenderer.invoke('closeExperienceSamplingWindow', false);
} catch (error) {
console.error('Error creating team', error);
}
Expand All @@ -51,7 +51,7 @@ async function skipExperienceSample() {
),
new Promise((resolve) => setTimeout(resolve, 150))
]);
await typedIpcRenderer.invoke('closeExperienceSamplingWindow');
await typedIpcRenderer.invoke('closeExperienceSamplingWindow', true);
} catch (error) {
console.error('Error creating team', error);
}
Expand Down

0 comments on commit 34307aa

Please sign in to comment.