Fix to convert electron platform name darwin to macos (#3573)

* Fix to convert electron platform name darwin to macos

* Remove unneeded async

* Fix to handle other possible platform strings

* Add electron test for user sidebar menu text

* Fix formatting
This commit is contained in:
Jonathan Tran
2024-08-20 22:08:02 -04:00
committed by GitHub
parent 3543c5f0e7
commit 4a14ca38ab
2 changed files with 54 additions and 3 deletions

View File

@ -7,12 +7,29 @@ export default function usePlatform() {
const [platformName, setPlatformName] = useState<Platform>('')
useEffect(() => {
async function getPlatform() {
setPlatformName((window.electron.platform ?? '') as Platform)
function getPlatform(): Platform {
const platform = window.electron.platform ?? ''
// https://nodejs.org/api/process.html#processplatform
switch (platform) {
case 'darwin':
return 'macos'
case 'win32':
return 'windows'
// We don't currently care to distinguish between these.
case 'android':
case 'freebsd':
case 'linux':
case 'openbsd':
case 'sunos':
return 'linux'
default:
console.error('Unknown platform:', platform)
return ''
}
}
if (isDesktop()) {
void getPlatform()
setPlatformName(getPlatform())
} else {
if (navigator.userAgent.indexOf('Mac') !== -1) {
setPlatformName('macos')