Skip to content

Commit

Permalink
utils: Add function to check if application is running on Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl authored and ArturoManzoli committed Oct 3, 2024
1 parent c626983 commit dfe3941
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit dfe3941

Please sign in to comment.