From bc376963962f510671e86853d4c9d84854176f7c Mon Sep 17 00:00:00 2001 From: Sebastian Richner Date: Mon, 26 Feb 2024 10:45:20 +0100 Subject: [PATCH] Fix startup issue --- src/electron/electron/main/index.ts | 26 +++++++++++++------ .../electron/main/services/utils/helpers.ts | 4 ++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/electron/electron/main/index.ts b/src/electron/electron/main/index.ts index 6f97e95d..84b51180 100644 --- a/src/electron/electron/main/index.ts +++ b/src/electron/electron/main/index.ts @@ -17,6 +17,8 @@ import { IpcHandler } from '../ipc/IpcHandler'; import { ExperienceSamplingService } from './services/ExperienceSamplingService'; import studyConfig from '../../shared/study.config'; import { SchedulingService } from './services/SchedulingService'; +import { is } from './services/utils/helpers'; +import { Settings } from './entities/Settings'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -51,7 +53,7 @@ if (!app.requestSingleInstanceLock()) { process.exit(0); } -if (process.platform === 'darwin') { +if (is.macOS) { app.dock.hide(); } @@ -66,10 +68,6 @@ app.whenReady().then(async () => { openAtLogin: true }); - LOG.info( - `hasAccessibilityAndScreenRecordingPermission = ${hasAccessibilityAndScreenRecordingPermission()}, systemPreferences.isTrustedAccessibilityClient(false) = ${systemPreferences.isTrustedAccessibilityClient(false)}, systemPreferences.getMediaAccessStatus('screen') = ${systemPreferences.getMediaAccessStatus('screen')}` - ); - try { await databaseService.init(); await settingsService.init(); @@ -92,11 +90,19 @@ app.whenReady().then(async () => { ); } - if (process.platform === 'darwin' && hasAccessibilityAndScreenRecordingPermission() === false) { - LOG.info('Screen recording permission not granted, opening onboarding window...'); + const settings: Settings = await Settings.findOneBy({ onlyOneEntityShouldExist: 1 }); + + if (settings.onboardingShown === false || !hasAccessibilityAndScreenRecordingPermission()) { + LOG.debug( + `Onboarding shown: ${settings.onboardingShown}, hasAccessibilityAndScreenRecordingPermission: ${hasAccessibilityAndScreenRecordingPermission()}, creating onboarding window...` + ); await windowService.createOnboardingWindow(); + settings.onboardingShown = true; + await settings.save(); } else { - LOG.info('Screen recording permission granted, starting all trackers...'); + LOG.debug( + `Onboarding shown: ${settings.onboardingShown}, hasAccessibilityAndScreenRecordingPermission: ${hasAccessibilityAndScreenRecordingPermission()}, starting all trackers...` + ); await trackers.startAllTrackers(); LOG.info(`Trackers started: ${trackers.getRunningTrackerNames().join(', ')}`); @@ -151,6 +157,10 @@ app.on('window-all-closed', () => { }); function hasAccessibilityAndScreenRecordingPermission(): boolean { + if (!is.macOS) { + return true; + } + return ( systemPreferences.isTrustedAccessibilityClient(false) && systemPreferences.getMediaAccessStatus('screen') === 'granted' diff --git a/src/electron/electron/main/services/utils/helpers.ts b/src/electron/electron/main/services/utils/helpers.ts index 011d18f9..ef1789c3 100644 --- a/src/electron/electron/main/services/utils/helpers.ts +++ b/src/electron/electron/main/services/utils/helpers.ts @@ -2,10 +2,12 @@ import electron from 'electron'; export declare interface Is { dev: boolean; + macOS: boolean; } export const is: Is = { - dev: !electron.app.isPackaged + dev: !electron.app.isPackaged, + macOS: process.platform === 'darwin' }; export function generateAlphaNumericString(length: number = 0): string {