From dfe3941a7f86667e7ca94126a76fcb98bc98de9c Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 2 Oct 2024 14:23:38 -0300 Subject: [PATCH] utils: Add function to check if application is running on Electron --- src/libs/utils.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libs/utils.ts b/src/libs/utils.ts index d09d1e282..eace84dbc 100644 --- a/src/libs/utils.ts +++ b/src/libs/utils.ts @@ -149,3 +149,25 @@ export const reloadCockpit = (timeout = 500): void => { showDialog({ message: restartMessage, variant: 'info', timer: timeout }) setTimeout(() => location.reload(), timeout) } + +/** + * Detects if the application is running in Electron + * @returns {boolean} True if running in Electron, false otherwise + */ +export const isElectron = (): boolean => { + // Check if the userAgent contains 'electron' (for renderer process) + if (typeof navigator === 'object' && typeof navigator.userAgent === 'string') { + return navigator.userAgent.toLowerCase().includes('electron') + } + + // Check if the process object exists and contains 'electron' (for main process) + if ( + typeof process === 'object' && + typeof process.versions === 'object' && + typeof process.versions.electron === 'string' + ) { + return true + } + + return false +}